Add slider dialogbox

svn path=/trunk/KDE/kdebase/apps/; revision=909191
This commit is contained in:
Laurent Montel 2009-01-11 09:21:59 +00:00
parent d91b30df1d
commit d6b5ce60d0
3 changed files with 54 additions and 2 deletions

View file

@ -18,6 +18,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
#include <kdebug.h>
#include "widgets.h"
#include <kmessagebox.h>
@ -640,7 +641,25 @@ static int directCommand(KCmdLineArgs *args)
}
return 1; // cancelled
}
if (args->isSet("slider"))
{
int miniValue = 0;
int maxValue = 0;
int step = 0;
QString text = args->getOption( "slider" );
if ( args->count() == 3 )
{
miniValue = args->arg(0).toInt();
maxValue = args->arg( 1 ).toInt();
step = args->arg( 2 ).toInt();
}
int result = 0;
bool returnCode = Widgets::slider(0, title, text, miniValue, maxValue, step, result);
if ( returnCode )
cout << result << endl;
return returnCode;
}
KCmdLineArgs::usage();
return -2; // NOTREACHED
}
@ -697,6 +716,7 @@ int main(int argc, char *argv[])
options.add("separate-output", ki18n("Return list items on separate lines (for checklist option and file open with --multiple)"));
options.add("print-winid", ki18n("Outputs the winId of each dialog"));
options.add("dontagain <file:entry>", ki18n("Config file and option name for saving the \"do-not-show/ask-again\" state"));
options.add( "slider <text> [minvalue] [maxvalue] [step]", ki18n( "Slider dialogbox, returns value selected" ) );
/* kdialog originally used --embed for attaching the dialog box. However this is misleading and so we changed to --attach.
* For backwards compatibility, we silently map --embed to --attach */

View file

@ -105,7 +105,7 @@ int Widgets::textBox(QWidget *parent, int width, int height, const QString& titl
kapp->setTopWidget( &dlg );
KVBox* vbox = new KVBox(&dlg);
dlg.setMainWidget(vbox);
KTextEdit *edit = new KTextEdit( vbox );
edit->setReadOnly(true);
@ -139,7 +139,7 @@ int Widgets::textInputBox(QWidget *parent, int width, int height, const QString&
dlg.setCaption( title );
dlg.setButtons( KDialog::Ok );
dlg.setModal( true );
kapp->setTopWidget( &dlg );
KVBox* vbox = new KVBox(&dlg);
@ -305,3 +305,34 @@ bool Widgets::progressBar(QWidget *parent, const QString& title, const QString&
dlg.exec();
return dlg.wasCancelled();
}
bool Widgets::slider( QWidget *parent, const QString& title, const QString& text, int minValue, int maxValue, int step, int &result )
{
KDialog dlg( parent );
kapp->setTopWidget( &dlg );
dlg.setCaption( title );
dlg.setButtons( KDialog::Ok|KDialog::Cancel );
dlg.setModal( true );
dlg.setDefaultButton( KDialog::Ok );
KVBox* vbox = new KVBox( &dlg );
dlg.setMainWidget( vbox );
QLabel label (vbox);
label.setText (text);
QSlider slider (vbox);
slider.setMinimum( minValue );
slider.setMaximum( maxValue );
slider.setSingleStep( step );
slider.setTickPosition ( QSlider::TicksAbove );
slider.setOrientation( Qt::Horizontal );
handleXGeometry(&dlg);
bool retcode = (dlg.exec() == QDialog::Accepted);
if (retcode)
result = slider.value();
return retcode;
}

View file

@ -36,6 +36,7 @@ namespace Widgets
bool radioBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args, QString &result);
bool comboBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args, const QString& defaultEntry, QString &result);
bool progressBar(QWidget *parent, const QString& title, const QString& text, int totalSteps);
bool slider( QWidget *parent, const QString& title, const QString& test, int minValue, int maxValue, int step, int &result );
void handleXGeometry(QWidget * dlg);