summaryrefslogtreecommitdiff
path: root/noncore/graphics/opie-eye/gui/messagebox.cpp
Unidiff
Diffstat (limited to 'noncore/graphics/opie-eye/gui/messagebox.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/messagebox.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/noncore/graphics/opie-eye/gui/messagebox.cpp b/noncore/graphics/opie-eye/gui/messagebox.cpp
new file mode 100644
index 0000000..c84e4e1
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/messagebox.cpp
@@ -0,0 +1,119 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2004 Holger Hans Peter <freyther@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "messagebox.h"
30
31#include <qapplication.h>
32#include <qmessagebox.h>
33
34/*
35 * LGPLv2 KDE Project kstringhandler.cpp
36 */
37template<class T>
38inline const T& kClamp( const T& x, const T& low, const T& high )
39{
40 if ( x < low ) return low;
41 else if ( high < x ) return high;
42 else return x;
43}
44
45/**
46 * dependant on the screen rotation place the dots
47 */
48static QString g_insert_ldot( const QString& name, const QFontMetrics& fontMetrics ) {
49 uint maxPixels = qApp->desktop()->width()-90;
50 uint nameWidth = fontMetrics.width(name);
51
52 if (maxPixels < nameWidth) {
53 QString tmp = name;
54 const uint em = fontMetrics.maxWidth();
55 maxPixels -= fontMetrics.width("...");
56
57 while (maxPixels < nameWidth && !tmp.isEmpty()) {
58 int delta = (nameWidth - maxPixels) / em;
59 delta = kClamp(delta, 1, delta); // no max
60
61 tmp.remove(0, delta);
62 nameWidth = fontMetrics.width(tmp);
63 }
64
65 return ("..." + tmp);
66 }
67
68 return name;
69}
70
71/**
72 *
73 * #FIXME Write Own message box to be more independant on sizes
74 * #FIXME Ask translator how to make the sentence more robust
75 *
76 * \brief replacement for QPEMessageBox::confirmDelete
77 *
78 * If you want to delete a file and the path is too long to fit
79 * on the screen \ldots is inserted in the middle of the string
80 * to fit on the screen. This allows the user still to identify
81 * the file.
82 *
83 * @param parent The parent of this MessageBox
84 * @param type The type of the object to delte. i.e 'the image'
85 * @param object The 'object' to be deleted
86 * @param caption An optional caption for the box
87 *
88 */
89bool OMessageBox::confirmDelete( QWidget* parent, const QString& type, const QString& object,
90 const QString& _caption ) {
91 /*
92 * create a messagebox to get the font metrics
93 */
94 QMessageBox msg( QString::null, QString::null,
95 QMessageBox::Warning, QMessageBox::Yes,
96 QMessageBox::No|QMessageBox::Default|QMessageBox::Escape,
97 QMessageBox::NoButton,
98 parent, "OMessageBox::confirmDelete" );
99
100 /*
101 * Create the Message and Caption
102 */
103 QString msga = QObject::tr("<qt>Are you sure you want to delete %1<br> %2?</qt>" )
104 .arg( type )
105 .arg( g_insert_ldot( object, msg.fontMetrics() ) );
106 QString caption = _caption.isEmpty() ?
107 QObject::tr( "Confirm Deletion" ) : _caption;
108
109 msg.setText( msga );
110 msg.setCaption( caption );
111 msg.setIcon( QMessageBox::Warning );
112 msg.adjustSize();
113
114 /*
115 * Warn the user that he will delete
116 */
117 int ret = msg.exec();
118 return ( ret == QMessageBox::Yes );
119}