diff --git a/part.rc b/part.rc --- a/part.rc +++ b/part.rc @@ -1,5 +1,5 @@ - + &File @@ -104,4 +104,14 @@ +Annotations toolbar + + + + + + + + + diff --git a/ui/pageview.cpp b/ui/pageview.cpp --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -729,6 +729,9 @@ connect(d->document, &Okular::Document::canRedoChanged, kredo, &QAction::setEnabled); kundo->setEnabled(false); kredo->setEnabled(false); + + slotToggleAnnotator( true); + d->annotator->setupActions( ac ); } bool PageView::canFitPageWidth() const diff --git a/ui/pageviewannotator.h b/ui/pageviewannotator.h --- a/ui/pageviewannotator.h +++ b/ui/pageviewannotator.h @@ -10,10 +10,13 @@ #ifndef _OKULAR_PAGEVIEWANNOTATOR_H_ #define _OKULAR_PAGEVIEWANNOTATOR_H_ +#include #include #include #include +#include + #include "pageviewutils.h" #include "annotationtools.h" @@ -54,6 +57,8 @@ PageViewAnnotator( PageView * parent, Okular::Document * storage ); ~PageViewAnnotator(); + void setupActions( KActionCollection *ac ); + // called to show/hide the editing toolbar void setEnabled( bool enabled ); @@ -91,7 +96,7 @@ private Q_SLOTS: void slotToolSelected( int toolID ); void slotSaveToolbarOrientation( int side ); - void slotToolDoubleClicked( int toolID ); + void slotPinAnnotationToolToggled( bool enabled ); private: void detachAnnotation(); diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -613,8 +613,10 @@ return QList< Okular::Annotation* >(); // set common attributes - ann->style().setColor( m_annotElement.hasAttribute( QStringLiteral("color") ) ? - m_annotElement.attribute( QStringLiteral("color") ) : m_engineColor ); + //FIXME: What'0s the point of the inner color property? Why not always using m_engineColor +// ann->style().setColor( m_annotElement.hasAttribute( QStringLiteral("color") ) ? +// m_annotElement.attribute( QStringLiteral("color") ) : m_engineColor ); + ann->style().setColor( m_engineColor ); if ( m_annotElement.hasAttribute( QStringLiteral("opacity") ) ) ann->style().setOpacity( m_annotElement.attribute( QStringLiteral("opacity"), QStringLiteral("1.0") ).toDouble() ); @@ -642,7 +644,7 @@ PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage ) : QObject( parent ), m_document( storage ), m_pageView( parent ), m_toolBar( nullptr ), m_engine( nullptr ), m_textToolsEnabled( false ), m_toolsEnabled( false ), - m_continuousMode( false ), m_hidingWasForced( false ), m_lastToolID( -1 ), m_lockedItem( nullptr ) + m_continuousMode( true ), m_hidingWasForced( false ), m_lastToolID( -1 ), m_lockedItem( nullptr ) { reparseConfig(); } @@ -706,8 +708,6 @@ if ( !on ) { // remove toolBar - if ( m_toolBar ) - m_toolBar->hideAndDestroy(); m_toolBar = nullptr; // deactivate the active tool, if any slotToolSelected( -1 ); @@ -721,31 +721,33 @@ // create toolBar if ( !m_toolBar ) { - m_toolBar = new PageViewToolBar( m_pageView, m_pageView->viewport() ); - m_toolBar->setSide( (PageViewToolBar::Side)Okular::Settings::editToolBarPlacement() ); - m_toolBar->setItems( m_items ); - m_toolBar->setToolsEnabled( m_toolsEnabled ); - m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); - connect(m_toolBar, &PageViewToolBar::toolSelected, this, &PageViewAnnotator::slotToolSelected); - connect(m_toolBar, &PageViewToolBar::orientationChanged, this, &PageViewAnnotator::slotSaveToolbarOrientation); - - connect(m_toolBar, &PageViewToolBar::buttonDoubleClicked, this, &PageViewAnnotator::slotToolDoubleClicked); - m_toolBar->setCursor(Qt::ArrowCursor); + m_toolBar = new PageViewToolBar( m_pageView ); +// m_toolBar->setSide( (PageViewToolBar::Side)Okular::Settings::editToolBarPlacement() ); +// m_toolBar->setItems( m_items ); +// m_toolBar->setToolsEnabled( m_toolsEnabled ); +// m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); + connect(m_toolBar, &PageViewToolBar::toolSelected, this, &PageViewAnnotator::slotToolSelected); +// connect(m_toolBar, &PageViewToolBar::orientationChanged, this, &PageViewAnnotator::slotSaveToolbarOrientation); +// + connect(m_toolBar, &PageViewToolBar::pinAnnotationToolToggled, this, &PageViewAnnotator::slotPinAnnotationToolToggled); +// m_toolBar->setCursor(Qt::ArrowCursor); } // show the toolBar - m_toolBar->showAndAnimate(); + //m_toolBar->showAndAnimate(); } void PageViewAnnotator::setTextToolsEnabled( bool enabled ) { + //FIXME: Add code to enable tools m_textToolsEnabled = enabled; if ( m_toolBar ) m_toolBar->setTextToolsEnabled( m_textToolsEnabled ); } void PageViewAnnotator::setToolsEnabled( bool enabled ) { + //FIXME: Add code to enable tools m_toolsEnabled = enabled; if ( m_toolBar ) m_toolBar->setToolsEnabled( m_toolsEnabled ); @@ -763,7 +765,8 @@ bool PageViewAnnotator::active() const { - return m_engine && m_toolBar; + //FIXME: + return m_engine;// && m_toolBar; } bool PageViewAnnotator::annotating() const @@ -875,18 +878,6 @@ return QRect(); } - // We set all tablet events that take place over the annotations toolbar to ignore so that corresponding mouse - // events will be delivered to the toolbar. However, we still allow the annotations code to handle - // TabletMove and TabletRelease events in case the user is drawing an annotation onto the toolbar. - const QPoint toolBarPos = m_toolBar->mapFromGlobal( e->globalPos() ); - const QRect toolBarRect = m_toolBar->rect(); - if ( toolBarRect.contains( toolBarPos ) ) - { - e->ignore(); - if (e->type() == QEvent::TabletPress) - return QRect(); - } - AnnotatorEngine::EventType eventType; AnnotatorEngine::Button button; @@ -910,7 +901,8 @@ bool PageViewAnnotator::routePaints( const QRect & wantedRect ) const { - return m_engine && m_toolBar && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem; + //FIXME: Add check on annotation toolbar avability + return m_engine && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem; } void PageViewAnnotator::routePaint( QPainter * painter, const QRect & paintRect ) @@ -954,7 +946,6 @@ m_lastDrawnRect = QRect(); } - if ( toolID != m_lastToolID ) m_continuousMode = false; // store current tool for later usage m_lastToolID = toolID; @@ -987,6 +978,11 @@ // create the AnnotatorEngine if ( toolSubElement.tagName() == QLatin1String("engine") ) { + if ( toolSubElement.hasAttribute( QStringLiteral("color") ) ) + { + qDebug() << m_toolBar->annotationColor(); + toolSubElement.setAttribute( QStringLiteral("color"), m_toolBar->annotationColor()); + } QString type = toolSubElement.attribute( QStringLiteral("type") ); if ( type == QLatin1String("SmoothLine") ) m_engine = new SmoothPathEngine( toolSubElement ); @@ -1051,14 +1047,14 @@ Okular::Settings::self()->save(); } -void PageViewAnnotator::slotToolDoubleClicked( int /*toolID*/ ) +void PageViewAnnotator::slotPinAnnotationToolToggled( bool enabled ) { - m_continuousMode = true; + m_continuousMode = enabled; } void PageViewAnnotator::detachAnnotation() { - m_toolBar->selectButton( -1 ); + m_toolBar->deselectAllButtons(); } QString PageViewAnnotator::defaultToolName( const QDomElement &toolElement ) @@ -1241,6 +1237,11 @@ return pixmap; } +void PageViewAnnotator::setupActions( KActionCollection * ac ) +{ + m_toolBar->setupActions( ac ); +} + #include "moc_pageviewannotator.cpp" /* kate: replace-tabs on; indent-width 4; */ diff --git a/ui/pageviewutils.h b/ui/pageviewutils.h --- a/ui/pageviewutils.h +++ b/ui/pageviewutils.h @@ -22,6 +22,7 @@ #include "core/area.h" +class KActionCollection; class QAction; class QLabel; class QTimer; @@ -141,83 +142,43 @@ bool isText; }; -class ToolBarButton : public QToolButton -{ - Q_OBJECT - public: - static const int iconSize = 32; - static const int buttonSize = 40; - - ToolBarButton( QWidget * parent, const AnnotationToolItem &item ); - int buttonID() const { return m_id; } - bool isText() const { return m_isText; } - - Q_SIGNALS: - void buttonDoubleClicked( int buttonID ); - - protected: - void mouseDoubleClickEvent( QMouseEvent * event ) override; - - private: - int m_id; - bool m_isText; -}; - /** * @short A widget containing exclusive buttons, that slides in from a side. * * This is a shaped widget that slides in from a side of the 'anchor widget' * it's attached to. It can be dragged and docked on {left,top,right,bottom} * sides and contains toggable exclusive buttons. * When a 'tool' of this 'toolBar' is selected, a signal is emitted. */ -class PageViewToolBar : public QWidget +class PageViewToolBar : public QObject { Q_OBJECT public: - PageViewToolBar( PageView * parent, QWidget * anchorWidget ); + PageViewToolBar( PageView * parent); ~PageViewToolBar(); - // animated widget controls - enum Side { Left = 0, Top = 1, Right = 2, Bottom = 3 }; - - void setItems( const QLinkedList &items ); - void setSide( Side side ); + void setupActions( KActionCollection *ac ); - void showAndAnimate(); - void hideAndDestroy(); - - void selectButton( int id ); + void deselectAllButtons(); void setToolsEnabled( bool on ); void setTextToolsEnabled( bool on ); - - // query properties - + + QString annotationColor(); + Q_SIGNALS: // the tool 'toolID' has been selected void toolSelected( int toolID ); - // orientation has been changed - void orientationChanged( int side ); - // a tool button of this toolbar has been double clicked - void buttonDoubleClicked( int buttonID ); - - protected: - // handle widget events { anchor_resize, paint, animation, drag } - bool eventFilter( QObject * o, QEvent * e ) override; - void paintEvent( QPaintEvent * ) override; - void mousePressEvent( QMouseEvent * e ) override; - void mouseMoveEvent( QMouseEvent * e ) override; - void mouseReleaseEvent( QMouseEvent * e ) override; + // the button to enable continuous mode has been toggled + void pinAnnotationToolToggled( bool enabled ); private: // private variables friend class ToolBarPrivate; class ToolBarPrivate * d; - + private Q_SLOTS: - void slotAnimate(); - void slotButtonClicked(); + void slotSelectAnnotationColor(); }; #endif diff --git a/ui/pageviewutils.cpp b/ui/pageviewutils.cpp --- a/ui/pageviewutils.cpp +++ b/ui/pageviewutils.cpp @@ -15,12 +15,14 @@ // qt/kde includes #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -36,6 +38,7 @@ // local includes #include "formwidgets.h" #include "pageview.h" +#include "toolaction.h" #include "videowidget.h" #include "core/movie.h" #include "core/page.h" @@ -434,515 +437,128 @@ /** PageViewToolBar */ /*********************/ -ToolBarButton::ToolBarButton( QWidget * parent, const AnnotationToolItem &item ) - : QToolButton( parent ), m_id( item.id ), m_isText( item.isText ) -{ - setCheckable( true ); - setAutoRaise( true ); - resize( buttonSize, buttonSize ); - setIconSize( QSize( iconSize, iconSize ) ); - setIcon( QIcon( item.pixmap ) ); - // set shortcut if defined - if ( !item.shortcut.isEmpty() ) - setShortcut( QKeySequence( item.shortcut ) ); - else - KAcceleratorManager::setNoAccel( this ); - - // if accel is set display it along name - QString accelString = shortcut().toString( QKeySequence::NativeText ); - if ( !accelString.isEmpty() ) - setToolTip( QStringLiteral("%1 [%2]").arg( item.text, accelString ) ); - else - setToolTip( item.text ); -} - -void ToolBarButton::mouseDoubleClickEvent( QMouseEvent * /*event*/ ) -{ - emit buttonDoubleClicked( buttonID() ); -} - -/* PageViewToolBar */ - static const int toolBarGridSize = 40; class ToolBarPrivate { public: ToolBarPrivate( PageViewToolBar * qq ) - : q( qq ) + : q( qq ), m_annotationColor( QColor("yellow") ) { } - // rebuild contents and reposition then widget - void buildToolBar(); - void reposition(); - // compute the visible and hidden positions along current side - QPoint getInnerPoint() const; - QPoint getOuterPoint() const; - void selectButton( ToolBarButton * button ); - + QIcon colorizeIcon(QIcon &icon, const QColor &color); + PageViewToolBar * q; - // anchored widget and side - QWidget * anchorWidget; - PageViewToolBar::Side anchorSide; - - // slide in/out stuff - QTimer * animTimer; - QPoint currentPosition; - QPoint endPosition; - bool hiding; - bool visible; - - // background pixmap and buttons - QPixmap backgroundPixmap; - QLinkedList< ToolBarButton * > buttons; + QActionGroup * m_annotationToolsGroup; + QList< QAction * > m_annotations; + QAction * m_colorPicker; + QColor m_annotationColor; }; -PageViewToolBar::PageViewToolBar( PageView * parent, QWidget * anchorWidget ) - : QWidget( parent ), d( new ToolBarPrivate( this ) ) +QIcon ToolBarPrivate::colorizeIcon(QIcon &icon, const QColor &color) { - // initialize values of the private data storage structure - d->anchorWidget = anchorWidget; - d->anchorSide = Left; - d->hiding = false; - d->visible = false; - - // create the animation timer - d->animTimer = new QTimer( this ); - connect( d->animTimer, &QTimer::timeout, this, &PageViewToolBar::slotAnimate ); - - // apply a filter to get notified when anchor changes geometry - d->anchorWidget->installEventFilter( this ); + //FIXME: Use GuiUtils::colorize if possible instead or write a decent version of this method + QPixmap iconPixmap = icon.pixmap(32, 32); + QBitmap mask = iconPixmap.createMaskFromColor(QColor(Qt::transparent), Qt::MaskInColor); + iconPixmap.fill(color); + iconPixmap.setMask(mask); + return QIcon(iconPixmap); +} - setContextMenuPolicy( Qt::ActionsContextMenu ); - addAction( parent->actionCollection()->action( QStringLiteral("options_configure_annotations") ) ); +PageViewToolBar::PageViewToolBar( PageView * parent) + : QObject( parent ), d( new ToolBarPrivate( this ) ) +{ } PageViewToolBar::~PageViewToolBar() { // delete the private data storage structure delete d; } -void PageViewToolBar::setItems( const QLinkedList &items ) -{ - // delete buttons if already present - if ( !d->buttons.isEmpty() ) - { - QLinkedList< ToolBarButton * >::iterator it = d->buttons.begin(), end = d->buttons.end(); - for ( ; it != end; ++it ) - delete *it; - d->buttons.clear(); - } - - // create new buttons for given items - QLinkedList::const_iterator it = items.begin(), end = items.end(); - for ( ; it != end; ++it ) - { - ToolBarButton * button = new ToolBarButton( this, *it ); - connect(button, &ToolBarButton::clicked, this, &PageViewToolBar::slotButtonClicked); - connect(button, &ToolBarButton::buttonDoubleClicked, this, &PageViewToolBar::buttonDoubleClicked); - d->buttons.append( button ); - } - - // rebuild toolbar shape and contents - d->reposition(); -} - -void PageViewToolBar::setSide( Side side ) -{ - d->anchorSide = side; - - d->reposition(); -} - -void PageViewToolBar::showAndAnimate() -{ - // set parameters for sliding in - d->hiding = false; - - show(); - -#ifdef OKULAR_ANIMATE_REVIEW_TOOBAR - // start scrolling in - d->animTimer->start( 20 ); -#else - d->currentPosition = d->endPosition; - - move( d->currentPosition ); - - d->visible = true; -#endif -} - -void PageViewToolBar::hideAndDestroy() -{ - // set parameters for sliding out - d->hiding = true; - d->endPosition = d->getOuterPoint(); - -#ifdef OKULAR_ANIMATE_REVIEW_TOOBAR - // start scrolling out - d->animTimer->start( 20 ); -#else - d->currentPosition = d->endPosition; - - move( d->currentPosition ); - - d->visible = false; - deleteLater(); -#endif -} - -void PageViewToolBar::selectButton( int id ) -{ - ToolBarButton * button = nullptr; - if ( id >= 0 && id < d->buttons.count() ) - button = *(d->buttons.begin() + id); - else - { - QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); - for ( ; !button && it != end; ++it ) - if ( (*it)->isChecked() ) - button = *it; - if ( button ) - button->setChecked( false ); - } - d->selectButton( button ); -} - -bool PageViewToolBar::eventFilter( QObject * obj, QEvent * e ) -{ - // if anchorWidget changed geometry reposition toolbar - if ( obj == d->anchorWidget && e->type() == QEvent::Resize ) - { - d->animTimer->stop(); - if ( d->hiding ) - deleteLater(); - else - d->reposition(); +void PageViewToolBar::setupActions( KActionCollection * ac ) +{ + // Other actions + QAction * annInlineNote = new QAction(QIcon::fromTheme( QStringLiteral("note") ), "Inline note", this); + annInlineNote->setCheckable( true ); + ac->addAction(QStringLiteral("annotation_inline_note"), annInlineNote ); + + QAction * annHighlighter = new QAction(QIcon::fromTheme( QStringLiteral("tool_pen") ), "Highlighter", this); + annHighlighter->setCheckable( true ); + ac->addAction(QStringLiteral("annotation_highlighter"), annHighlighter ); + + QAction * annPolygon = new QAction(QIcon::fromTheme( QStringLiteral("pentagon-shape") ), "Polygon", this); + annPolygon->setCheckable( true ); + QAction * annEllipse = new QAction(QIcon::fromTheme( QStringLiteral("ellipse-shape") ), "Ellipse", this); + annEllipse->setCheckable( true ); + + ToolAction *ta = new ToolAction( this ); + ac->addAction( QStringLiteral("annotation_geometrical_shape"), ta ); + ta->addAction( annEllipse ); + ta->addAction( annPolygon ); + + QSignalMapper * signalMapper = new QSignalMapper(this); + connect(annInlineNote, SIGNAL(triggered()), signalMapper, SLOT(map())); + connect(annHighlighter, SIGNAL(triggered()), signalMapper, SLOT(map())); + connect(annPolygon, SIGNAL(triggered()), signalMapper, SLOT(map())); + connect(annEllipse, SIGNAL(triggered()), signalMapper, SLOT(map())); + signalMapper->setMapping(annInlineNote, 2); + signalMapper->setMapping(annHighlighter, 4); + signalMapper->setMapping(annPolygon, 6); + signalMapper->setMapping(annEllipse, 9); + connect(signalMapper, SIGNAL(mapped(int)), this, SIGNAL(toolSelected(int))); + + d->m_annotationToolsGroup = new QActionGroup(this); + d->m_annotationToolsGroup->addAction(annInlineNote); + d->m_annotationToolsGroup->addAction(annHighlighter); + d->m_annotationToolsGroup->addAction(annPolygon); + d->m_annotationToolsGroup->addAction(annEllipse); + + d->m_annotations = d->m_annotationToolsGroup->actions(); + + QIcon colorPicker = QIcon::fromTheme( QStringLiteral("color-picker") ); + QIcon colorizedColorPicker = d->colorizeIcon(colorPicker, d->m_annotationColor); + d->m_colorPicker = new QAction(colorizedColorPicker, "Pick color", this); + ac->addAction(QStringLiteral("annotation_color"), d->m_colorPicker ); + connect(d->m_colorPicker, SIGNAL(triggered()), this, SLOT(slotSelectAnnotationColor())); + + QAction * pinAnnotationTool = new QAction(QIcon::fromTheme( QStringLiteral("port") ), "Pin annotation", this); + pinAnnotationTool->setCheckable( true ); + pinAnnotationTool->setChecked( true ); + ac->addAction(QStringLiteral("pin_annotation_tool"), pinAnnotationTool ); + connect(pinAnnotationTool, SIGNAL(toggled(bool)), this, SIGNAL(pinAnnotationToolToggled(bool))); +} + +void PageViewToolBar::deselectAllButtons() +{ + foreach( QAction * ann, d->m_annotations ) + { + ann->setChecked( false ); } - - // don't block event - return false; -} - -void PageViewToolBar::paintEvent( QPaintEvent * e ) -{ - // paint the internal pixmap over the widget - QPainter p( this ); - p.drawImage( e->rect().topLeft(), d->backgroundPixmap.toImage(), e->rect() ); -} - -void PageViewToolBar::mousePressEvent( QMouseEvent * e ) -{ - // set 'dragging' cursor - if ( e->button() == Qt::LeftButton ) - setCursor( Qt::SizeAllCursor ); -} - -void PageViewToolBar::mouseMoveEvent( QMouseEvent * e ) -{ - if ( ( QApplication::mouseButtons() & Qt::LeftButton ) != Qt::LeftButton ) - return; - - // compute the nearest side to attach the widget to - QPoint parentPos = mapToParent( e->pos() ); - float nX = (float)parentPos.x() / (float)d->anchorWidget->width(), - nY = (float)parentPos.y() / (float)d->anchorWidget->height(); - if ( nX > 0.3 && nX < 0.7 && nY > 0.3 && nY < 0.7 ) - return; - bool LT = nX < (1.0 - nY); - bool LB = nX < (nY); - Side side = LT ? ( LB ? Left : Top ) : ( LB ? Bottom : Right ); - - // check if side changed - if ( side == d->anchorSide ) - return; - - d->anchorSide = side; - d->reposition(); - emit orientationChanged( (int)side ); -} - -void PageViewToolBar::mouseReleaseEvent( QMouseEvent * e ) -{ - // set normal cursor - if ( e->button() == Qt::LeftButton ) - setCursor( Qt::ArrowCursor ); + emit toolSelected( -1 ); } -void ToolBarPrivate::buildToolBar() -{ - int buttonsNumber = buttons.count(), - parentWidth = anchorWidget->width(), - parentHeight = anchorWidget->height(), - myCols = 1, - myRows = 1; - - // 1. find out columns and rows we're going to use - bool topLeft = anchorSide == PageViewToolBar::Left || anchorSide == PageViewToolBar::Top; - bool vertical = anchorSide == PageViewToolBar::Left || anchorSide == PageViewToolBar::Right; - if ( vertical ) - { - myCols = 1 + (buttonsNumber * toolBarGridSize) / - (parentHeight - toolBarGridSize); - myRows = (int)ceil( (float)buttonsNumber / (float)myCols ); - } - else - { - myRows = 1 + (buttonsNumber * toolBarGridSize) / - (parentWidth - toolBarGridSize); - myCols = (int)ceil( (float)buttonsNumber / (float)myRows ); - } - - // 2. compute widget size (from rows/cols) - int myWidth = myCols * toolBarGridSize, - myHeight = myRows * toolBarGridSize, - xOffset = (toolBarGridSize - ToolBarButton::buttonSize) / 2, - yOffset = (toolBarGridSize - ToolBarButton::buttonSize) / 2; - - if ( vertical ) - { - myHeight += 16; - myWidth += 4; - yOffset += 12; - if ( anchorSide == PageViewToolBar::Right ) - xOffset += 4; - } - else - { - myWidth += 16; - myHeight += 4; - xOffset += 12; - if ( anchorSide == PageViewToolBar::Bottom ) - yOffset += 4; - } - - bool prevUpdates = q->updatesEnabled(); - q->setUpdatesEnabled( false ); - - // 3. resize pixmap, mask and widget - QBitmap mask( myWidth + 1, myHeight + 1 ); - backgroundPixmap = QPixmap( myWidth + 1, myHeight + 1 ); - backgroundPixmap.fill(Qt::transparent); - q->resize( myWidth + 1, myHeight + 1 ); - - // 4. create and set transparency mask // 4. draw background - QPainter maskPainter( &mask); - mask.fill( Qt::white ); - maskPainter.setBrush( Qt::black ); - if ( vertical ) - maskPainter.drawRoundRect( topLeft ? -10 : 0, 0, myWidth + 11, myHeight, 2000 / (myWidth + 10), 2000 / myHeight ); - else - maskPainter.drawRoundRect( 0, topLeft ? -10 : 0, myWidth, myHeight + 11, 2000 / myWidth, 2000 / (myHeight + 10) ); - maskPainter.end(); - q->setMask( mask ); - - // 5. draw background - QPainter bufferPainter( &backgroundPixmap ); - bufferPainter.translate( 0.5, 0.5 ); - QPalette pal = q->palette(); - // 5.1. draw horizontal/vertical gradient - QLinearGradient grad; - switch ( anchorSide ) - { - case PageViewToolBar::Left: - grad = QLinearGradient( 0, 1, myWidth + 1, 1 ); - break; - case PageViewToolBar::Right: - grad = QLinearGradient( myWidth + 1, 1, 0, 1 ); - break; - case PageViewToolBar::Top: - grad = QLinearGradient( 1, 0, 1, myHeight + 1 ); - break; - case PageViewToolBar::Bottom: - grad = QLinearGradient( 1, myHeight + 1, 0, 1 ); - break; - } - grad.setColorAt( 0, pal.color( QPalette::Active, QPalette::Button ) ); - grad.setColorAt( 1, pal.color( QPalette::Active, QPalette::Light ) ); - bufferPainter.setBrush( QBrush( grad ) ); - // 5.2. draw rounded border - bufferPainter.setPen( pal.color( QPalette::Active, QPalette::Dark ).lighter( 140 ) ); - bufferPainter.setRenderHints( QPainter::Antialiasing ); - if ( vertical ) - bufferPainter.drawRoundRect( topLeft ? -10 : 0, 0, myWidth + 10, myHeight, 2000 / (myWidth + 10), 2000 / myHeight ); - else - bufferPainter.drawRoundRect( 0, topLeft ? -10 : 0, myWidth, myHeight + 10, 2000 / myWidth, 2000 / (myHeight + 10) ); - // 5.3. draw handle - bufferPainter.translate( -0.5, -0.5 ); - bufferPainter.setPen( pal.color( QPalette::Active, QPalette::Mid ) ); - if ( vertical ) - { - int dx = anchorSide == PageViewToolBar::Left ? 2 : 4; - bufferPainter.drawLine( dx, 6, dx + myWidth - 8, 6 ); - bufferPainter.drawLine( dx, 9, dx + myWidth - 8, 9 ); - bufferPainter.setPen( pal.color( QPalette::Active, QPalette::Light ) ); - bufferPainter.drawLine( dx + 1, 7, dx + myWidth - 7, 7 ); - bufferPainter.drawLine( dx + 1, 10, dx + myWidth - 7, 10 ); - } - else - { - int dy = anchorSide == PageViewToolBar::Top ? 2 : 4; - bufferPainter.drawLine( 6, dy, 6, dy + myHeight - 8 ); - bufferPainter.drawLine( 9, dy, 9, dy + myHeight - 8 ); - bufferPainter.setPen( pal.color( QPalette::Active, QPalette::Light ) ); - bufferPainter.drawLine( 7, dy + 1, 7, dy + myHeight - 7 ); - bufferPainter.drawLine( 10, dy + 1, 10, dy + myHeight - 7 ); - } - bufferPainter.end(); - - // 6. reposition buttons (in rows/col grid) - int gridX = 0, - gridY = 0; - QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); - for ( ; it != end; ++it ) - { - ToolBarButton * button = *it; - button->move( gridX * toolBarGridSize + xOffset, - gridY * toolBarGridSize + yOffset ); - button->show(); - if ( ++gridX == myCols ) - { - gridX = 0; - gridY++; - } - } - - q->setUpdatesEnabled( prevUpdates ); -} - -void ToolBarPrivate::reposition() -{ - // note: hiding widget here will gives better gfx, but ends drag operation - // rebuild widget and move it to its final place - buildToolBar(); - if ( !visible ) - { - currentPosition = getOuterPoint(); - endPosition = getInnerPoint(); - } - else - { - currentPosition = getInnerPoint(); - endPosition = getOuterPoint(); - } - q->move( currentPosition ); - - // repaint all buttons (to update background) - QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); - for ( ; it != end; ++it ) - (*it)->update(); -} - -QPoint ToolBarPrivate::getInnerPoint() const -{ - // returns the final position of the widget - QPoint newPos; - switch ( anchorSide ) - { - case PageViewToolBar::Left: - newPos = QPoint( 0, ( anchorWidget->height() - q->height() ) / 2 ); - break; - case PageViewToolBar::Top: - newPos = QPoint( ( anchorWidget->width() - q->width() ) / 2, 0 ); - break; - case PageViewToolBar::Right: - newPos = QPoint( anchorWidget->width() - q->width(), ( anchorWidget->height() - q->height() ) / 2 ); - break; - case PageViewToolBar::Bottom: - newPos = QPoint( ( anchorWidget->width() - q->width()) / 2, anchorWidget->height() - q->height() ); - break; - } - return newPos + anchorWidget->pos(); -} - -QPoint ToolBarPrivate::getOuterPoint() const -{ - // returns the point from which the transition starts - QPoint newPos; - switch ( anchorSide ) - { - case PageViewToolBar::Left: - newPos = QPoint( -q->width(), ( anchorWidget->height() - q->height() ) / 2 ); - break; - case PageViewToolBar::Top: - newPos = QPoint( ( anchorWidget->width() - q->width() ) / 2, -q->height() ); - break; - case PageViewToolBar::Right: - newPos = QPoint( anchorWidget->width(), ( anchorWidget->height() - q->height() ) / 2 ); - break; - case PageViewToolBar::Bottom: - newPos = QPoint( ( anchorWidget->width() - q->width() ) / 2, anchorWidget->height() ); - break; - } - return newPos + anchorWidget->pos(); -} - -void PageViewToolBar::slotAnimate() -{ - // move currentPosition towards endPosition - int dX = d->endPosition.x() - d->currentPosition.x(), - dY = d->endPosition.y() - d->currentPosition.y(); - dX = dX / 6 + qMax( -1, qMin( 1, dX) ); - dY = dY / 6 + qMax( -1, qMin( 1, dY) ); - d->currentPosition.setX( d->currentPosition.x() + dX ); - d->currentPosition.setY( d->currentPosition.y() + dY ); - - // move the widget - move( d->currentPosition ); - - // handle arrival to the end - if ( d->currentPosition == d->endPosition ) - { - d->animTimer->stop(); - if ( d->hiding ) - { - d->visible = false; - deleteLater(); - } - else - { - d->visible = true; - } - } -} - -void PageViewToolBar::slotButtonClicked() +void PageViewToolBar::setToolsEnabled( bool on ) { - ToolBarButton * button = qobject_cast( sender() ); - d->selectButton( button ); } -void ToolBarPrivate::selectButton( ToolBarButton * button ) +void PageViewToolBar::setTextToolsEnabled( bool on ) { - if ( button ) - { - // deselect other buttons - QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); - for ( ; it != end; ++it ) - if ( *it != button ) - (*it)->setChecked( false ); - // emit signal (-1 if button has been unselected) - emit q->toolSelected( button->isChecked() ? button->buttonID() : -1 ); - } } -void PageViewToolBar::setToolsEnabled( bool on ) +QString PageViewToolBar::annotationColor() { - QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); - for ( ; it != end; ++it ) - (*it)->setEnabled( on ); + return d->m_annotationColor.name(QColor::HexArgb); } - -void PageViewToolBar::setTextToolsEnabled( bool on ) + +void PageViewToolBar::slotSelectAnnotationColor() { - QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); - for ( ; it != end; ++it ) - if ( (*it)->isText() ) - (*it)->setEnabled( on ); + d->m_annotationColor = QColorDialog::getColor(d->m_annotationColor, nullptr, i18n("Select annotation color"), QColorDialog::ShowAlphaChannel); + + QIcon currentIcon = d->m_colorPicker->icon(); + QIcon colorizedColorPicker = d->colorizeIcon(currentIcon, d->m_annotationColor); + d->m_colorPicker->setIcon(colorizedColorPicker); } - #include "moc_pageviewutils.cpp"