• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kontact

knotetip.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of the KDE project
00003 
00004   Copyright (C) 2004 Michael Brade <brade@kde.org>
00005 
00006   This program is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU General Public
00008   License as published by the Free Software Foundation; either
00009   version 2 of the License, or (at your option) any later version.
00010 
00011   This program is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   General Public License for more details.
00015 
00016   You should have received a copy of the GNU General Public License
00017   along with this program; see the file COPYING.  If not, write to
00018   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019   Boston, MA 02110-1301, USA.
00020 
00021   In addition, as a special exception, the copyright holders give
00022   permission to link the code of this program with any edition of
00023   the Qt library by Trolltech AS, Norway (or with modified versions
00024   of Qt that use the same license as Qt), and distribute linked
00025   combinations including the two.  You must obey the GNU General
00026   Public License in all respects for all of the code used other than
00027   Qt.  If you modify this file, you may extend this exception to
00028   your version of the file, but you are not obligated to do so.  If
00029   you do not wish to do so, delete this exception statement from
00030   your version.
00031 */
00032 
00033 #include "knotetip.h"
00034 #include "knotes_part_p.h"
00035 
00036 #include <kglobalsettings.h>
00037 
00038 #include <Q3Frame>
00039 #include <QAbstractEventDispatcher>
00040 #include <QApplication>
00041 #include <QToolTip>
00042 #include <QLayout>
00043 #include <QTextEdit>
00044 #include <QEvent>
00045 #include <QTimerEvent>
00046 #include <QResizeEvent>
00047 #include <QVBoxLayout>
00048 
00049 KNoteTip::KNoteTip( K3IconView *parent )
00050   : Q3Frame( 0, 0, Qt::WX11BypassWM |   // this will make Seli happy >:-P
00051              Qt::WStyle_Customize | Qt::WStyle_NoBorder | Qt::WStyle_Tool | Qt::WStyle_StaysOnTop ),
00052     mFilter( false ),
00053     mView( parent ),
00054     mNoteIVI( 0 ),
00055     mPreview( new QTextEdit( this ) )
00056 {
00057   mPreview->setReadOnly( true );
00058   mPreview->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
00059   mPreview->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
00060 
00061   QBoxLayout *layout = new QVBoxLayout( this );
00062   layout->addWidget( mPreview );
00063 
00064   setPalette( QToolTip::palette() );
00065   setMargin( 1 );
00066   setFrameStyle( Q3Frame::Plain | Q3Frame::Box );
00067   hide();
00068 }
00069 
00070 KNoteTip::~KNoteTip()
00071 {
00072   delete mPreview;
00073   mPreview = 0;
00074 }
00075 
00076 void KNoteTip::setNote( KNotesIconViewItem *item )
00077 {
00078   if ( mNoteIVI == item ) {
00079     return;
00080   }
00081 
00082   mNoteIVI = item;
00083 
00084   if ( !mNoteIVI ) {
00085     QAbstractEventDispatcher::instance()->unregisterTimers(this);
00086     if ( isVisible() ) {
00087       setFilter( false );
00088       hide();
00089     }
00090   } else {
00091     KCal::Journal *journal = item->journal();
00092     if ( journal->customProperty( "KNotes", "RichText" ) == "true" ) {
00093       mPreview->setTextFormat( Qt::RichText );
00094     } else {
00095       mPreview->setTextFormat( Qt::PlainText );
00096     }
00097 
00098     QColor fg( journal->customProperty( "KNotes", "FgColor" ) );
00099     QColor bg( journal->customProperty( "KNotes", "BgColor" ) );
00100     setColor( fg, bg );
00101 
00102     mPreview->setText( journal->description() );
00103     //mPreview->zoomTo( 8 );
00104     mPreview->sync();
00105 
00106     int w = 400;
00107     int h = mPreview->heightForWidth( w );
00108     while ( w > 60 && h == mPreview->heightForWidth( w - 20 ) ) {
00109       w -= 20;
00110     }
00111 
00112     QRect desk = KGlobalSettings::desktopGeometry( mNoteIVI->rect().center() );
00113     resize( w, qMin( h, desk.height() / 2 - 20 ) );
00114 
00115     hide();
00116     QAbstractEventDispatcher::instance()->unregisterTimers( this );
00117     setFilter( true );
00118     startTimer( 600 );  // delay showing the tooltip for 0.7 sec
00119   }
00120 }
00121 
00122 // protected, virtual methods
00123 
00124 void KNoteTip::resizeEvent( QResizeEvent *ev )
00125 {
00126   Q3Frame::resizeEvent( ev );
00127   reposition();
00128 }
00129 
00130 void KNoteTip::timerEvent( QTimerEvent * )
00131 {
00132   QAbstractEventDispatcher::instance()->unregisterTimers( this );
00133 
00134   if ( !isVisible() ) {
00135     startTimer( 15000 ); // show the tooltip for 15 sec
00136     reposition();
00137     show();
00138   } else {
00139     setFilter( false );
00140     hide();
00141   }
00142 }
00143 
00144 bool KNoteTip::eventFilter( QObject *, QEvent *e )
00145 {
00146   switch ( e->type() ) {
00147   case QEvent::Leave:
00148   case QEvent::MouseButtonPress:
00149   case QEvent::MouseButtonRelease:
00150   case QEvent::KeyPress:
00151   case QEvent::KeyRelease:
00152   case QEvent::FocusIn:
00153   case QEvent::FocusOut:
00154   case QEvent::Wheel:
00155     QAbstractEventDispatcher::instance()->unregisterTimers(this);
00156     setFilter( false );
00157     hide();
00158   default:
00159     break;
00160   }
00161 
00162   return false;
00163 }
00164 
00165 // private stuff
00166 
00167 void KNoteTip::setColor( const QColor &fg, const QColor &bg )
00168 {
00169   QPalette newpalette = palette();
00170   newpalette.setColor( QPalette::Background, bg );
00171   newpalette.setColor( QPalette::Foreground, fg );
00172   newpalette.setColor( QPalette::Base, bg ); // text background
00173   newpalette.setColor( QPalette::Text, fg ); // text color
00174   newpalette.setColor( QPalette::Button, bg );
00175 
00176   // the shadow
00177   newpalette.setColor( QPalette::Midlight, bg.light(110) );
00178   newpalette.setColor( QPalette::Shadow, bg.dark(116) );
00179   newpalette.setColor( QPalette::Light, bg.light(180) );
00180   newpalette.setColor( QPalette::Dark, bg.dark(108) );
00181   setPalette( newpalette );
00182 
00183   // set the text color
00184   mPreview->setColor( fg );
00185 }
00186 
00187 void KNoteTip::setFilter( bool enable )
00188 {
00189   if ( enable == mFilter ) {
00190     return;
00191   }
00192 
00193   if ( enable ) {
00194     qApp->installEventFilter( this );
00195     QApplication::setGlobalMouseTracking( true );
00196   } else {
00197     QApplication::setGlobalMouseTracking( false );
00198     qApp->removeEventFilter( this );
00199   }
00200 
00201   mFilter = enable;
00202 }
00203 
00204 void KNoteTip::reposition()
00205 {
00206   if ( !mNoteIVI ) {
00207     return;
00208   }
00209 
00210   QRect rect = mNoteIVI->rect();
00211   QPoint off = mView->mapToGlobal( mView->contentsToViewport( QPoint( 0, 0 ) ) );
00212   rect.translate( off.x(), off.y() );
00213 
00214   QPoint pos = rect.center();
00215 
00216   // should the tooltip be shown to the left or to the right of the ivi?
00217   QRect desk = KGlobalSettings::desktopGeometry( pos );
00218   if ( rect.center().x() + width() > desk.right() ) {
00219     // to the left
00220     if ( pos.x() - width() < 0 ) {
00221       pos.setX( 0 );
00222     } else {
00223       pos.setX( pos.x() - width() );
00224     }
00225   }
00226 
00227   // should the tooltip be shown above or below the ivi ?
00228   if ( rect.bottom() + height() > desk.bottom() ) {
00229     // above
00230     pos.setY( rect.top() - height() );
00231   } else {
00232     pos.setY( rect.bottom() );
00233   }
00234 
00235   move( pos );
00236   update();
00237 }

kontact

Skip menu "kontact"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal