[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [Konversation] 1ae86fc: OSD changes: - New shadow instead of
From:       Christian Muehlhaeuser <chris () chris ! de>
Date:       2010-07-01 13:27:15
Message-ID: 20100701132715.7CC4EBB5565 () projects ! kde ! org
[Download RAW message or body]

commit 1ae86fccb230ea2fbbf7e8187ae0ee099afbd450
Author: Christian Muehlhaeuser <chris@chris.de>
Date:   Wed Jan 7 00:40:43 2004 +0000

    OSD changes:
    - New shadow instead of text-border -> less flickering
    - Minimum show time for an OSD message is 500ms, now -> no rushing
    - Complete double-buffering -> less flickering, still some left
      (setMask paints the masked (white) block, the method paintEvent
       draws the coloured image. If there's a break between the call
       of those two methods, it starts flickering. still dunno what to
       do about it)
    
    svn path=/trunk/kdeextragear-2/konversation/; revision=277431

diff --git a/konversation/osd.cpp b/konversation/osd.cpp
index c548005..a27a43e 100644
--- a/konversation/osd.cpp
+++ b/konversation/osd.cpp
@@ -27,41 +27,101 @@ OSDWidget::OSDWidget() : QWidget(NULL, "osd",
                                  WStyle_Customize | WStyle_NoBorder |
                                  WStyle_Tool | WRepaintNoErase | WX11BypassWM)
 {
-  // Get desktop dimensions
-  QWidget *d = QApplication::desktop();
-  int desktop_w = d->width();
-
   // Currently fixed to the top border of desktop, full width
   // This should be configurable, already on my TODO
-  move(5, 5);
-  resize(desktop_w - 10, 120);
-  setFocusPolicy(NoFocus);
-  timer = new QTimer(this);
+  move( 5, 5 );
+  resize( 0, 0 );
+  setFocusPolicy( NoFocus );
+  timer = new QTimer( this );
+  timerMin = new QTimer( this );
+  connect( timer, SIGNAL( timeout() ), this, SLOT( removeOSD() ) );
+  connect( timerMin, SIGNAL( timeout() ), this, SLOT( minReached() ) );
 }
 
-void OSDWidget::showOSD(const QString &text)
+void OSDWidget::paintOSD( const QString &text )
 {
-  if (isEnabled())
-  {
-    if (timer->isActive()) timer->stop();
+  this->text = text;
+  // Drawing process itself    
+  QPainter paint;
+  QColor bg( 0, 0, 0 );
+  QColor fg( 255, 255, 255 );
+    
+  QFontMetrics *fm = new QFontMetrics( font );
+      
+  // Get desktop dimensions
+  QWidget *d = QApplication::desktop();
+      
+  QRect fmRect = fm->boundingRect( 0, 0, d->width(), d->height(), AlignLeft | WordBreak, this->text );
+  fmRect.addCoords( 0, 0, fmRect.width() + 2, fmRect.height() + 2);
+  
+  resize( fmRect.size() );
+  //    QPixmap *buffer = new QPixmap( fmRect.width(), fmRect.height() );
+  QPixmap buffer = QPixmap( fmRect.size() );
+      
+  // Draw the OnScreenMessage
+  QPainter paintBuffer( &buffer );
+  paintBuffer.setFont( font );
+    
+  // Draw the border around the text
+  paintBuffer.setPen( black );
+/*  paintBuffer.drawText( 0, 0, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+  paintBuffer.drawText( 2, 0, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+  paintBuffer.drawText( 0, 2, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+  paintBuffer.drawText( 2, 2, width()-1, height()-1, AlignLeft | WordBreak, this->text );*/
+  paintBuffer.drawText( 3, 3, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+      
+  // Draw the text
+  paintBuffer.setPen( color );
+  paintBuffer.drawText( 1, 1, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+  paintBuffer.end();
+      
+  // Masking for transparency
+  QBitmap bm( fmRect.size() );
+  paint.begin( &bm );
+  paint.fillRect( 0, 0, fmRect.width(), fmRect.height(), bg );
+  paint.setPen( Qt::color0 );
+  paint.setFont( font );
+//  paint.drawText( 0, 0, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+  paint.drawText( 1, 1, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+  paint.drawText( 3, 3, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+//  paint.drawText( 2, 0, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+//  paint.drawText( 0, 2, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+//  paint.drawText( 2, 2, width()-1, height()-1, AlignLeft | WordBreak, this->text );
+  paint.end();
+    
+  delete fm;
+      
+  // Let's make it real, flush the buffers
+  osdBuffer = buffer;
+  // Repaint the QWidget and get it on top
+  setMask( bm );
+  //    qApp->syncX();
+  QWidget::show();
+  raise();
+  
+  // let it disappear via a QTimer
+  timer->start( 5000, TRUE );
+  timerMin->start( 500, TRUE );
+}
 
+void OSDWidget::showOSD( const QString &text )
+{
+  if ( isEnabled() )
+  {
     // Strip HTML tags, expand basic HTML entities
     QString plaintext = text.copy();
-    plaintext.replace(QRegExp("</?(?:font|a|b|i)\\b[^>]*>"), QString(""));
-    plaintext.replace(QRegExp("&lt;"), QString("<"));
-    plaintext.replace(QRegExp("&gt;"), QString(">"));
-    plaintext.replace(QRegExp("&amp;"), QString("&"));
-
-    this->text = plaintext;
-
-    // Repaint the QWidget and get it on top
-    QWidget::show();
-    repaint();
-    raise();
-
-    // let it disappear via a QTimer
-    connect(timer, SIGNAL(timeout()), this, SLOT(removeOSD()));
-    timer->start(5000, TRUE);
+    plaintext.replace( QRegExp( "</?(?:font|a|b|i)\\b[^>]*>" ), QString( "" ) );
+    plaintext.replace( QRegExp( "&lt;" ), QString( "<" ) );
+    plaintext.replace( QRegExp( "&gt;" ), QString( ">" ) );
+    plaintext.replace( QRegExp( "&amp;" ), QString( "&" ) );
+      
+    if ( timerMin->isActive() )
+      textBuffer.append( plaintext );
+    else
+    {
+      if ( timer->isActive() ) timer->stop();
+      paintOSD( plaintext );
+    }
   }
 }
 
@@ -75,6 +135,16 @@ void OSDWidget::setColor(QColor newcolor)
   color = newcolor;
 }
 
+void OSDWidget::minReached()
+{
+  if ( textBuffer.count() > 0 )
+  {
+    paintOSD( textBuffer[0] );
+    textBuffer.remove( textBuffer.at( 0 ) );
+  } else
+    this->text = "";
+}
+
 void OSDWidget::removeOSD()
 {
   // hide() and show() prevents flickering
@@ -82,49 +152,11 @@ void OSDWidget::removeOSD()
   this->text = "";
 }
 
-void OSDWidget::paintEvent(QPaintEvent*)
+void OSDWidget::paintEvent( QPaintEvent* )
 {
-  QPainter paint;
-  QPixmap *buffer = new QPixmap(width(), height());
-  QColor bg(0, 0, 0);
-  QColor fg(255, 255, 255);
-
-  qApp->syncX();
-
-  // Draw the OnScreenMessage
-  QPainter paintBuffer(buffer, this);
-  paintBuffer.setFont(font);
-
-  // Draw the border around the text
-  paintBuffer.setPen(black);
-  paintBuffer.drawText(0, 0, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paintBuffer.drawText(2, 0, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paintBuffer.drawText(0, 2, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paintBuffer.drawText(2, 2, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-
-  // Draw the text
-  paintBuffer.setPen(color);
-  paintBuffer.drawText(1, 1, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paintBuffer.end();
-
-  // Masking for transparency
-  QBitmap bm(size());
-  bm.fill(bg);
-  paint.begin(&bm, this);
-  paint.setPen(Qt::color0);
-  paint.setFont(font);
-  paint.drawText(0, 0, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paint.drawText(1, 1, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paint.drawText(2, 0, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paint.drawText(0, 2, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paint.drawText(2, 2, width()-1, height()-1, AlignLeft | WordBreak, this->text);
-  paint.end();
-
-  // Let's make it real, flush the buffers
-  bitBlt(this, 0, 0, buffer);
-  setMask(bm);
-
-  delete buffer;
+  QPainter p( this );
+  p.drawPixmap( 0, 0, osdBuffer );
+  p.end();
 }
 
 #include "osd.moc"
diff --git a/konversation/osd.h b/konversation/osd.h
index 4a59fb8..18abb91 100644
--- a/konversation/osd.h
+++ b/konversation/osd.h
@@ -35,14 +35,19 @@ class OSDWidget : public QWidget
         void setColor(QColor newcolor);
       protected slots:
         void removeOSD();
+        void minReached();
 //        void dblClick();
       protected:
+        void paintOSD(const QString &text);
         void paintEvent(QPaintEvent*);
 //        void mouseDoubleClickEvent(QMouseEvent *e);
         QString text;
         QTimer *timer;
+        QTimer *timerMin;
         QFont font;
         QColor color;
+        QPixmap osdBuffer;
+        QStringList textBuffer;
 };
 
 #endif
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic