libyui-qt
2.43.5
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YQPartitionSplitter.cc 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #define YUILogComponent "qt-ui" 00026 #include <yui/YUILog.h> 00027 00028 #include "utf8.h" 00029 #include "YQUI.h" 00030 #include <yui/YEvent.h> 00031 #include "YQWidgetFactory.h" 00032 #include "YQOptionalWidgetFactory.h" 00033 #include "YQPartitionSplitter.h" 00034 #include "YQLayoutBox.h" 00035 #include "YQBarGraph.h" 00036 #include "YQIntField.h" 00037 #include "YQSlider.h" 00038 #include "YQSignalBlocker.h" 00039 00040 00041 YQPartitionSplitter::YQPartitionSplitter( YWidget * parent, 00042 int usedSize, 00043 int totalFreeSize, 00044 int newPartSize, 00045 int minNewSize, 00046 int minFreeSize, 00047 const std::string & usedLabel, 00048 const std::string & freeLabel, 00049 const std::string & newPartLabel, 00050 const std::string & freeFieldLabel, 00051 const std::string & newPartFieldLabel ) 00052 : QWidget( (QWidget *) parent->widgetRep() ) 00053 , YPartitionSplitter( parent, 00054 usedSize, 00055 totalFreeSize, 00056 newPartSize, 00057 minNewSize, 00058 minFreeSize, 00059 usedLabel, 00060 freeLabel, 00061 newPartLabel, 00062 freeFieldLabel, 00063 newPartFieldLabel ) 00064 , _vbox( 0 ) 00065 , _barGraph( 0 ) 00066 , _hbox( 0 ) 00067 , _freeSizeSlider( 0 ) 00068 , _newPartField( 0 ) 00069 { 00070 setWidgetRep( this ); 00071 00072 // Replace children manager so it will accept one single direct child (the outer vbox) 00073 setChildrenManager( new YSingleWidgetChildManager( this ) ); 00074 00075 // 00076 // Create internal widgets 00077 // 00078 00079 _vbox = YUI::widgetFactory()->createVBox( this ); 00080 _barGraph = dynamic_cast<YQBarGraph *> ( YUI::optionalWidgetFactory()->createBarGraph( _vbox ) ); 00081 YUI_CHECK_PTR( _barGraph ); 00082 00083 int freeSize = totalFreeSize - newPartSize; 00084 00085 { 00086 YBarGraphMultiUpdate multiUpdate( _barGraph ); 00087 00088 _barGraph->addSegment( YBarGraphSegment( usedSize, usedLabel ) ); 00089 _barGraph->addSegment( YBarGraphSegment( freeSize, freeLabel ) ); 00090 _barGraph->addSegment( YBarGraphSegment( newPartSize, newPartLabel) ); 00091 } 00092 00093 _hbox = YUI::widgetFactory()->createHBox( _vbox ); 00094 00095 _freeSizeSlider = new YQSlider( _hbox, freeFieldLabel, 00096 minFreeSize, maxFreeSize(), freeSize, 00097 true ); // reverseLayout (put QSpinBox left of QSlider) 00098 YUI_CHECK_PTR( _freeSizeSlider ); 00099 _freeSizeSlider->setStretchable( YD_HORIZ, true ); 00100 00101 _newPartField = new YQIntField( _hbox, newPartFieldLabel, 00102 minNewSize, maxNewPartSize(), newPartSize ); 00103 YUI_CHECK_PTR( _newPartField ); 00104 _newPartField->setStretchable( YD_HORIZ, false ); 00105 00106 00107 // Connect signals 00108 00109 connect( _newPartField, SIGNAL( valueChanged (int) ), 00110 this, SLOT ( setNewPartSizeSlot(int) ) ); 00111 00112 connect( _freeSizeSlider, SIGNAL( valueChanged (int) ), 00113 this, SLOT ( setFreeSizeSlot(int) ) ); 00114 } 00115 00116 00117 YQPartitionSplitter::~YQPartitionSplitter() 00118 { 00119 // NOP 00120 } 00121 00122 00123 void YQPartitionSplitter::setEnabled( bool enabled ) 00124 { 00125 _freeSizeSlider->setEnabled( enabled ); 00126 _newPartField->setEnabled ( enabled ); 00127 00128 YWidget::setEnabled( enabled ); 00129 } 00130 00131 00132 int YQPartitionSplitter::preferredWidth() 00133 { 00134 return _vbox->preferredWidth(); 00135 } 00136 00137 00138 int YQPartitionSplitter::preferredHeight() 00139 { 00140 return _vbox->preferredHeight(); 00141 } 00142 00143 00144 void YQPartitionSplitter::setSize( int newWidth, int newHeight ) 00145 { 00146 QWidget::resize( newWidth, newHeight ); 00147 _vbox->setSize ( newWidth, newHeight ); 00148 } 00149 00150 00151 int YQPartitionSplitter::value() 00152 { 00153 YUI_CHECK_PTR( _newPartField ); 00154 00155 return _newPartField->value(); 00156 } 00157 00158 00159 void YQPartitionSplitter::setValue( int newValue ) 00160 { 00161 YUI_CHECK_PTR( _barGraph ); 00162 YUI_CHECK_PTR( _freeSizeSlider ); 00163 YUI_CHECK_PTR( _newPartField ); 00164 00165 YQSignalBlocker sigBlocker1( _barGraph ); 00166 YQSignalBlocker sigBlocker2( _freeSizeSlider ); 00167 YQSignalBlocker sigBlocker3( _newPartField ); 00168 00169 _newPartField->setValue( newValue ); 00170 00171 int freeSize = totalFreeSize() - newValue; 00172 _freeSizeSlider->setValue( freeSize ); 00173 00174 YBarGraphMultiUpdate multiUpdate( _barGraph ); 00175 { 00176 _barGraph->setValue( freeSegment, freeSize ); 00177 _barGraph->setValue( newPartSegment, newValue ); 00178 } 00179 } 00180 00181 00182 void YQPartitionSplitter::setFreeSizeSlot( int newFreeSize ) 00183 { 00184 int newPartSize = totalFreeSize() - newFreeSize; 00185 00186 setValue( newPartSize ); 00187 00188 if ( notify() ) 00189 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) ); 00190 } 00191 00192 00193 void YQPartitionSplitter::setNewPartSizeSlot( int newPartSize ) 00194 { 00195 setValue( newPartSize ); 00196 00197 if ( notify() ) 00198 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) ); 00199 } 00200 00201 00202 bool YQPartitionSplitter::setKeyboardFocus() 00203 { 00204 _newPartField->setKeyboardFocus(); 00205 00206 return true; 00207 } 00208 00209 00210 #include "YQPartitionSplitter.moc"