1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include "scinputdialog.h"
#include <QEvent>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QSpacerItem>
#include <QVBoxLayout>
#include "scrspinbox.h"
#include "util.h"
#include "util_icon.h"
ScInputDialog::ScInputDialog( QWidget* parent, const char* name, bool modal, Qt::WFlags fl )
: QDialog( parent )
{
if ( !name )
setObjectName( "ScInputDialog" );
setModal(modal);
setWindowIcon(QIcon(loadIcon ( "AppIcon.png" )));
setSizeGripEnabled( TRUE );
ScInputDialogLayout = new QVBoxLayout( this );
ScInputDialogLayout->setMargin(10);
ScInputDialogLayout->setSpacing(5);
labelEntryLayout = new QHBoxLayout;
labelEntryLayout->setMargin(0);
labelEntryLayout->setSpacing(5);
entryLabel = new QLabel( this );
labelEntryLayout->addWidget( entryLabel );
entrySpin = new ScrSpinBox( this, 0 );
entrySpin->setMinimumSize( QSize( 0, 10 ) );
labelEntryLayout->addWidget( entrySpin );
buttonLayout = new QHBoxLayout;
buttonLayout->setMargin(0);
buttonLayout->setSpacing(5);
QSpacerItem* hspacing = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
buttonLayout->addItem(hspacing);
buttonOk = new QPushButton( this );
buttonOk->setAutoDefault( TRUE );
buttonOk->setDefault( TRUE );
buttonLayout->addWidget( buttonOk );
buttonCancel = new QPushButton( this );
buttonCancel->setAutoDefault( TRUE );
buttonLayout->addWidget( buttonCancel );
ScInputDialogLayout->addLayout(labelEntryLayout);
ScInputDialogLayout->addLayout(buttonLayout);
languageChange();
// signals and slots connections
connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
}
void ScInputDialog::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange)
{
languageChange();
}
else
QWidget::changeEvent(e);
}
void ScInputDialog::languageChange()
{
setWindowTitle( tr( "Input Dialog" ) );
entryLabel->setText( tr( "InputDialog" ) );
buttonOk->setText( tr( "&OK" ) );
buttonOk->setShortcut( QKeySequence( QString::null ) );
buttonCancel->setText( tr( "&Cancel" ) );
buttonCancel->setShortcut( QKeySequence( QString::null ) );
}
double ScInputDialog::getDouble( const QString &caption, const QString &label, double num,
double from, double to, int decimals,
QString suffix, bool *ok,
QWidget *parent, const char *name )
{
ScInputDialog *dlg = new ScInputDialog(parent, name, TRUE);
dlg->setWindowTitle( caption );
dlg->entryLabel->setText(label);
dlg->entrySpin->setValues(0.0, 1000.0, decimals, num);
dlg->entrySpin->setSuffix(suffix);
dlg->entrySpin->selectAll();
bool accepted = ( dlg->exec() == QDialog::Accepted );
if ( ok )
*ok = accepted;
double result = dlg->entrySpin->value();
delete dlg;
return result;
}
|