@@ -189,6 +189,7 @@ Qarma::Qarma(int &argc, char **argv) : QApplication(argc, argv)
189189, m_type(Invalid)
190190{
191191 m_pos = QPoint (INT_MAX, INT_MAX); // invalid
192+ m_size = QSize (0 ,0 ); // so we can reasonably use isNull …
192193 QStringList argList = QCoreApplication::arguments (); // arguments() is slow
193194 const QString binary = argList.at (0 );
194195 m_zenity = binary.endsWith (" zenity" );
@@ -818,6 +819,10 @@ char Qarma::showMessage(const QStringList &args, char type)
818819 //
819820 // still a lousy hack which might run into windowmanager related problems
820821 if (!(wrap && m_size.isNull ()) && msgLabel) {
822+ if (m_size.width () > 0 && dlg->width () <= 500 ) {
823+ // QMessageBox unconditionally disables wrapping for dialogs < 500px width, so don't try to shrink those
824+ m_size.setWidth (qMax (m_size.width (), dlg->width ()));
825+ }
821826 // figure the dimensions of the dialog if the label wasn't there
822827 QLabel *icnLabel = dlg->findChild <QLabel*>(" qt_msgboxex_icon_label" );
823828 QSize delta = msgLabel->size ();
@@ -828,6 +833,7 @@ char Qarma::showMessage(const QStringList &args, char type)
828833 // delta is now the virtual label size, subtract if from the dialog
829834 delta = dlg->size () - delta;
830835 QRect r;
836+ QMargins marge = msgLabel->contentsMargins () + QMargins (4 ,4 ,4 ,4 );
831837 if (!wrap) {
832838 r = msgLabel->fontMetrics ().boundingRect (msgLabel->text ());
833839 } else if (m_size.width () < 1 || m_size.height () < 1 ) {
@@ -845,15 +851,21 @@ char Qarma::showMessage(const QStringList &args, char type)
845851 } else { // or completely fixed size
846852 r.setSize (m_size);
847853 delta = QSize (0 ,0 );
854+ marge = QMargins ();
848855 }
856+ m_size = QSize (0 ,0 ); // reset so the global size adjustment doesn't apply
857+ r.setWidth (r.width () + marge.left ()+marge.right ());
858+ r.setHeight (r.height () + marge.top ()+marge.bottom ());
849859 // if there's an icon, our new label, regardless of the widths sufficient for one unwrapped line, gets at least its height
850860 if (icnLabel)
851861 r.setHeight (qMax (r.height (), icnLabel->height ()));
852862 dlg->setFixedSize (delta + r.size ());
853863 // here's the catch - the WM migth think the pre-showing size is mandatory
854864 // (probably race condition between window mapping and the size fix and the WM handling client messages)
855865 // so we briefly wait (100ms is a complete random time) and set the current size again to get the WM up to speed
856- QTimer::singleShot (100 , this , [=]() {dlg->setFixedSize (dlg->size ());});
866+ for (int ms = 2 ; ms < 150 ; ms*=2 ) {
867+ QTimer::singleShot (ms, this , [=]() {dlg->setFixedSize (delta + r.size ());});
868+ }
857869 }
858870 return 0 ;
859871}
@@ -1946,8 +1958,8 @@ void Qarma::printHelp(const QString &category)
19461958 helpDict[" general" ] = CategoryHelp (tr (" General options" ), HelpList () <<
19471959 Help (" --title=TITLE" , tr (" Set the dialog title" )) <<
19481960 Help (" --window-icon=ICONPATH" , tr (" Set the window icon" )) <<
1949- Help (" --width=WIDTH" , tr (" Set the width" )) <<
1950- Help (" --height=HEIGHT" , tr (" Set the height" )) <<
1961+ Help (" --width=WIDTH" , tr (" Set the width" ) + tr ( " (not entirely deterministic for message dialogs " ) ) <<
1962+ Help (" --height=HEIGHT" , tr (" Set the height" ) + tr ( " (not entirely deterministic for message dialogs " ) ) <<
19511963 Help (" --pos=[+-]x[(+-)y]" , " QARMA ONLY! " + tr (" Set the position" )) <<
19521964 Help (" --timeout=TIMEOUT" , tr (" Set dialog timeout in seconds" )) <<
19531965 Help (" --ok-label=TEXT" , tr (" Sets the label of the Ok button" )) <<
0 commit comments