pageviewutils.h 5.35 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it>             *
3 4 5 6 7 8 9
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

10 11
#ifndef _PAGEVIEW_UTILS_H_
#define _PAGEVIEW_UTILS_H_
12 13 14 15

#include <qwidget.h>
#include <qpixmap.h>
#include <qrect.h>
16
#include <qhash.h>
17
#include <qtoolbutton.h>
18

Albert Astals Cid's avatar
Albert Astals Cid committed
19 20
#include <KIcon>

21
class QAction;
22
class QLabel;
23
class QTimer;
24
class FormWidgetIface;
25 26 27 28

namespace Okular {
class Page;
}
29

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

42
        const Okular::Page * page() const;
43 44 45 46 47
        int pageNumber() const;
        const QRect& geometry() const;
        int width() const;
        int height() const;
        double zoomFactor() const;
48
        bool isVisible() const;
49
        QHash<QString, FormWidgetIface*>& formWidgets();
50

51 52 53
        void setGeometry( int x, int y, int width, int height );
        void setWHZ( int w, int h, double zoom );
        void moveTo( int x, int y );
54
        void setVisible( bool visible );
55
        void invalidate();
56
        bool setFormWidgetsVisible( bool visible );
57 58

    private:
59
        const Okular::Page * m_page;
60 61
        double m_zoomFactor;
        QRect m_geometry;
62
        bool m_visible;
63
        bool m_formsVisible;
64
        QHash<QString, FormWidgetIface*> m_formWidgets;
65 66
};

67 68 69

/**
 * @short A widget that displays messages in the top-left corner.
70 71 72 73
 *
 * 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.
74 75 76 77 78 79
 */
class PageViewMessage : public QWidget
{
    public:
        PageViewMessage( QWidget * parent );

80
        enum Icon { None, Info, Warning, Error, Find, Annotation };
81
        void display( const QString & message, Icon icon = Info, int durationMs = 4000 );
82 83 84

    protected:
        void paintEvent( QPaintEvent * e );
85
        void mousePressEvent( QMouseEvent * e );
86 87 88 89 90 91

    private:
        QPixmap m_pixmap;
        QTimer * m_timer;
};

92

93 94 95 96 97 98 99 100 101 102 103
/**
 * @short A widget that displays messages in the top part of the page view.
 *
 * ...
 */
class PageViewTopMessage : public QWidget
{
    Q_OBJECT
    public:
        PageViewTopMessage( QWidget * parent );

104
        void setup( const QString & message, const KIcon& icon = KIcon() );
105
        void setIconSize( int size );
106
        void setActionButton( QAction * action );
107 108 109 110 111 112

    signals:
        void action();

    private:
        QLabel * m_label;
113
        QLabel * m_icon;
114
        QToolButton * m_button;
115 116 117
};


118
struct AnnotationToolItem
119
{
120
    AnnotationToolItem()
121 122 123 124
        : id( -1 ), isText( false )
    {
    }

125 126 127
    int id;
    QString text;
    QString pixmap;
128
    QString shortcut;
129
    bool isText;
130 131
};

132 133 134 135 136 137 138
class ToolBarButton : public QToolButton
{
    Q_OBJECT
    public:
        static const int iconSize = 32;
        static const int buttonSize = 40;

139
        ToolBarButton( QWidget * parent, const AnnotationToolItem &item );
140
        int buttonID() const { return m_id; }
Pino Toscano's avatar
Pino Toscano committed
141
        bool isText() const { return m_isText; }
142 143 144

    private:
        int m_id;
Pino Toscano's avatar
Pino Toscano committed
145
        bool m_isText;
146 147
};

148 149 150 151 152 153 154 155
/**
 * @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.
 */
156 157 158 159 160 161 162 163 164
class PageViewToolBar : public QWidget
{
    Q_OBJECT
    public:
        PageViewToolBar( QWidget * parent, QWidget * anchorWidget );
        ~PageViewToolBar();

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

166
        void setItems( const QLinkedList<AnnotationToolItem> &items );
167 168 169
        void setSide( Side side );

        void showAndAnimate();
170 171
        void hideAndDestroy();

172 173
        void selectButton( int id );

Pino Toscano's avatar
Pino Toscano committed
174 175 176
        void setToolsEnabled( bool on );
        void setTextToolsEnabled( bool on );

177 178
        // query properties

179 180 181
    signals:
        // the tool 'toolID' has been selected
        void toolSelected( int toolID );
182 183
        // orientation has been changed
        void orientationChanged( int side );
184 185 186 187 188 189 190 191 192 193 194

    protected:
        // handle widget events { anchor_resize, paint, animation, drag }
        bool eventFilter( QObject * o, QEvent * e );
        void paintEvent( QPaintEvent * );
        void mousePressEvent( QMouseEvent * e );
        void mouseMoveEvent( QMouseEvent * e );
        void mouseReleaseEvent( QMouseEvent * e );

    private:
        // private variables
195
        friend class ToolBarPrivate;
196 197 198 199
        class ToolBarPrivate * d;

    private slots:
        void slotAnimate();
200
        void slotButtonClicked();
201 202
};

203
#endif