summaryrefslogtreecommitdiff
authorzecke <zecke>2005-02-05 15:47:16 (UTC)
committer zecke <zecke>2005-02-05 15:47:16 (UTC)
commit8ba13dd38e7da296177719dcc8fddbbe978a4b9a (patch) (unidiff)
treefdba0d440e7b462faa2b845a0f4364cff134166f
parent28c5c88c3535c035bd26abd988ef7fb0e098143f (diff)
downloadopie-8ba13dd38e7da296177719dcc8fddbbe978a4b9a.zip
opie-8ba13dd38e7da296177719dcc8fddbbe978a4b9a.tar.gz
opie-8ba13dd38e7da296177719dcc8fddbbe978a4b9a.tar.bz2
Add a special MessageBox to squeeze the path to fit onto the screen.
This is a fix for #1539
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/gui.pro6
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp13
-rw-r--r--noncore/graphics/opie-eye/gui/messagebox.cpp119
-rw-r--r--noncore/graphics/opie-eye/gui/messagebox.h57
4 files changed, 185 insertions, 10 deletions
diff --git a/noncore/graphics/opie-eye/gui/gui.pro b/noncore/graphics/opie-eye/gui/gui.pro
index 2759dd5..250c8b1 100644
--- a/noncore/graphics/opie-eye/gui/gui.pro
+++ b/noncore/graphics/opie-eye/gui/gui.pro
@@ -4,7 +4,8 @@ HEADERS += gui/filesystem.h \
4 gui/imageview.h \ 4 gui/imageview.h \
5 gui/mainwindow.h \ 5 gui/mainwindow.h \
6 gui/viewmodebutton.h \ 6 gui/viewmodebutton.h \
7 gui/basesetup.h 7 gui/basesetup.h \
8 gui/messagebox.h
8 9
9SOURCES += gui/filesystem.cpp \ 10SOURCES += gui/filesystem.cpp \
10 gui/iconview.cpp \ 11 gui/iconview.cpp \
@@ -12,6 +13,7 @@ SOURCES += gui/filesystem.cpp \
12 gui/imageview.cpp \ 13 gui/imageview.cpp \
13 gui/mainwindow.cpp \ 14 gui/mainwindow.cpp \
14 gui/viewmodebutton.cpp \ 15 gui/viewmodebutton.cpp \
15 gui/basesetup.cpp 16 gui/basesetup.cpp \
17 gui/messagebox.cpp
16 18
17 19
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp
index 138e661..b2443e8 100644
--- a/noncore/graphics/opie-eye/gui/iconview.cpp
+++ b/noncore/graphics/opie-eye/gui/iconview.cpp
@@ -4,6 +4,7 @@
4 */ 4 */
5 5
6#include "iconview.h" 6#include "iconview.h"
7#include "messagebox.h"
7 8
8#include <lib/imagecache.h> 9#include <lib/imagecache.h>
9#include <gui/imageinfoui.h> 10#include <gui/imageinfoui.h>
@@ -377,13 +378,12 @@ QString PIconView::prevFileName(bool &isDir)const{
377void PIconView::slotTrash() { 378void PIconView::slotTrash() {
378 bool isDir; 379 bool isDir;
379 QString pa = currentFileName( isDir ); 380 QString pa = currentFileName( isDir );
380 if ( isDir && pa.isEmpty() ) 381 if ( isDir || pa.isEmpty() )
381 return; 382 return;
382 383
383 if (!QPEMessageBox::confirmDelete( this, 384 if (!OMessageBox::confirmDelete( this, tr("the Image"),
384 tr("Delete Image" ), 385 pa, tr("Delete Image" )))
385 tr("the Image %1" ).arg(pa))) 386 return;
386 return
387 387
388 388
389 currentView()->dirLister()->deleteImage( pa ); 389 currentView()->dirLister()->deleteImage( pa );
@@ -430,9 +430,6 @@ void PIconView::resetView() {
430 430
431void PIconView::polish() 431void PIconView::polish()
432{ 432{
433 odebug << "===\n"
434 << "PIconView::polish()\n"
435 << "====" << oendl;
436 QVBox::polish(); 433 QVBox::polish();
437 434
438 QString lastView = m_cfg->readEntry("LastView",""); 435 QString lastView = m_cfg->readEntry("LastView","");
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}
diff --git a/noncore/graphics/opie-eye/gui/messagebox.h b/noncore/graphics/opie-eye/gui/messagebox.h
new file mode 100644
index 0000000..a0e6fa0
--- a/dev/null
+++ b/noncore/graphics/opie-eye/gui/messagebox.h
@@ -0,0 +1,57 @@
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#ifndef OPIE_UI_OMESSAGE_BOX_H
30#define OPIE_UI_OMEESAGE_BOX_H
31
32#include <qstring.h>
33
34class QWidget;
35
36/*
37 * ### to be moved to OpieUI
38 * ### move KDEs KStringHandler to OpieCore
39 * ### once done
40 * FIXME
41 */
42
43/**
44 * \brief Custom and common Opie MessageBoxes
45 *
46 * A set of static methods to open special MessageBoxes.
47 */
48class OMessageBox {
49public:
50 static bool confirmDelete(QWidget *parent,
51 const QString& type,
52 const QString& object,
53 const QString & caption = QString::null);
54
55};
56
57#endif