Diffstat (limited to 'noncore/settings/packagemanager/promptdlg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/packagemanager/promptdlg.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/noncore/settings/packagemanager/promptdlg.cpp b/noncore/settings/packagemanager/promptdlg.cpp new file mode 100644 index 0000000..3122699 --- a/dev/null +++ b/noncore/settings/packagemanager/promptdlg.cpp | |||
@@ -0,0 +1,140 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | |||
4 | =. Copyright (c) 2003 Dan Williams <drw@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This file is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This file is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
19 | ..}^=.= = ; Public License for more details. | ||
20 | ++= -. .` .: | ||
21 | : = ...= . :.=- You should have received a copy of the GNU | ||
22 | -. .:....=;==+<; General Public License along with this file; | ||
23 | -_. . . )=. = see the file COPYING. If not, write to the | ||
24 | -- :-=` Free Software Foundation, Inc., | ||
25 | 59 Temple Place - Suite 330, | ||
26 | Boston, MA 02111-1307, USA. | ||
27 | |||
28 | */ | ||
29 | |||
30 | #include "promptdlg.h" | ||
31 | |||
32 | #include <qlabel.h> | ||
33 | #include <qlayout.h> | ||
34 | #include <qpushbutton.h> | ||
35 | #include <qwidgetlist.h> | ||
36 | |||
37 | #include <qpe/qpeapplication.h> | ||
38 | |||
39 | PromptDlg::PromptDlg( const QString &caption, const QString &text, const QString &btn1, const QString &btn2, | ||
40 | QWidget *parent ) | ||
41 | : QWidget( parent, QString::null, WType_Modal | WType_TopLevel | WStyle_Dialog ) | ||
42 | , m_btnClicked( -1 ) | ||
43 | { | ||
44 | setCaption( caption ); | ||
45 | |||
46 | QGridLayout *layout = new QGridLayout( this, 2, 2, 4, 2 ); | ||
47 | QLabel *label = new QLabel( text, this ); | ||
48 | label->setAlignment( AlignCenter | WordBreak ); | ||
49 | layout->addMultiCellWidget( label, 0, 0, 0, 1 ); | ||
50 | |||
51 | QPushButton *btn = new QPushButton( btn1, this ); | ||
52 | layout->addWidget( btn, 1, 0 ); | ||
53 | connect( btn, SIGNAL(clicked()), this, SLOT(slotBtn1Clicked()) ); | ||
54 | |||
55 | btn = new QPushButton( btn2, this ); | ||
56 | layout->addWidget( btn, 1, 1 ); | ||
57 | connect( btn, SIGNAL(clicked()), this, SLOT(slotBtn2Clicked()) ); | ||
58 | } | ||
59 | |||
60 | int PromptDlg::exec() | ||
61 | { | ||
62 | // Determine position of dialog. Derived from QT's QDialog::show() method. | ||
63 | QWidget *w = parentWidget(); | ||
64 | QPoint p( 0, 0 ); | ||
65 | int extraw = 0, extrah = 0; | ||
66 | QWidget * desk = QApplication::desktop(); | ||
67 | if ( w ) | ||
68 | w = w->topLevelWidget(); | ||
69 | |||
70 | QWidgetList *list = QApplication::topLevelWidgets(); | ||
71 | QWidgetListIt it( *list ); | ||
72 | while ( (extraw == 0 || extrah == 0) && it.current() != 0 ) | ||
73 | { | ||
74 | int w, h; | ||
75 | QWidget * current = it.current(); | ||
76 | ++it; | ||
77 | w = current->geometry().x() - current->x(); | ||
78 | h = current->geometry().y() - current->y(); | ||
79 | |||
80 | extraw = QMAX( extraw, w ); | ||
81 | extrah = QMAX( extrah, h ); | ||
82 | } | ||
83 | delete list; | ||
84 | |||
85 | // sanity check for decoration frames. With embedding, we | ||
86 | // might get extraordinary values | ||
87 | if ( extraw >= 10 || extrah >= 40 ) | ||
88 | extraw = extrah = 0; | ||
89 | |||
90 | if ( w ) | ||
91 | { | ||
92 | // Use mapToGlobal rather than geometry() in case w might | ||
93 | // be embedded in another application | ||
94 | QPoint pp = w->mapToGlobal( QPoint(0,0) ); | ||
95 | p = QPoint( pp.x() + w->width()/2, pp.y() + w->height()/ 2 ); | ||
96 | } | ||
97 | else | ||
98 | p = QPoint( desk->width()/2, desk->height()/2 ); | ||
99 | |||
100 | p = QPoint( p.x()-width()/2 - extraw, p.y()-height()/2 - extrah ); | ||
101 | |||
102 | if ( p.x() + extraw + width() > desk->width() ) | ||
103 | p.setX( desk->width() - width() - extraw ); | ||
104 | if ( p.x() < 0 ) | ||
105 | p.setX( 0 ); | ||
106 | |||
107 | if ( p.y() + extrah + height() > desk->height() ) | ||
108 | p.setY( desk->height() - height() - extrah ); | ||
109 | if ( p.y() < 0 ) | ||
110 | p.setY( 0 ); | ||
111 | |||
112 | move( p ); | ||
113 | show(); | ||
114 | |||
115 | // Enter event loop for modality | ||
116 | qApp->enter_loop(); | ||
117 | |||
118 | return m_btnClicked; | ||
119 | } | ||
120 | |||
121 | int PromptDlg::ask( const QString &caption, const QString &text, const QString &btn1, const QString &btn2, | ||
122 | QWidget *parent ) | ||
123 | { | ||
124 | PromptDlg *dlg = new PromptDlg( caption, text, btn1, btn2, parent ); | ||
125 | int rc = dlg->exec(); | ||
126 | delete dlg; | ||
127 | return rc; | ||
128 | } | ||
129 | |||
130 | void PromptDlg::slotBtn1Clicked() | ||
131 | { | ||
132 | m_btnClicked = 1; | ||
133 | qApp->exit_loop(); | ||
134 | } | ||
135 | |||
136 | void PromptDlg::slotBtn2Clicked() | ||
137 | { | ||
138 | m_btnClicked = 2; | ||
139 | qApp->exit_loop(); | ||
140 | } | ||