replace embedded annotation dialog with annot window, child of PageView

svn path=/trunk/playground/graphics/okular/; revision=572243
remotes/origin/KDE/4.0
Chu Xiaodong 20 years ago
parent a6516a74ef
commit 9c575a91d3
  1. 2
      CMakeLists.txt
  2. 175
      ui/annotwindow.cpp
  3. 85
      ui/annotwindow.h
  4. 6
      ui/pagepainter.cpp
  5. 44
      ui/pageview.cpp
  6. 4
      ui/pageviewannotator.cpp

@ -70,7 +70,7 @@ install(TARGETS okularcore DESTINATION ${LIB_INSTALL_DIR} )
set(okularpart_SRCS set(okularpart_SRCS
part.cpp part.cpp
ui/embeddedfilesdialog.cpp ui/embeddedfilesdialog.cpp
ui/embeddedannotationdialog.cpp ui/annotwindow.cpp
ui/annotationpropertiesdialog.cpp ui/annotationpropertiesdialog.cpp
ui/minibar.cpp ui/minibar.cpp
ui/newstuff.cpp ui/newstuff.cpp

@ -0,0 +1,175 @@
/***************************************************************************
* Copyright (C) 2006 by Chu Xiaodong <xiaodongchu@gmail.com> *
* *
* 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. *
***************************************************************************/
#include <QPainter>
#include "annotwindow.h"
MouseBox::MouseBox( QWidget * parent)
: QWidget(parent),pointpressed(0,0)//pointpressed(QPoint(0,0))// m_parent(parent)
{
}
void MouseBox::paintEvent(QPaintEvent *e)
{
emit paintevent(e);
}
void MouseBox::mousePressEvent(QMouseEvent *e)
{
pointpressed=e->pos();
//kDebug( )<<"astario: mousebox pressed"<<endl;
emit mousepressevent(e);
}
void MouseBox::mouseMoveEvent(QMouseEvent *e)
{
emit mousemoveevent(e);
}
void MouseBox::mouseReleaseEvent(QMouseEvent *e)
{
emit mousereleaseevent(e);
}
AnnotWindow::AnnotWindow( QWidget * parent, Annotation * annot)
: QWidget(parent,Qt::SubWindow), m_annot( annot )
{
textEdit=new QTextEdit(m_annot->window.text, this);
connect(textEdit,SIGNAL(textChanged()),
this,SLOT(slotsaveWindowText()));
modTime=m_annot->modifyDate.toString(Qt::ISODate);
setPalette( QPalette(m_annot->style.color));
QPalette pl=textEdit->palette();
pl.setColor(QPalette::Base,m_annot->style.color);
textEdit->setPalette(pl);
titleBox=new MouseBox(this);
titleBox->setCursor(Qt::SizeAllCursor);
resizerBox=new MouseBox(this);
resizerBox->setCursor(Qt::SizeFDiagCursor);
connect( titleBox,SIGNAL(mousemoveevent(QMouseEvent*)),
this,SLOT(slotTitleMouseMove(QMouseEvent*)));
connect( resizerBox,SIGNAL(mousemoveevent(QMouseEvent*)),
this,SLOT(slotResizerMouseMove(QMouseEvent*)));
connect( resizerBox,SIGNAL(paintevent(QPaintEvent*)),
this,SLOT(slotResizerPaint(QPaintEvent*)));
btnClose=new MouseBox(this);
connect( btnClose,SIGNAL(mousereleaseevent( QMouseEvent* )),
this,SLOT(slotCloseBtn( QMouseEvent* )));
connect( btnClose,SIGNAL(paintevent( QPaintEvent* )),
this,SLOT(slotPaintCloseBtn( QPaintEvent* )));
btnOption=new MouseBox(this);
connect( btnOption,SIGNAL(mousereleaseevent( QMouseEvent* )),
this,SLOT(slotOptionBtn( QMouseEvent* )));
// connect( btnOption,SIGNAL(paintevent( QPaintEvent* )),
// this,SLOT(slotPaintOptionBtn( QPaintEvent* )));
setGeometry(10,10,300,300 );
}
void AnnotWindow::paintEvent(QPaintEvent *)
{
QPainter annopainter(this);
QRect rc=rect();
QPen pen=QPen(Qt::black);
annopainter.setPen(pen);
annopainter.setBrush(m_annot->style.color);
annopainter.drawRect( rc );
annopainter.translate( rc.topLeft() );
// QFont qft=annopainter.font();
// qft.setPointSize( 10 );
// annopainter.setFont( qft);
annopainter.drawText(rc.right()-150,16,modTime);
annopainter.drawText(2,32,m_annot->author);
pen.setWidth(2);
annopainter.setPen(pen);
annopainter.drawText(2,16,m_annot->window.summary);
//draw options button:
pen.setWidth(1);
annopainter.setPen(pen);
rc=btnOption->geometry(); //(0,0,x,x)
annopainter.drawRect(rc.left(),rc.top(),rc.width()-1,rc.height()-1);
annopainter.drawText( rc.left(),rc.top(),rc.width(),rc.height(),Qt::AlignLeft,"options");
// annopainter.drawLine( 0,10,rc.width(),10);
}
void AnnotWindow::resizeEvent ( QResizeEvent * e )
{ //size:
QSize sz=e->size();
btnClose->setGeometry( sz.width()-16,2,14,14);
btnOption->setGeometry( sz.width()-80,16,75,16);
titleBox->setGeometry(0,0,sz.width(),32);
textEdit->setGeometry(0,32,sz.width(),sz.height()-32-14);
resizerBox->setGeometry(sz.width()-14,sz.height()-14,14,14);
//titlerc.setRect( 0,0,sz.width(),20);
//sizegriprc.setRect(sz.width()-14,sz.height()-14,14,14);
}
void AnnotWindow::slotTitleMouseMove(QMouseEvent* e)
{
if (e->buttons() != Qt::LeftButton)
return;
move(e->pos()-titleBox->pointpressed+pos());
}
void AnnotWindow::slotResizerMouseMove(QMouseEvent* e)
{
if (e->buttons() != Qt::LeftButton)
return;
QSize sz=size();
QPoint dpt=e->pos()-resizerBox->pointpressed;
sz.setHeight(qMax(10,sz.height()+dpt.y()));
sz.setWidth(qMax(20,sz.width()+dpt.x()));
resize(sz);
}
void AnnotWindow::slotResizerPaint(QPaintEvent* )
{
//draw Size griper:
QPainter pnter(resizerBox);
int w=resizerBox->rect().width(),h=resizerBox->rect().height();
for(int i=0;i<5;i++)
{
pnter.drawLine( w-1-i*3,h,w,h-1-i*3);
}
}
void AnnotWindow::slotPaintCloseBtn(QPaintEvent* )
{
//draw close button
QPainter pnter(btnClose);
QRect rc=btnClose->rect();
rc.moveTo( 0,0);
pnter.drawRect(rc.left(),rc.top(),rc.width()-1,rc.height()-1);
pnter.drawLine(rc.topLeft(),rc.bottomRight());
pnter.drawLine(rc.topRight(),rc.bottomLeft());
}
void AnnotWindow::slotCloseBtn( QMouseEvent* e)
{
this->hide();
}
void AnnotWindow::slotOptionBtn( QMouseEvent* e)
{
//TODO: call context menu in pageview
//emit sig...
}
void AnnotWindow::slotsaveWindowText()
{
m_annot->window.text=textEdit->text();
}
#include "annotwindow.moc"

@ -0,0 +1,85 @@
/***************************************************************************
* Copyright (C) 2006 by Chu Xiaodong <xiaodongchu@gmail.com> *
* *
* 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. *
***************************************************************************/
//annotwindow.h
#ifndef _ANNOTWINDOW_H_
#define _ANNOTWINDOW_H_
#include <QtGui/qwidget.h>
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QTextEdit>
#include "core/annotations.h"
//this widget is for the titlebar and size griper
class MouseBox : public QWidget
{
Q_OBJECT
public:
MouseBox( QWidget * parent);
signals:
void paintevent(QPaintEvent *e);
void mousepressevent(QMouseEvent *e);
void mousemoveevent(QMouseEvent *e);
void mousereleaseevent(QMouseEvent *e);
private:
//QWidget * m_parent;
public:
QPoint pointpressed;
protected:
void paintEvent(QPaintEvent *e);
void mousePressEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
};
class AnnotWindow : public QWidget
{
Q_OBJECT
public:
AnnotWindow( QWidget * parent, Annotation * annot);
private:
QFrame *frame;
//QLabel *labelAnnotName;
//QLabel *labelTimeDate;
//QRect rcCloseBtn;
//QRect rcOptionBtn;
//QSizeGrip *resizer;
MouseBox* titleBox;
MouseBox* resizerBox;
MouseBox* btnClose;
MouseBox* btnOption;
QString modTime;
// QRect titlerc;
// QRect sizegriprc;
QTextEdit *textEdit;
public:
Annotation* m_annot;
protected:
void paintEvent(QPaintEvent * e);
void resizeEvent ( QResizeEvent * e );
// void mousePressEvent(QMouseEvent * e);
// void mouseMoveEvent(QMouseEvent * e);
private slots:
void slotTitleMouseMove(QMouseEvent* e);
void slotResizerMouseMove(QMouseEvent* e);
void slotResizerPaint(QPaintEvent* e);
void slotPaintCloseBtn(QPaintEvent* e);
// void slotPaintOptionBtn(QPaintEvent* e);
void slotCloseBtn( QMouseEvent* e);
void slotOptionBtn( QMouseEvent* e);
void slotsaveWindowText();
};
#endif

@ -457,8 +457,10 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const KPDFPage * p
painter.setPen( Qt::black );//( NoPen ); painter.setPen( Qt::black );//( NoPen );
//painter.setBrush( bule); //painter.setBrush( bule);
painter.drawRect( 0, 0, sz.width()-2, sz.height()-2 ); painter.drawRect( 0, 0, sz.width()-2, sz.height()-2 );
painter.drawText(2,sz.height()/2+int(rcf.height()/2),text->inplaceText); //painter.drawText(2,sz.height()/2+int(rcf.height()/2),text->inplaceText);
//kDebug()<<"astario: w,h="<<sz.width()<<", "<<sz.height()<<endl; painter.drawText(0,0,sz.width(),sz.height(),
Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWrapAnywhere,
text->inplaceText);
painter.end(); painter.end();
QImage scaledImage; QImage scaledImage;
scalePixmapOnImage( scaledImage, &pixmap, scalePixmapOnImage( scaledImage, &pixmap,

@ -56,7 +56,7 @@
#include "pageviewutils.h" #include "pageviewutils.h"
#include "pagepainter.h" #include "pagepainter.h"
#include "core/annotations.h" #include "core/annotations.h"
#include "embeddedannotationdialog.h" #include "annotwindow.h" //"embeddedannotationdialog.h"
#include "annotationpropertiesdialog.h" #include "annotationpropertiesdialog.h"
#include "pageviewannotator.h" #include "pageviewannotator.h"
#include "core/document.h" #include "core/document.h"
@ -115,7 +115,7 @@ public:
// annotations // annotations
PageViewAnnotator * annotator; PageViewAnnotator * annotator;
//text annotation dialogs list //text annotation dialogs list
QList<EmbeddedAnnotationDialog *> m_annowindows; QList<AnnotWindow *> m_annowindows;
// other stuff // other stuff
QTimer * delayResizeTimer; QTimer * delayResizeTimer;
bool dirtyLayout; bool dirtyLayout;
@ -215,7 +215,7 @@ PageView::PageView( QWidget *parent, KPDFDocument *document )
PageView::~PageView() PageView::~PageView()
{ {
// delete the local storage structure // delete the local storage structure
foreach(EmbeddedAnnotationDialog* tempwnd, d->m_annowindows) foreach(AnnotWindow* tempwnd, d->m_annowindows)
{ {
if(tempwnd) if(tempwnd)
delete tempwnd; delete tempwnd;
@ -344,8 +344,8 @@ void PageView::setAnnotsWindow(Annotation * annot)
if(!annot) if(!annot)
return; return;
//find the annot window //find the annot window
EmbeddedAnnotationDialog* existWindow=0; AnnotWindow* existWindow=0;
foreach(EmbeddedAnnotationDialog* tempwnd, d->m_annowindows) foreach(AnnotWindow* tempwnd, d->m_annowindows)
{ {
if(tempwnd) if(tempwnd)
{ {
@ -357,7 +357,7 @@ void PageView::setAnnotsWindow(Annotation * annot)
} }
} }
if(annot->window.flags & Annotation::Hidden) /* if(annot->window.flags & Annotation::Hidden)
{ {
if(existWindow) if(existWindow)
{ {
@ -365,14 +365,15 @@ void PageView::setAnnotsWindow(Annotation * annot)
} }
} }
else else
{ {*/
if(existWindow==0) if(existWindow==0)
{ {
existWindow=new EmbeddedAnnotationDialog(this,annot); existWindow=new AnnotWindow(this,annot);
d->m_annowindows<<existWindow; d->m_annowindows<<existWindow;
} }
existWindow->show(); existWindow->show();
} //}
return; return;
} }
@ -1250,10 +1251,10 @@ if (d->document->handleEvent( e ) )
KMenu menu( this ); KMenu menu( this );
QAction *popoutWindow=0, *deleteNote=0, *showProperties=0; QAction *popoutWindow=0, *deleteNote=0, *showProperties=0;
menu.addTitle( i18n("Annotation")); menu.addTitle( i18n("Annotation"));
if(ann->window.flags & Annotation::Hidden) // if(ann->window.flags & Annotation::Hidden)
popoutWindow = menu.addAction( SmallIconSet("comment"), i18n( "&Open Pop-up Note" ) ); popoutWindow = menu.addAction( SmallIconSet("comment"), i18n( "&Open Pop-up Note" ) );
else // else
popoutWindow = menu.addAction( SmallIconSet("comment"), i18n( "&Close Pop-up Note" ) ); // popoutWindow = menu.addAction( SmallIconSet("comment"), i18n( "&Close Pop-up Note" ) );
deleteNote = menu.addAction( SmallIconSet("remove"), i18n( "&Delete" ) ); deleteNote = menu.addAction( SmallIconSet("remove"), i18n( "&Delete" ) );
showProperties = menu.addAction( SmallIconSet("thumbnail"), i18n( "&Properties..." ) ); showProperties = menu.addAction( SmallIconSet("thumbnail"), i18n( "&Properties..." ) );
@ -1264,21 +1265,22 @@ if (d->document->handleEvent( e ) )
{ {
if ( choice == popoutWindow) if ( choice == popoutWindow)
{ {
if(ann->window.flags & Annotation::Hidden) // ann->window.flags ^= Annotation::Hidden;
{
kDebug()<<"astario: select popoutWindow"<<endl;
}
else
{
kDebug()<<"astario: select close annotsWindow"<<endl;
}
ann->window.flags ^= Annotation::Hidden;
this->setAnnotsWindow(ann); this->setAnnotsWindow(ann);
} }
if(choice==deleteNote) if(choice==deleteNote)
{ {
kDebug()<<"astario: select deleteNote"<<endl; kDebug()<<"astario: select deleteNote"<<endl;
//find and close the annotwindow
foreach(AnnotWindow* annwnd, d->m_annowindows)
{
if(ann==annwnd->m_annot)
{
delete annwnd;
break;
}
}
d->document->removePageAnnotation(pageItem->page()->number(),ann); d->document->removePageAnnotation(pageItem->page()->number(),ann);
kDebug()<<"astario: deleted Note"<<endl; kDebug()<<"astario: deleted Note"<<endl;

@ -310,6 +310,7 @@ class PickPointEngine : public AnnotatorEngine
rect.right = qMax(rect.right, rect.left+rcf.width()*pixfactor); rect.right = qMax(rect.right, rect.left+rcf.width()*pixfactor);
rect.bottom = qMax(rect.bottom, rect.top+rcf.height()*pixfactor*xscale/yscale); rect.bottom = qMax(rect.bottom, rect.top+rcf.height()*pixfactor*xscale/yscale);
ta->boundary=this->rect; ta->boundary=this->rect;
ta->window.summary="TextBox";
} }
} }
else if ( typeString == "Text") else if ( typeString == "Text")
@ -317,7 +318,7 @@ class PickPointEngine : public AnnotatorEngine
TextAnnotation * ta = new TextAnnotation(); TextAnnotation * ta = new TextAnnotation();
ann = ta; ann = ta;
ta->textType = TextAnnotation::Linked; ta->textType = TextAnnotation::Linked;
ta->window.text="This is a text annotation"; ta->window.text="";
//ta->window.flags &= ~(Annotation::Hidden); //ta->window.flags &= ~(Annotation::Hidden);
ta->textIcon="comment"; ta->textIcon="comment";
double iconhei=0.03; double iconhei=0.03;
@ -326,6 +327,7 @@ class PickPointEngine : public AnnotatorEngine
rect.right=rect.left+iconhei; rect.right=rect.left+iconhei;
rect.bottom=rect.top+iconhei*xscale/yscale; rect.bottom=rect.top+iconhei*xscale/yscale;
ta->boundary=this->rect; ta->boundary=this->rect;
ta->window.summary="Note";
} }
// create StampAnnotation from path // create StampAnnotation from path
else if ( typeString == "Stamp" ) else if ( typeString == "Stamp" )

Loading…
Cancel
Save