Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

messagebox.cpp

Go to the documentation of this file.
00001 /*
00002                =.            This file is part of the OPIE Project
00003              .=l.            Copyright (c)  2004 Holger Hans Peter <freyther@handhelds.org>
00004            .>+-=
00005  _;:,     .>    :=|.         This library is free software; you can
00006 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00007 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00008 .="- .-=="i,     .._         License as published by the Free Software
00009  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00010      ._= =}       :          or (at your option) any later version.
00011     .%`+i>       _;_.
00012     .i_,=:_.      -<s.       This library is distributed in the hope that
00013      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00014     : ..    .:,     . . .    without even the implied warranty of
00015     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00016   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00017 ..}^=.=       =       ;      Library General Public License for more
00018 ++=   -.     .`     .:       details.
00019  :     =  ...= . :.=-
00020  -.   .:....=;==+<;          You should have received a copy of the GNU
00021   -_. . .   )=.  =           Library General Public License along with
00022     --        :-=`           this library; see the file COPYING.LIB.
00023                              If not, write to the Free Software Foundation,
00024                              Inc., 59 Temple Place - Suite 330,
00025                              Boston, MA 02111-1307, USA.
00026 
00027 */
00028 
00029 #include "messagebox.h"
00030 
00031 #include <qapplication.h>
00032 #include <qmessagebox.h>
00033 
00034 /*
00035  * LGPLv2 KDE Project kstringhandler.cpp
00036  */
00037 template<class T>
00038 inline const T& kClamp( const T& x, const T& low, const T& high )
00039 {
00040     if ( x < low )       return low;
00041     else if ( high < x ) return high;
00042     else                 return x;
00043 }
00044 
00048 static QString g_insert_ldot( const QString& name, const QFontMetrics& fontMetrics ) {
00049     uint  maxPixels = qApp->desktop()->width()-90;
00050     uint nameWidth = fontMetrics.width(name);
00051 
00052     if (maxPixels < nameWidth) {
00053         QString tmp = name;
00054         const uint em = fontMetrics.maxWidth();
00055         maxPixels -= fontMetrics.width("...");
00056 
00057         while (maxPixels < nameWidth && !tmp.isEmpty()) {
00058             int delta = (nameWidth - maxPixels) / em;
00059             delta = kClamp(delta, 1, delta); // no max
00060 
00061             tmp.remove(0, delta);
00062             nameWidth = fontMetrics.width(tmp);
00063         }
00064 
00065         return ("..." + tmp);
00066     }
00067 
00068     return name;
00069 }
00070 
00089 bool OMessageBox::confirmDelete( QWidget* parent, const QString& type, const QString& object,
00090                                  const QString& _caption ) {
00091     /*
00092      * create a messagebox to get the font metrics
00093      */
00094     QMessageBox msg( QString::null, QString::null,
00095                      QMessageBox::Warning, QMessageBox::Yes,
00096                      QMessageBox::No|QMessageBox::Default|QMessageBox::Escape,
00097                      QMessageBox::NoButton,
00098                      parent, "OMessageBox::confirmDelete" );
00099 
00100     /*
00101      * Create the Message and Caption
00102      */
00103     QString msga = QObject::tr("<qt>Are you sure you want to delete %1<br> %2?</qt>" )
00104                    .arg( type )
00105                    .arg( g_insert_ldot( object, msg.fontMetrics() ) );
00106     QString caption = _caption.isEmpty() ?
00107                       QObject::tr( "Confirm Deletion" ) : _caption;
00108 
00109     msg.setText( msga );
00110     msg.setCaption( caption );
00111     msg.setIcon( QMessageBox::Warning );
00112     msg.adjustSize();
00113 
00114     /*
00115      * Warn the user that he will delete
00116      */
00117     int ret = msg.exec();
00118     return ( ret == QMessageBox::Yes );
00119 }

Generated on Sat Nov 5 16:17:30 2005 for OPIE by  doxygen 1.4.2