00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "messagebox.h"
00030
00031 #include <qapplication.h>
00032 #include <qmessagebox.h>
00033
00034
00035
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);
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
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
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
00116
00117 int ret = msg.exec();
00118 return ( ret == QMessageBox::Yes );
00119 }