summaryrefslogtreecommitdiff
authorzecke <zecke>2005-02-05 15:47:16 (UTC)
committer zecke <zecke>2005-02-05 15:47:16 (UTC)
commit8ba13dd38e7da296177719dcc8fddbbe978a4b9a (patch) (side-by-side diff)
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 \
gui/imageview.h \
gui/mainwindow.h \
gui/viewmodebutton.h \
- gui/basesetup.h
+ gui/basesetup.h \
+ gui/messagebox.h
SOURCES += gui/filesystem.cpp \
gui/iconview.cpp \
@@ -12,6 +13,7 @@ SOURCES += gui/filesystem.cpp \
gui/imageview.cpp \
gui/mainwindow.cpp \
gui/viewmodebutton.cpp \
- gui/basesetup.cpp
+ gui/basesetup.cpp \
+ gui/messagebox.cpp
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 @@
*/
#include "iconview.h"
+#include "messagebox.h"
#include <lib/imagecache.h>
#include <gui/imageinfoui.h>
@@ -377,13 +378,12 @@ QString PIconView::prevFileName(bool &isDir)const{
void PIconView::slotTrash() {
bool isDir;
QString pa = currentFileName( isDir );
- if ( isDir && pa.isEmpty() )
+ if ( isDir || pa.isEmpty() )
return;
- if (!QPEMessageBox::confirmDelete( this,
- tr("Delete Image" ),
- tr("the Image %1" ).arg(pa)))
- return
+ if (!OMessageBox::confirmDelete( this, tr("the Image"),
+ pa, tr("Delete Image" )))
+ return;
currentView()->dirLister()->deleteImage( pa );
@@ -430,9 +430,6 @@ void PIconView::resetView() {
void PIconView::polish()
{
- odebug << "===\n"
- << "PIconView::polish()\n"
- << "====" << oendl;
QVBox::polish();
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 @@
+/*
+               =. This file is part of the OPIE Project
+             .=l. Copyright (c) 2004 Holger Hans Peter <freyther@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This library is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This library is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.=       =       ; Library General Public License for more
+++=   -.     .`     .: details.
+ :     =  ...= . :.=-
+ -.   .:....=;==+<; You should have received a copy of the GNU
+  -_. . .   )=.  = Library General Public License along with
+    --        :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "messagebox.h"
+
+#include <qapplication.h>
+#include <qmessagebox.h>
+
+/*
+ * LGPLv2 KDE Project kstringhandler.cpp
+ */
+template<class T>
+inline const T& kClamp( const T& x, const T& low, const T& high )
+{
+ if ( x < low ) return low;
+ else if ( high < x ) return high;
+ else return x;
+}
+
+/**
+ * dependant on the screen rotation place the dots
+ */
+static QString g_insert_ldot( const QString& name, const QFontMetrics& fontMetrics ) {
+ uint maxPixels = qApp->desktop()->width()-90;
+ uint nameWidth = fontMetrics.width(name);
+
+ if (maxPixels < nameWidth) {
+ QString tmp = name;
+ const uint em = fontMetrics.maxWidth();
+ maxPixels -= fontMetrics.width("...");
+
+ while (maxPixels < nameWidth && !tmp.isEmpty()) {
+ int delta = (nameWidth - maxPixels) / em;
+ delta = kClamp(delta, 1, delta); // no max
+
+ tmp.remove(0, delta);
+ nameWidth = fontMetrics.width(tmp);
+ }
+
+ return ("..." + tmp);
+ }
+
+ return name;
+}
+
+/**
+ *
+ * #FIXME Write Own message box to be more independant on sizes
+ * #FIXME Ask translator how to make the sentence more robust
+ *
+ * \brief replacement for QPEMessageBox::confirmDelete
+ *
+ * If you want to delete a file and the path is too long to fit
+ * on the screen \ldots is inserted in the middle of the string
+ * to fit on the screen. This allows the user still to identify
+ * the file.
+ *
+ * @param parent The parent of this MessageBox
+ * @param type The type of the object to delte. i.e 'the image'
+ * @param object The 'object' to be deleted
+ * @param caption An optional caption for the box
+ *
+ */
+bool OMessageBox::confirmDelete( QWidget* parent, const QString& type, const QString& object,
+ const QString& _caption ) {
+ /*
+ * create a messagebox to get the font metrics
+ */
+ QMessageBox msg( QString::null, QString::null,
+ QMessageBox::Warning, QMessageBox::Yes,
+ QMessageBox::No|QMessageBox::Default|QMessageBox::Escape,
+ QMessageBox::NoButton,
+ parent, "OMessageBox::confirmDelete" );
+
+ /*
+ * Create the Message and Caption
+ */
+ QString msga = QObject::tr("<qt>Are you sure you want to delete %1<br> %2?</qt>" )
+ .arg( type )
+ .arg( g_insert_ldot( object, msg.fontMetrics() ) );
+ QString caption = _caption.isEmpty() ?
+ QObject::tr( "Confirm Deletion" ) : _caption;
+
+ msg.setText( msga );
+ msg.setCaption( caption );
+ msg.setIcon( QMessageBox::Warning );
+ msg.adjustSize();
+
+ /*
+ * Warn the user that he will delete
+ */
+ int ret = msg.exec();
+ return ( ret == QMessageBox::Yes );
+}
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 @@
+/*
+               =. This file is part of the OPIE Project
+             .=l. Copyright (c) 2004 Holger Hans Peter <freyther@handhelds.org>
+           .>+-=
+ _;:,     .>    :=|. This library is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This library is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
+..}^=.=       =       ; Library General Public License for more
+++=   -.     .`     .: details.
+ :     =  ...= . :.=-
+ -.   .:....=;==+<; You should have received a copy of the GNU
+  -_. . .   )=.  = Library General Public License along with
+    --        :-=` this library; see the file COPYING.LIB.
+ If not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef OPIE_UI_OMESSAGE_BOX_H
+#define OPIE_UI_OMEESAGE_BOX_H
+
+#include <qstring.h>
+
+class QWidget;
+
+/*
+ * ### to be moved to OpieUI
+ * ### move KDEs KStringHandler to OpieCore
+ * ### once done
+ * FIXME
+ */
+
+/**
+ * \brief Custom and common Opie MessageBoxes
+ *
+ * A set of static methods to open special MessageBoxes.
+ */
+class OMessageBox {
+public:
+ static bool confirmDelete(QWidget *parent,
+ const QString& type,
+ const QString& object,
+ const QString & caption = QString::null);
+
+};
+
+#endif