This forum has been archived. All content is frozen. Please use KDE Discuss instead.

[Kourse 1] Patch - Bug 175186: Timer rectangle is too small

Tags: None
(comma "," separated)
User avatar
msoeken
Mentor
Posts
300
Karma
4
OS
This is the patch from Linex with small modifications which I currently mailed to Richard, the maintainer from ksnapshot.

Code: Select all
Index: snapshottimer.cpp
===================================================================
--- snapshottimer.cpp   (revision 903716)
+++ snapshottimer.cpp   (working copy)
@@ -31,7 +31,9 @@
 SnapshotTimer::SnapshotTimer() : QWidget(0)
 {
     setWindowFlags( Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
-    resize(180,20);
+    // The text is copied from paintEvent and
+    // the maximum number is used as %1 argument
+    resize(fontMetrics().width(i18n("Snapshot will be taken in %1 seconds", 99)), fontMetrics().height());
     connect(&timer, SIGNAL(timeout()), this, SLOT(bell()));
 }

@@ -86,7 +88,7 @@
       painter.setBrush( textBackgroundColor );
       QString helpText = i18np( "Snapshot will be taken in 1 second",
                                 "Snapshot will be taken in %1 seconds", ( length-time ) );
-      QRect textRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText );
+      QRect textRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextSingleLine, helpText );
       textRect.adjust( -2, -2, 4, 2 );
       painter.drawRect( rect().adjusted(0,0,-1,-1) );
       textRect.moveTopLeft( QPoint( 3, 3 ) );

Last edited by sayakb on Fri Jan 02, 2009 5:49 pm, edited 1 time in total.


Image
[size=x-small]code | [url=cia.vc/stats/author/msoeken]cia.vc[/url] | [url=kde.org/support]donating KDE[/url] | [url=tinyurl.com/cto4ns]wishlist[/url][/size]
User avatar
Linex
Alumni
Posts
6
Karma
0
OS
I saw the patch below today on kde's bugzilla. The patch is quite similar to mine but I think mine is less complicating because it solved it at one place. In this proposed patch, the width and height are resized in the constructor. The width is first resized to an arbitary width(180). Then it is resized again in paintEvent(). I think its unnecessary to resize in paintEvent(), its not like the text or font going to change while counting down. Maybe I'm missing something here.

Furthermore, I think it is quite necessary to change the flag in boundingRect() to Qt::TextSingleLine so that even if in unforeseen situation, part of the text will at the very least be shown. If it is Qt::TextWordWrap, the slightest shortage of space on the left will wrap the rest of the text and in this case makes it not visible since the height of the widget is kinda fixed to the height of the font. So for what its worth, Qt::TextWordWrap really served no purpose here( in fact, less helpful ) except having to put something as part of the function's parameters. Qt::TextSingleLine would serve a better purpose instead.

The core issue in this bug is that we need to resize the SnapshotTimer widget which is a QWidget. But to what size ? The text is not declared yet so we don't know what size to resize the widget to. I can think of no other way except to declare the text first, and then resize() the qwidget, or do both in one line. I tried setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum ) in the constructor, nothing happened. It would be interesting to see if there is an alternative way.
Code: Select all
Proposed patch: adjust the widget size to the font width and height using QFontMetrics   (962 bytes, patch)
2008-12-31 18:22, Darío Andrés

--- kdegraphics/ksnapshot/snapshottimer.cpp   2008-12-31 15:20:31.000000000 -0200
+++ kdegraphics/ksnapshot/snapshottimer.new.cpp   2008-12-31 15:18:37.000000000 -0200
@@ -31,7 +31,7 @@
 SnapshotTimer::SnapshotTimer() : QWidget(0)
 {
     setWindowFlags( Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
-    resize(180,20);
+    resize(180,fontMetrics().height());
     connect(&timer, SIGNAL(timeout()), this, SLOT(bell()));
 }
 
@@ -86,6 +86,7 @@
       painter.setBrush( textBackgroundColor );
       QString helpText = i18np( "Snapshot will be taken in 1 second",
                                 "Snapshot will be taken in %1 seconds", ( length-time ) );
+      resize(fontMetrics().width(helpText)+6,size().height());
       QRect textRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText );
       textRect.adjust( -2, -2, 4, 2 );
       painter.drawRect( rect().adjusted(0,0,-1,-1) );

Last edited by Linex on Fri Jan 02, 2009 9:35 am, edited 1 time in total.


Alsagoff, proud to be a member of KDE forums since 2008-Dec.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], kesang, Sogou [Bot], Yahoo [Bot]