@@ -817,9 +817,7 @@ char Qarma::showMessage(const QStringList &args, char type)
817817 // the suggested spacer however doesn't work, but Qt allows us to fix the size after the show event
818818 //
819819 // still a lousy hack which might run into windowmanager related problems
820- bool forceSize = false ;
821- if (!wrap && msgLabel) {
822- forceSize = true ;
820+ if (!(wrap && m_size.isNull ()) && msgLabel) {
823821 // figure the dimensions of the dialog if the label wasn't there
824822 QLabel *icnLabel = dlg->findChild <QLabel*>(" qt_msgboxex_icon_label" );
825823 QSize delta = msgLabel->size ();
@@ -829,27 +827,34 @@ char Qarma::showMessage(const QStringList &args, char type)
829827 delta.setHeight (qMax (delta.height (), icnLabel->height ()));
830828 // delta is now the virtual label size, subtract if from the dialog
831829 delta = dlg->size () - delta;
832- QRect r = msgLabel->fontMetrics ().boundingRect (msgLabel->text ());
830+ QRect r;
831+ if (!wrap) {
832+ r = msgLabel->fontMetrics ().boundingRect (msgLabel->text ());
833+ } else if (m_size.width () < 1 || m_size.height () < 1 ) {
834+ // likewise we can apply unilateral --width/--height
835+ r = QRect (0 ,0 ,QWIDGETSIZE_MAX,QWIDGETSIZE_MAX);
836+ if (m_size.width () > 0 )
837+ r.setWidth (m_size.width () - delta.width ());
838+ r = msgLabel->fontMetrics ().boundingRect (r, Qt::TextWordWrap, msgLabel->text ());
839+ if (m_size.height () > 0 ) {
840+ // for only fixed height, calculate the line count and overguess the necessary columns
841+ r.setHeight (m_size.height () - delta.height ());
842+ int lines = qMax (1 , r.height ()/msgLabel->fontMetrics ().lineSpacing ());
843+ r.setWidth (3 *r.width ()/(2 *lines)); // generous 50% overhead to account for word wrapping, better the dialog is a bit wider than missing text
844+ }
845+ } else { // or completely fixed size
846+ r.setSize (m_size);
847+ delta = QSize (0 ,0 );
848+ }
833849 // if there's an icon, our new label, regardless of the widths sufficient for one unwrapped line, gets at least its height
834850 if (icnLabel)
835851 r.setHeight (qMax (r.height (), icnLabel->height ()));
836852 dlg->setFixedSize (delta + r.size ());
837- }
838- // likewise we can apply --width/--height
839- if (!m_size.isNull ()) {
840- forceSize = true ;
841- QSize sz = dlg->size ();
842- if (m_size.width () > 0 )
843- sz.setWidth (m_size.width ());
844- if (m_size.height () > 0 )
845- sz.setHeight (m_size.height ());
846- dlg->setFixedSize (sz);
847- }
848- // here's the catch - the WM migth think the pre-showing size is mandatory
849- // (probably race condition between window mapping and the size fix and the WM handling client messages)
850- // so we briefly wait (100ms is a complete random time) and set the current size again to get the WM up to speed
851- if (forceSize)
853+ // here's the catch - the WM migth think the pre-showing size is mandatory
854+ // (probably race condition between window mapping and the size fix and the WM handling client messages)
855+ // so we briefly wait (100ms is a complete random time) and set the current size again to get the WM up to speed
852856 QTimer::singleShot (100 , this , [=]() {dlg->setFixedSize (dlg->size ());});
857+ }
853858 return 0 ;
854859}
855860
0 commit comments