2006-08-11 23:53:48 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Chu Xiaodong <xiaodongchu@gmail.com> *
|
2006-09-17 16:09:10 +00:00
|
|
|
* Copyright (C) 2006 by Pino Toscano <pino@kde.org> *
|
2006-08-11 23:53:48 +00:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
2006-09-16 16:38:09 +00:00
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "annotwindow.h"
|
|
|
|
|
2006-09-16 16:38:09 +00:00
|
|
|
// qt/kde includes
|
2006-09-17 16:09:10 +00:00
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qevent.h>
|
|
|
|
#include <qfont.h>
|
2006-09-19 10:20:13 +00:00
|
|
|
#include <qfontinfo.h>
|
|
|
|
#include <qfontmetrics.h>
|
2006-09-16 17:06:56 +00:00
|
|
|
#include <qframe.h>
|
2006-09-17 16:09:10 +00:00
|
|
|
#include <qlabel.h>
|
|
|
|
#include <qlayout.h>
|
2006-08-11 23:53:48 +00:00
|
|
|
#include <QPainter>
|
2006-09-16 17:06:56 +00:00
|
|
|
#include <qpushbutton.h>
|
2007-07-23 13:05:26 +00:00
|
|
|
#include <qsizegrip.h>
|
2006-09-16 17:06:56 +00:00
|
|
|
#include <qstyle.h>
|
|
|
|
#include <qtextedit.h>
|
2006-09-17 16:09:10 +00:00
|
|
|
#include <qtoolbutton.h>
|
2006-09-16 16:38:09 +00:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <klocale.h>
|
2006-09-19 10:20:13 +00:00
|
|
|
#include <kdebug.h>
|
2006-08-11 23:53:48 +00:00
|
|
|
|
2006-09-16 16:38:09 +00:00
|
|
|
// local includes
|
2006-09-16 17:06:56 +00:00
|
|
|
#include "core/annotations.h"
|
|
|
|
|
|
|
|
|
|
|
|
class CloseButton
|
|
|
|
: public QPushButton
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CloseButton( QWidget * parent = 0 )
|
|
|
|
: QPushButton( parent )
|
|
|
|
{
|
|
|
|
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
2006-09-17 16:09:10 +00:00
|
|
|
QSize size = QSize( 14, 14 ).expandedTo( QApplication::globalStrut() );
|
|
|
|
setFixedSize( size );
|
2006-09-16 17:06:56 +00:00
|
|
|
setIcon( style()->standardIcon( QStyle::SP_DockWidgetCloseButton ) );
|
2006-09-17 16:09:10 +00:00
|
|
|
setIconSize( size );
|
2006-09-16 17:06:56 +00:00
|
|
|
setToolTip( i18n( "Close" ) );
|
|
|
|
}
|
|
|
|
};
|
2006-08-11 23:53:48 +00:00
|
|
|
|
|
|
|
|
2006-09-17 16:09:10 +00:00
|
|
|
class MovableTitle
|
|
|
|
: public QWidget
|
2006-08-11 23:53:48 +00:00
|
|
|
{
|
2006-09-17 16:09:10 +00:00
|
|
|
public:
|
|
|
|
MovableTitle( QWidget * parent )
|
|
|
|
: QWidget( parent )
|
|
|
|
{
|
|
|
|
QVBoxLayout * mainlay = new QVBoxLayout( this );
|
|
|
|
mainlay->setMargin( 0 );
|
|
|
|
mainlay->setSpacing( 0 );
|
|
|
|
// close button row
|
|
|
|
QHBoxLayout * buttonlay = new QHBoxLayout();
|
|
|
|
mainlay->addLayout( buttonlay );
|
|
|
|
titleLabel = new QLabel( this );
|
|
|
|
QFont f = titleLabel->font();
|
|
|
|
f.setBold( true );
|
|
|
|
titleLabel->setFont( f );
|
|
|
|
titleLabel->setCursor( Qt::SizeAllCursor );
|
|
|
|
buttonlay->addWidget( titleLabel );
|
|
|
|
dateLabel = new QLabel( this );
|
|
|
|
dateLabel->setAlignment( Qt::AlignTop | Qt::AlignRight );
|
2006-09-19 10:20:13 +00:00
|
|
|
f = dateLabel->font();
|
|
|
|
f.setPointSize( QFontInfo( f ).pointSize() - 2 );
|
|
|
|
dateLabel->setFont( f );
|
2006-09-17 16:09:10 +00:00
|
|
|
dateLabel->setCursor( Qt::SizeAllCursor );
|
|
|
|
buttonlay->addWidget( dateLabel );
|
|
|
|
CloseButton * close = new CloseButton( this );
|
|
|
|
connect( close, SIGNAL( clicked() ), parent, SLOT( hide() ) );
|
|
|
|
buttonlay->addWidget( close );
|
|
|
|
// option button row
|
|
|
|
QHBoxLayout * optionlay = new QHBoxLayout();
|
|
|
|
mainlay->addLayout( optionlay );
|
|
|
|
authorLabel = new QLabel( this );
|
|
|
|
authorLabel->setCursor( Qt::SizeAllCursor );
|
|
|
|
authorLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum );
|
|
|
|
optionlay->addWidget( authorLabel );
|
|
|
|
optionButton = new QToolButton( this );
|
2006-09-19 10:20:13 +00:00
|
|
|
QString opttext = i18n( "Options" );
|
|
|
|
optionButton->setText( opttext );
|
2006-09-17 16:09:10 +00:00
|
|
|
optionButton->setAutoRaise( true );
|
2006-09-19 10:20:13 +00:00
|
|
|
QSize s = QFontMetrics( optionButton->font() ).boundingRect( opttext ).size() + QSize( 8, 8 );
|
|
|
|
optionButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
|
|
|
optionButton->setFixedSize( s );
|
2006-09-17 16:09:10 +00:00
|
|
|
optionlay->addWidget( optionButton );
|
2007-12-07 21:55:41 +00:00
|
|
|
// ### disabled for now
|
|
|
|
optionButton->hide();
|
2006-09-17 16:09:10 +00:00
|
|
|
|
|
|
|
titleLabel->installEventFilter( this );
|
|
|
|
dateLabel->installEventFilter( this );
|
|
|
|
authorLabel->installEventFilter( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool eventFilter( QObject * obj, QEvent * e )
|
|
|
|
{
|
|
|
|
if ( obj != titleLabel && obj != authorLabel && obj != dateLabel )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QMouseEvent * me = 0;
|
|
|
|
switch ( e->type() )
|
|
|
|
{
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
me = (QMouseEvent*)e;
|
|
|
|
mousePressPos = me->pos();
|
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
mousePressPos = QPoint();
|
|
|
|
break;
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
me = (QMouseEvent*)e;
|
|
|
|
parentWidget()->move( me->pos() - mousePressPos + parentWidget()->pos() );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTitle( const QString& title )
|
|
|
|
{
|
|
|
|
titleLabel->setText( QString( " " ) + title );
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDate( const QDateTime& dt )
|
|
|
|
{
|
2007-04-09 23:36:26 +00:00
|
|
|
dateLabel->setText( KGlobal::locale()->formatDateTime( dt, KLocale::ShortDate, true ) + ' ' );
|
2006-09-17 16:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setAuthor( const QString& author )
|
|
|
|
{
|
|
|
|
authorLabel->setText( QString( " " ) + author );
|
|
|
|
}
|
|
|
|
|
|
|
|
void connectOptionButton( QObject * recv, const char* method )
|
|
|
|
{
|
|
|
|
connect( optionButton, SIGNAL( clicked() ), recv, method );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QLabel * titleLabel;
|
|
|
|
QLabel * dateLabel;
|
|
|
|
QLabel * authorLabel;
|
|
|
|
QPoint mousePressPos;
|
|
|
|
QToolButton * optionButton;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-07-23 13:05:26 +00:00
|
|
|
// Qt::SubWindow is needed to make QSizeGrip work
|
2006-09-21 08:45:36 +00:00
|
|
|
AnnotWindow::AnnotWindow( QWidget * parent, Okular::Annotation * annot)
|
2007-07-23 13:05:26 +00:00
|
|
|
: QFrame( parent, Qt::SubWindow ), m_annot( annot )
|
2006-08-11 23:53:48 +00:00
|
|
|
{
|
2006-09-17 16:09:10 +00:00
|
|
|
setAutoFillBackground( true );
|
|
|
|
setFrameStyle( Panel | Raised );
|
|
|
|
|
2006-12-05 11:05:50 +00:00
|
|
|
textEdit=new QTextEdit(m_annot->window().text(), this);
|
2006-08-11 23:53:48 +00:00
|
|
|
connect(textEdit,SIGNAL(textChanged()),
|
|
|
|
this,SLOT(slotsaveWindowText()));
|
|
|
|
|
2006-12-05 11:05:50 +00:00
|
|
|
QColor col = m_annot->style().color().isValid() ? m_annot->style().color() : Qt::yellow;
|
2006-09-17 18:22:00 +00:00
|
|
|
setPalette( QPalette( col ) );
|
2006-08-11 23:53:48 +00:00
|
|
|
QPalette pl=textEdit->palette();
|
2006-09-17 18:22:00 +00:00
|
|
|
pl.setColor( QPalette::Base, col );
|
2006-08-11 23:53:48 +00:00
|
|
|
textEdit->setPalette(pl);
|
|
|
|
|
2006-09-17 16:09:10 +00:00
|
|
|
QVBoxLayout * mainlay = new QVBoxLayout( this );
|
|
|
|
mainlay->setMargin( 2 );
|
|
|
|
mainlay->setSpacing( 0 );
|
|
|
|
m_title = new MovableTitle( this );
|
|
|
|
mainlay->addWidget( m_title );
|
|
|
|
mainlay->addWidget( textEdit );
|
|
|
|
QHBoxLayout * lowerlay = new QHBoxLayout();
|
|
|
|
mainlay->addLayout( lowerlay );
|
|
|
|
lowerlay->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Fixed ) );
|
2007-07-23 13:05:26 +00:00
|
|
|
QSizeGrip * sb = new QSizeGrip( this );
|
2006-09-17 16:09:10 +00:00
|
|
|
lowerlay->addWidget( sb );
|
|
|
|
|
2006-12-05 11:05:50 +00:00
|
|
|
m_title->setTitle( m_annot->window().summary() );
|
|
|
|
m_title->setDate( m_annot->modificationDate() );
|
|
|
|
m_title->setAuthor( m_annot->author() );
|
2006-09-17 16:09:10 +00:00
|
|
|
m_title->connectOptionButton( this, SLOT( slotOptionBtn() ) );
|
2006-08-11 23:53:48 +00:00
|
|
|
|
2006-09-17 16:09:10 +00:00
|
|
|
setGeometry(10,10,300,300 );
|
2006-08-11 23:53:48 +00:00
|
|
|
}
|
|
|
|
|
2006-09-17 16:09:10 +00:00
|
|
|
void AnnotWindow::slotOptionBtn()
|
2006-08-11 23:53:48 +00:00
|
|
|
{
|
|
|
|
//TODO: call context menu in pageview
|
|
|
|
//emit sig...
|
|
|
|
}
|
2006-09-17 16:09:10 +00:00
|
|
|
|
2006-08-11 23:53:48 +00:00
|
|
|
void AnnotWindow::slotsaveWindowText()
|
|
|
|
{
|
2006-12-05 11:05:50 +00:00
|
|
|
m_annot->window().setText( textEdit->toPlainText() );
|
2006-08-11 23:53:48 +00:00
|
|
|
}
|
2006-09-17 16:09:10 +00:00
|
|
|
|
2006-08-11 23:53:48 +00:00
|
|
|
#include "annotwindow.moc"
|