36 #include <KCal/Journal>
41 #include <KGlobalSettings>
43 #include <QAbstractEventDispatcher>
44 #include <QApplication>
51 Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint ),
55 mPreview( new QTextEdit( this ) )
57 mPreview->setReadOnly(
true );
58 mPreview->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
59 mPreview->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
61 QBoxLayout *layout =
new QVBoxLayout(
this );
62 layout->addWidget( mPreview );
63 layout->setMargin( 1 );
64 setPalette( QToolTip::palette() );
65 setFrameStyle( QFrame::Plain );
77 if ( mNoteIVI == item ) {
83 QAbstractEventDispatcher::instance()->unregisterTimers(
this);
89 Journal *journal = item->
journal();
90 mPreview->setAcceptRichText( journal->customProperty(
"KNotes",
"RichText" ) == QLatin1String(
"true") );
92 const QColor fg( journal->customProperty(
"KNotes",
"FgColor" ) );
93 const QColor bg( journal->customProperty(
"KNotes",
"BgColor" ) );
96 mPreview->setText( journal->description() );
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 ) ) {
107 const QRect desk = KGlobalSettings::desktopGeometry( mView->visualItemRect( mNoteIVI ).center() );
108 resize( w, qMin( h, desk.height() / 2 - 20 ) );
111 QAbstractEventDispatcher::instance()->unregisterTimers(
this );
121 QFrame::resizeEvent( ev );
127 QAbstractEventDispatcher::instance()->unregisterTimers(
this );
129 if ( !isVisible() ) {
141 switch ( e->type() ) {
143 case QEvent::MouseButtonPress:
144 case QEvent::MouseButtonRelease:
145 case QEvent::KeyPress:
146 case QEvent::KeyRelease:
147 case QEvent::FocusIn:
148 case QEvent::FocusOut:
150 QAbstractEventDispatcher::instance()->unregisterTimers(
this);
162 void KNoteTip::setColor(
const QColor &fg,
const QColor &bg )
164 QPalette newpalette = palette();
165 newpalette.setColor( QPalette::Background, bg );
166 newpalette.setColor( QPalette::Foreground, fg );
167 newpalette.setColor( QPalette::Base, bg );
168 newpalette.setColor( QPalette::Text, fg );
169 newpalette.setColor( QPalette::Button, bg );
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 );
179 mPreview->setTextColor( fg );
182 void KNoteTip::setFilter(
bool enable )
184 if ( enable == mFilter ) {
189 qApp->installEventFilter(
this );
190 setMouseTracking(
true );
192 setMouseTracking(
false );
193 qApp->removeEventFilter(
this );
199 void KNoteTip::reposition()
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() );
209 QPoint pos = rect.center();
211 const QRect desk = KGlobalSettings::desktopGeometry( pos );
212 if ( rect.center().x() + width() > desk.right() ) {
214 if ( pos.x() - width() < 0 ) {
217 pos.setX( pos.x() - width() );
222 if ( rect.bottom() + height() > desk.bottom() ) {
224 pos.setY( rect.top() - height() );
226 pos.setY( rect.bottom() );
Journal * journal() const
KNoteTip(QListWidget *parent)
bool eventFilter(QObject *, QEvent *e)
void setNote(KNotesIconViewItem *item)
void timerEvent(QTimerEvent *)
void resizeEvent(QResizeEvent *)