pageviewutils.h 6.88 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it>             *
3 4 5
 *   Copyright (C) 2017    Klarälvdalens Datakonsult AB, a KDAB Group      *
 *                         company, info@kdab.com. Work sponsored by the   *
 *                         LiMux project of the city of Munich             *
6 7 8 9 10 11 12
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

13 14
#ifndef _PAGEVIEW_UTILS_H_
#define _PAGEVIEW_UTILS_H_
15 16 17 18

#include <qwidget.h>
#include <qpixmap.h>
#include <qrect.h>
19
#include <qhash.h>
20
#include <qtoolbutton.h>
21

22

23 24
#include "core/area.h"

25
class QTimer;
26
class FormWidgetIface;
27
class PageView;
28
class VideoWidget;
29 30

namespace Okular {
31
class Movie;
32 33
class Page;
}
34

35
/**
36
 * @short PageViewItem represents graphically a page into the PageView.
37 38 39 40
 *
 * It has methods for settings Item's geometry and other visual properties such
 * as the individual zoom factor.
 */
41 42 43
class PageViewItem
{
    public:
44
        PageViewItem( const Okular::Page * page );
45
        ~PageViewItem();
46

47 48 49
        PageViewItem(const PageViewItem &) = delete;
        PageViewItem &operator=(const PageViewItem &) = delete;

50
        const Okular::Page * page() const;
51 52
        int pageNumber() const;
        double zoomFactor() const;
53
        bool isVisible() const;
54
        QSet<FormWidgetIface*>& formWidgets();
55
        QHash< Okular::Movie *, VideoWidget * >& videoWidgets();
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        /* The page is cropped as follows: */
        const Okular::NormalizedRect & crop() const;

        /* Real geometry into which the cropped page is rendered: */
        const QRect& croppedGeometry() const;
        int croppedWidth() const;
        int croppedHeight() const;

        /* "Uncropped" geometry:
         * If the whole page was rendered into the uncropped geometry then the
         * cropped page would be rendered into the real geometry.
         * (Hence, uncropped always contains cropped, and they are equal only if
         * the page is uncropped.) This is just for convenience in calculations.
         */
        const QRect& uncroppedGeometry() const;
        int uncroppedWidth() const;
        int uncroppedHeight() const;

        /* Convert absolute geometry coordinates to normalized [0,1] page coordinates: */
        double absToPageX(double absX) const;
        double absToPageY(double absY) const;

        void setWHZC( int w, int h, double zoom, const Okular::NormalizedRect & c );
80
        void moveTo( int x, int y );
81
        void setVisible( bool visible );
82
        void invalidate();
83
        bool setFormWidgetsVisible( bool visible );
84
        void reloadFormWidgetsState();
85 86

    private:
87
        const Okular::Page * m_page;
88
        double m_zoomFactor;
89
        bool m_visible;
90
        bool m_formsVisible;
91 92 93
        QRect m_croppedGeometry;
        QRect m_uncroppedGeometry;
        Okular::NormalizedRect m_crop;
94
        QSet<FormWidgetIface*> m_formWidgets;
95
        QHash< Okular::Movie *, VideoWidget * > m_videoWidgets;
96 97
};

98 99 100

/**
 * @short A widget that displays messages in the top-left corner.
101 102 103 104
 *
 * This is a widget with thin border and rounded corners that displays a given
 * text along as an icon. It's meant to be used for displaying messages to the
 * user by placing this above other widgets.
105 106 107
 */
class PageViewMessage : public QWidget
{
108 109
    Q_OBJECT

110
    public:
Yuri Chornoivan's avatar
Yuri Chornoivan committed
111
        explicit PageViewMessage( QWidget * parent );
112

113
        enum Icon { None, Info, Warning, Error, Find, Annotation };
114
        void display( const QString & message, const QString & details = QString(), Icon icon = Info, int durationMs = 4000 );
115 116

    protected:
117 118 119
        bool eventFilter(QObject * obj, QEvent * event ) override;
        void paintEvent( QPaintEvent * e ) override;
        void mousePressEvent( QMouseEvent * e ) override;
120 121

    private:
122 123
        QRect computeTextRect( const QString & message, int extra_width ) const;
        void computeSizeAndResize();
124
        QString m_message;
125
        QString m_details;
126
        QPixmap m_symbol;
127
        QTimer * m_timer;
128
        int m_lineSpacing;
129 130
};

131
struct AnnotationToolItem
132
{
133
    AnnotationToolItem()
134 135 136 137
        : id( -1 ), isText( false )
    {
    }

138 139
    int id;
    QString text;
140
    QPixmap pixmap;
141
    QString shortcut;
142
    bool isText;
143 144
};

145 146 147 148 149 150 151
class ToolBarButton : public QToolButton
{
    Q_OBJECT
    public:
        static const int iconSize = 32;
        static const int buttonSize = 40;

152
        ToolBarButton( QWidget * parent, const AnnotationToolItem &item );
153
        int buttonID() const { return m_id; }
Pino Toscano's avatar
Pino Toscano committed
154
        bool isText() const { return m_isText; }
155

156
    Q_SIGNALS:
157 158 159
        void buttonDoubleClicked( int buttonID );

    protected:
160
        void mouseDoubleClickEvent( QMouseEvent * event ) override;
161

162 163
    private:
        int m_id;
Pino Toscano's avatar
Pino Toscano committed
164
        bool m_isText;
165 166
};

167 168 169 170 171 172 173 174
/**
 * @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.
 */
175 176 177 178
class PageViewToolBar : public QWidget
{
    Q_OBJECT
    public:
179
        PageViewToolBar( PageView * parent, QWidget * anchorWidget );
180 181 182 183
        ~PageViewToolBar();

        // animated widget controls
        enum Side { Left = 0, Top = 1, Right = 2, Bottom = 3 };
184

185
        void setItems( const QLinkedList<AnnotationToolItem> &items );
186 187 188
        void setSide( Side side );

        void showAndAnimate();
189 190
        void hideAndDestroy();

191 192
        void selectButton( int id );

Pino Toscano's avatar
Pino Toscano committed
193 194 195
        void setToolsEnabled( bool on );
        void setTextToolsEnabled( bool on );

196 197
        // query properties

198
    Q_SIGNALS:
199 200
        // the tool 'toolID' has been selected
        void toolSelected( int toolID );
201 202
        // orientation has been changed
        void orientationChanged( int side );
203 204
        // a tool button of this toolbar has been double clicked
        void buttonDoubleClicked( int buttonID );
205 206 207

    protected:
        // handle widget events { anchor_resize, paint, animation, drag }
208 209 210 211 212
        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;
213 214 215

    private:
        // private variables
216
        friend class ToolBarPrivate;
217 218
        class ToolBarPrivate * d;

219
    private Q_SLOTS:
220
        void slotAnimate();
221
        void slotButtonClicked();
222 223
};

224
#endif