[Kwintv] New thoughts on Elegant

Rizsanyi Zsolt kwintv@mail.kde.org
Tue, 24 Sep 2002 12:34:47 +0200


--------------Boundary-00=_ZPUXI6V74MH0EP5N40S2
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

On Tuesday 24 September 2002 00:34, George Staikos wrote:
> Another approach would be to make Elegant a KDE 3.1 or better plugin.  We
> could have a configure check to determine if it should be built.  This
> might be a nicer approach as Haze could be used for KDE 3.0 users while 3.1
> users will get the benefits of the nicer plugin.  However, Elegant looks
> very nice and it might be worthwhile trying to make it work with 3.0.

It was pretty simple to (back)port it to 3.0. Here is the attached patch.

I have also included in my patch a new configure option to the elegant plugin 
AutoFontSize. If that is enabled the font size is automatically changed when 
qtvision is resized (or changed to full screen). This way the shown text 
always stays on screen even if you resize qtvision to a small screen (or you 
have long channel names).

Regards
Zsolt
--------------Boundary-00=_ZPUXI6V74MH0EP5N40S2
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="elegant.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="elegant.patch"

Index: qtvision/plugins/osd/elegant/elegant.cpp
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/plugins/osd/elegant/elegant.cpp,v
retrieving revision 1.6
diff -u -r1.6 elegant.cpp
--- qtvision/plugins/osd/elegant/elegant.cpp	23 Sep 2002 22:45:51 -0000	1.6
+++ qtvision/plugins/osd/elegant/elegant.cpp	24 Sep 2002 10:20:30 -0000
@@ -43,7 +43,7 @@
       parent(p),
       align(AlignBottom|AlignCenter), indent(20),
       iconSize(KIcon::SizeLarge), fontSize(48),
-      fontBold(true), fontItalic(false), fontUnderline(false)
+      fontBold(true), fontItalic(false), fontUnderline(false), autoFontSize(false)
 {
     timer = new QTimer( this );
     popup = new KPopupTitle( p, "display" );
@@ -54,7 +54,7 @@
     updateGeometry();
 
     connect( timer, SIGNAL( timeout() ), popup, SLOT( hide() ) );
-//    connect( parent, SIGNAL( resized(int,int) ), this, SLOT( viewResized(int,int) ) );
+    connect( parent, SIGNAL( resized(int,int) ), this, SLOT( viewResized(int,int) ) );
 }
 
 QtVisionElegant::~QtVisionElegant()
@@ -83,6 +83,7 @@
     fontBold = _cfg->readBoolEntry( "FontBold", true );
     fontItalic = _cfg->readBoolEntry( "FontItalic", false );
     fontUnderline = _cfg->readBoolEntry( "FontUnderline", false );
+    autoFontSize = _cfg->readBoolEntry( "AutoFontSize", true );
 }
 
 void QtVisionElegant::writeConfig()
@@ -94,6 +95,7 @@
     _cfg->writeEntry( "FontBold", fontBold );
     _cfg->writeEntry( "FontItalic", fontItalic );
     _cfg->writeEntry( "FontUnderline", fontUnderline );
+    _cfg->writeEntry( "AutoFontSize", autoFontSize );
 }
 
 void QtVisionElegant::updateGeometry()
@@ -121,8 +123,8 @@
 
 void QtVisionElegant::clear()
 {
-    popup->setIcon( KGlobal::iconLoader()->loadIcon("kwintv", KIcon::NoGroup, iconSize) );
-    popup->setText( i18n("Elegant OSD") );
+    static QPixmap kwicon = KGlobal::iconLoader()->loadIcon("kwintv", KIcon::NoGroup, iconSize);
+    popup->setTitle(i18n("Elegant OSD"), &kwicon);
 }
 
 void QtVisionElegant::showPopup()
@@ -140,8 +142,7 @@
 
 void QtVisionElegant::display( const QString &text, const QPixmap &icon )
 {
-    popup->setText( text );
-    popup->setIcon( icon );
+    popup->setTitle(text, &icon);
     showPopup();
 }
 
@@ -174,8 +175,14 @@
     display( text );
 }
 
-void QtVisionElegant::viewResized( int /*w*/, int /*h*/ )
+void QtVisionElegant::viewResized( int w, int /*h*/ )
 {
+    if (!autoFontSize)
+	return;
+    QFont font = popup->font();
+    font.setPixelSize(w / 15);
+    popup->setFont( font );
+    kdDebug() << "elegant font resized to " << w / 15 << endl;
     if ( !popup->isHidden() ) {
 	updateGeometry();
     }
@@ -204,6 +211,7 @@
     form->BoldCheck->setChecked( fontBold );
     form->ItalicCheck->setChecked( fontItalic );
     form->UnderlineCheck->setChecked( fontUnderline );
+    form->AutoFontSizeCheck->setChecked( autoFontSize );
 
     return form;
 }
@@ -216,6 +224,7 @@
     fontBold = form->BoldCheck->isChecked();
     fontItalic = form->ItalicCheck->isChecked();
     fontUnderline = form->UnderlineCheck->isChecked();
+    autoFontSize = form->AutoFontSizeCheck->isChecked();
 
     switch ( form->HSlider->value() ) {
 	case 0:
Index: qtvision/plugins/osd/elegant/elegant.h
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/plugins/osd/elegant/elegant.h,v
retrieving revision 1.5
diff -u -r1.5 elegant.h
--- qtvision/plugins/osd/elegant/elegant.h	23 Sep 2002 00:41:19 -0000	1.5
+++ qtvision/plugins/osd/elegant/elegant.h	24 Sep 2002 10:20:31 -0000
@@ -88,6 +88,7 @@
     bool fontBold;
     bool fontItalic;
     bool fontUnderline;
+    bool autoFontSize;
 };
 
 #endif
Index: qtvision/plugins/osd/elegant/elegantconfigwidget.ui
===================================================================
RCS file: /home/kde/kdenonbeta/kwintv3/qtvision/plugins/osd/elegant/elegantconfigwidget.ui,v
retrieving revision 1.3
diff -u -r1.3 elegantconfigwidget.ui
--- qtvision/plugins/osd/elegant/elegantconfigwidget.ui	23 Sep 2002 22:45:51 -0000	1.3
+++ qtvision/plugins/osd/elegant/elegantconfigwidget.ui	24 Sep 2002 10:20:31 -0000
@@ -250,6 +250,14 @@
                             <string>Italic</string>
                         </property>
                     </widget>
+                    <widget class="QCheckBox" row="3" column="0">
+                        <property name="name">
+                            <cstring>AutoFontSizeCheck</cstring>
+                        </property>
+                        <property name="text">
+                            <string>Auto font size</string>
+                        </property>
+                    </widget>
                     <spacer row="3" column="1" rowspan="1" colspan="2">
                         <property name="name">
                             <cstring>Spacer23_2_3</cstring>

--------------Boundary-00=_ZPUXI6V74MH0EP5N40S2--