00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "autoResizeTreeView.h"
00022
00023 gf_AutoResizeTreeView::gf_AutoResizeTreeView (QWidget * parent)
00024 :QTreeView(parent)
00025 {
00026 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
00027 gf_gd = gf_GD_WIDTH;
00028 gf_gp = gf_GP_FRIENDLY;
00029 gf_twin = 0;
00030 gf_friendlyMin = 30;
00031 setMinimumSize(gf_friendlyMin,gf_friendlyMin);
00032 gf_shrinkToWidth = -1;
00033 gf_shrinkToHeight = -1;
00034 gf_hold = true;
00035 setStatus(gf_S_NORMAL);
00036 }
00037
00038 void gf_AutoResizeTreeView::storeSize()
00039 {
00040
00041 if (gf_shrinkToWidth == -1)
00042 gf_shrinkToWidth = width();
00043 if (gf_shrinkToHeight == -1)
00044 gf_shrinkToHeight = height();
00045 }
00046
00047 void gf_AutoResizeTreeView::restoreSize()
00048 {
00049
00050 if (gf_shrinkToWidth != -1 && gf_shrinkToHeight != -1)
00051 {
00052 setMaximumSize(1000,1000);
00053 resize(gf_shrinkToWidth,gf_shrinkToHeight);
00054 }
00055 }
00056
00057 void gf_AutoResizeTreeView::resizeEvent(QResizeEvent * event)
00058 {
00059 QTreeView::resizeEvent(event);
00060 switch (status)
00061 {
00062 case gf_S_GROWING:
00063 status = gf_S_GROWN;
00064 break;
00065 case gf_S_SHRINKING:
00066 status = gf_S_SHRUNK;
00067 break;
00068 case gf_S_SHRUNK:
00069 if (gf_gd & gf_GD_WIDTH)
00070 gf_twin->growWidth(event->size().width() - event->oldSize().width());
00071 if (gf_gd & gf_GD_HEIGHT)
00072 gf_twin->growHeight(event->size().height() - event->oldSize().height());
00073 break;
00074 case gf_S_NORMAL:
00075 case gf_S_GROWN:
00076 if (gf_shrinkToWidth != -1 && gf_shrinkToHeight != -1)
00077 {
00078 gf_shrinkToWidth += (event->size().width() - event->oldSize().width());
00079 gf_shrinkToHeight += (event->size().height() - event->oldSize().height());
00080 }
00081 }
00082
00083 }
00084
00085 void gf_AutoResizeTreeView::focusInEvent ( QFocusEvent * event )
00086 {
00087 QTreeView::focusInEvent(event);
00088 if (gf_twin != 0)
00089 {
00090
00091
00092 setStatus(gf_S_GROWING);
00093 gf_twin->setStatus(gf_S_SHRINKING);
00094 shrink();
00095
00096 storeSize();
00097 gf_twin->storeSize();
00098
00099 setStatus(gf_S_GROWING);
00100 gf_twin->setStatus(gf_S_SHRINKING);
00101 gf_twin->clearSelection();
00102 selectGrow();
00103 }
00104
00105 }
00106
00107 void gf_AutoResizeTreeView::focusOutEvent ( QFocusEvent * event )
00108 {
00109 QTreeView::focusOutEvent(event);
00110 if (gf_hold==false && gf_twin != 0)
00111 {
00112 setStatus(gf_S_NORMAL);
00113 gf_twin->setStatus(gf_S_NORMAL);
00114 shrink();
00115 }
00116
00117 }
00118
00119 void gf_AutoResizeTreeView::selectGrow()
00120 {
00121 if (gf_twin != 0)
00122 {
00123 switch (gf_gp)
00124 {
00125 case gf_GP_GREEDY:
00126 grow(1,1);
00127 break;
00128 case gf_GP_FRIENDLY:
00129 grow(gf_friendlyMin,gf_friendlyMin);
00130 break;
00131 case gf_GP_STAGGERED:
00132 staggeredGrow();
00133 break;
00134 case gf_GP_NONE:
00135
00136 break;
00137 }
00138 }
00139 }
00140
00141 void gf_AutoResizeTreeView::grow(int smallWidth, int smallHeight)
00142 {
00143 if (gf_gd & gf_GD_WIDTH)
00144 {
00145 int gf_twinwidth = gf_twin->width();
00146 gf_twin->setMaximumWidth(smallWidth);
00147 resize(width() +gf_twinwidth - smallWidth,height());
00148 }
00149
00150 if (gf_gd & gf_GD_HEIGHT)
00151 {
00152 int gf_twinheight = gf_twin->height();
00153 gf_twin->setMaximumHeight(smallHeight);
00154 resize(width(),height() +gf_twinheight - smallHeight);
00155 }
00156 }
00157
00158 void gf_AutoResizeTreeView::staggeredGrow()
00159 {
00160 }
00161
00162 void gf_AutoResizeTreeView::shrink()
00163 {
00164 int totalWidth = gf_twin->gf_shrinkToWidth + gf_shrinkToWidth;
00165 int totalHeight = gf_twin->gf_shrinkToHeight + gf_shrinkToHeight;
00166
00167 gf_twin->gf_shrinkToWidth = totalWidth / 2;
00168 gf_shrinkToWidth = totalWidth - gf_twin->gf_shrinkToWidth;
00169 gf_twin->gf_shrinkToHeight = totalHeight / 2;
00170 gf_shrinkToHeight = totalHeight - gf_twin->gf_shrinkToHeight;
00171
00172 restoreSize();
00173 gf_twin->restoreSize();
00174 }