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

kontact

  • sources
  • kde-4.12
  • kdepim
  • kontact
  • plugins
  • knotes
knotetip.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE project
3 
4  Copyright (C) 2004 Michael Brade <brade@kde.org>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; see the file COPYING. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include "knotetip.h"
34 #include "knotesiconview.h"
35 
36 #include <KCal/Journal>
37 using namespace KCal;
38 
39 
40 #include <KTextEdit>
41 #include <KGlobalSettings>
42 
43 #include <QAbstractEventDispatcher>
44 #include <QApplication>
45 #include <QBoxLayout>
46 #include <QToolTip>
47 
48 KNoteTip::KNoteTip( QListWidget *parent )
49  : QFrame( 0,
50  Qt::Tool |
51  Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint ),
52  mFilter( false ),
53  mView( parent ),
54  mNoteIVI( 0 ),
55  mPreview( new QTextEdit( this ) )
56 {
57  mPreview->setReadOnly( true );
58  mPreview->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
59  mPreview->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
60 
61  QBoxLayout *layout = new QVBoxLayout( this );
62  layout->addWidget( mPreview );
63  layout->setMargin( 1 );
64  setPalette( QToolTip::palette() );
65  setFrameStyle( QFrame::Plain );
66  hide();
67 }
68 
69 KNoteTip::~KNoteTip()
70 {
71  delete mPreview;
72  mPreview = 0;
73 }
74 
75 void KNoteTip::setNote( KNotesIconViewItem *item )
76 {
77  if ( mNoteIVI == item ) {
78  return;
79  }
80 
81  mNoteIVI = item;
82  if ( !mNoteIVI ) {
83  QAbstractEventDispatcher::instance()->unregisterTimers(this);
84  if ( isVisible() ) {
85  setFilter( false );
86  hide();
87  }
88  } else {
89  Journal *journal = item->journal();
90  mPreview->setAcceptRichText( journal->customProperty( "KNotes", "RichText" ) == QLatin1String("true") );
91 
92  const QColor fg( journal->customProperty( "KNotes", "FgColor" ) );
93  const QColor bg( journal->customProperty( "KNotes", "BgColor" ) );
94  setColor( fg, bg );
95 
96  mPreview->setText( journal->description() );
97  //mPreview->zoomTo( 8 );
98  //mPreview->sync(); this is deprecated in Qt4, but there is no replacement
99 
100  mPreview->document()->adjustSize ();
101  int w = int( mPreview->document ()->size().width() );
102  const int h = int( mPreview->document ()->size().height() );
103  while ( w > 60 && h == mPreview->heightForWidth( w - 20 ) ) {
104  w -= 20;
105  }
106 
107  const QRect desk = KGlobalSettings::desktopGeometry( mView->visualItemRect( mNoteIVI ).center() );
108  resize( w, qMin( h, desk.height() / 2 - 20 ) );
109 
110  hide();
111  QAbstractEventDispatcher::instance()->unregisterTimers( this );
112  setFilter( true );
113  startTimer( 600 ); // delay showing the tooltip for 0.7 sec
114  }
115 }
116 
117 // protected, virtual methods
118 
119 void KNoteTip::resizeEvent( QResizeEvent *ev )
120 {
121  QFrame::resizeEvent( ev );
122  reposition();
123 }
124 
125 void KNoteTip::timerEvent( QTimerEvent * )
126 {
127  QAbstractEventDispatcher::instance()->unregisterTimers( this );
128 
129  if ( !isVisible() ) {
130  startTimer( 15000 ); // show the tooltip for 15 sec
131  reposition();
132  show();
133  } else {
134  setFilter( false );
135  hide();
136  }
137 }
138 
139 bool KNoteTip::eventFilter( QObject *, QEvent *e )
140 {
141  switch ( e->type() ) {
142  case QEvent::Leave:
143  case QEvent::MouseButtonPress:
144  case QEvent::MouseButtonRelease:
145  case QEvent::KeyPress:
146  case QEvent::KeyRelease:
147  case QEvent::FocusIn:
148  case QEvent::FocusOut:
149  case QEvent::Wheel:
150  QAbstractEventDispatcher::instance()->unregisterTimers(this);
151  setFilter( false );
152  hide();
153  default:
154  break;
155  }
156 
157  return false;
158 }
159 
160 // private stuff
161 
162 void KNoteTip::setColor( const QColor &fg, const QColor &bg )
163 {
164  QPalette newpalette = palette();
165  newpalette.setColor( QPalette::Background, bg );
166  newpalette.setColor( QPalette::Foreground, fg );
167  newpalette.setColor( QPalette::Base, bg ); // text background
168  newpalette.setColor( QPalette::Text, fg ); // text color
169  newpalette.setColor( QPalette::Button, bg );
170 
171  // the shadow
172  newpalette.setColor( QPalette::Midlight, bg.light(110) );
173  newpalette.setColor( QPalette::Shadow, bg.dark(116) );
174  newpalette.setColor( QPalette::Light, bg.light(180) );
175  newpalette.setColor( QPalette::Dark, bg.dark(108) );
176  setPalette( newpalette );
177 
178  // set the text color
179  mPreview->setTextColor( fg );
180 }
181 
182 void KNoteTip::setFilter( bool enable )
183 {
184  if ( enable == mFilter ) {
185  return;
186  }
187 
188  if ( enable ) {
189  qApp->installEventFilter( this );
190  setMouseTracking( true );
191  } else {
192  setMouseTracking( false );
193  qApp->removeEventFilter( this );
194  }
195 
196  mFilter = enable;
197 }
198 
199 void KNoteTip::reposition()
200 {
201  if ( !mNoteIVI ) {
202  return;
203  }
204 
205  QRect rect = mView->visualItemRect( mNoteIVI );
206  const QPoint off = mView->mapFromParent( mView->viewport()->mapToGlobal( QPoint( 0, 0 ) ) );
207  rect.translate( off.x(), off.y() );
208 
209  QPoint pos = rect.center();
210  // should the tooltip be shown to the left or to the right of the ivi?
211  const QRect desk = KGlobalSettings::desktopGeometry( pos );
212  if ( rect.center().x() + width() > desk.right() ) {
213  // to the left
214  if ( pos.x() - width() < 0 ) {
215  pos.setX( 0 );
216  } else {
217  pos.setX( pos.x() - width() );
218  }
219  }
220 
221  // should the tooltip be shown above or below the ivi ?
222  if ( rect.bottom() + height() > desk.bottom() ) {
223  // above
224  pos.setY( rect.top() - height() );
225  } else {
226  pos.setY( rect.bottom() );
227  }
228  move( pos );
229  update();
230 }
QListWidget
KNotesIconViewItem::journal
Journal * journal() const
Definition: knotesiconview.cpp:86
QObject
KNoteTip::~KNoteTip
~KNoteTip()
Definition: knotetip.cpp:69
knotetip.h
KNoteTip::KNoteTip
KNoteTip(QListWidget *parent)
Definition: knotetip.cpp:48
KNoteTip::eventFilter
bool eventFilter(QObject *, QEvent *e)
Definition: knotetip.cpp:139
KNoteTip::setNote
void setNote(KNotesIconViewItem *item)
Definition: knotetip.cpp:75
knotesiconview.h
KNotesIconViewItem
Definition: knotesiconview.h:37
KNoteTip::timerEvent
void timerEvent(QTimerEvent *)
Definition: knotetip.cpp:125
QFrame
KNoteTip::resizeEvent
void resizeEvent(QResizeEvent *)
Definition: knotetip.cpp:119
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:30 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kontact

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal