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: YQProgressBar.cc 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 00026 #include <qprogressbar.h> 00027 #include <QVBoxLayout> 00028 00029 #include <qlabel.h> 00030 #define YUILogComponent "qt-ui" 00031 #include <yui/YUILog.h> 00032 00033 using std::max; 00034 00035 #include "utf8.h" 00036 #include "YQUI.h" 00037 #include "YQProgressBar.h" 00038 #include "YQWidgetCaption.h" 00039 00040 00041 YQProgressBar::YQProgressBar( YWidget * parent, 00042 const std::string & label, 00043 int maxValue ) 00044 : QFrame( (QWidget *) parent->widgetRep() ) 00045 , YProgressBar( parent, label, maxValue ) 00046 { 00047 QVBoxLayout* layout = new QVBoxLayout( this ); 00048 setLayout( layout ); 00049 00050 setWidgetRep( this ); 00051 00052 layout->setSpacing( YQWidgetSpacing ); 00053 layout->setMargin ( YQWidgetMargin ); 00054 00055 _caption = new YQWidgetCaption( this, label ); 00056 YUI_CHECK_NEW( _caption ); 00057 layout->addWidget( _caption ); 00058 00059 _qt_progressbar = new QProgressBar( this ); 00060 _qt_progressbar->setRange(0, maxValue); 00061 YUI_CHECK_NEW( _qt_progressbar ); 00062 layout->addWidget( _qt_progressbar ); 00063 00064 _caption->setBuddy( _qt_progressbar ); 00065 } 00066 00067 00068 YQProgressBar::~YQProgressBar() 00069 { 00070 // NOP 00071 } 00072 00073 00074 void YQProgressBar::setLabel( const std::string & label ) 00075 { 00076 _caption->setText( label ); 00077 YProgressBar::setLabel( label ); 00078 } 00079 00080 00081 void YQProgressBar::setValue( int newValue ) 00082 { 00083 YProgressBar::setValue( newValue ); 00084 _qt_progressbar->setValue( value() ); 00085 } 00086 00087 00088 00089 void YQProgressBar::setEnabled( bool enabled ) 00090 { 00091 _caption->setEnabled( enabled ); 00092 _qt_progressbar->setEnabled( enabled ); 00093 YWidget::setEnabled( enabled ); 00094 } 00095 00096 00097 int YQProgressBar::preferredWidth() 00098 { 00099 int hintWidth = !_caption->isHidden() ? 00100 _caption->sizeHint().width() + layout()->margin() : 0; 00101 00102 return max( 200, hintWidth ); 00103 } 00104 00105 00106 int YQProgressBar::preferredHeight() 00107 { 00108 return sizeHint().height(); 00109 } 00110 00111 00112 void YQProgressBar::setSize( int newWidth, int newHeight ) 00113 { 00114 resize( newWidth, newHeight ); 00115 } 00116 00117 00118 bool YQProgressBar::setKeyboardFocus() 00119 { 00120 _qt_progressbar->setFocus(); 00121 00122 return true; 00123 } 00124 00125 00126 #include "YQProgressBar.moc"