klineal.h 3.65 KB
Newer Older
Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
1 2 3 4
/***************************************************************************
                          klineal.h  -  description
                             -------------------
    begin                : Fri Oct 13 2000
5 6
    Copyright            : (C) 2000 - 2008 by Till Krech <till@snafu.de>
                           (C) 2009        by Mathias Soeken <msoeken@tzi.de>
Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KLINEAL_H
#define KLINEAL_H

Urs Wolfer's avatar
Urs Wolfer committed
21
#include <QWidget>
Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
22

Christoph Feck's avatar
Christoph Feck committed
23 24 25
class QAction;
class QIcon;
class QMenu;
26
class QToolButton;
27 28

class KActionCollection;
29
class KRulerSystemTray;
Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
30

31
class KLineal : public QWidget {
32
  Q_OBJECT
Mathias Soeken's avatar
Mathias Soeken committed
33

34
public:
Mathias Soeken's avatar
Mathias Soeken committed
35
  KLineal( QWidget *parent = 0 );
Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
36
  ~KLineal();
Mathias Soeken's avatar
Mathias Soeken committed
37 38 39

  void move( int x, int y );
  void move( const QPoint &p );
Laurent Montel's avatar
Laurent Montel committed
40 41 42
  QPoint pos() const;
  int x() const;
  int y() const;
Mathias Soeken's avatar
Mathias Soeken committed
43

Mathias Soeken's avatar
Mathias Soeken committed
44
protected:
Mathias Soeken's avatar
Mathias Soeken committed
45
  void keyPressEvent( QKeyEvent *e );
Aurélien Gâteau's avatar
Aurélien Gâteau committed
46
  void leaveEvent( QEvent *e );
Mathias Soeken's avatar
Mathias Soeken committed
47 48 49
  void mousePressEvent( QMouseEvent *e );
  void mouseReleaseEvent( QMouseEvent *e );
  void mouseMoveEvent( QMouseEvent *e );
50
  void wheelEvent( QWheelEvent *e );
Mathias Soeken's avatar
Mathias Soeken committed
51
  void paintEvent( QPaintEvent *e );
52

Mathias Soeken's avatar
Mathias Soeken committed
53
  void createSystemTray();
54

Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
55
private:
Aurélien Gâteau's avatar
Aurélien Gâteau committed
56
  void createCrossCursor();
Christoph Feck's avatar
Christoph Feck committed
57
  QAction* addAction( QMenu *menu, const QIcon& icon, const QString& text,
58 59
                      const QObject* receiver, const char* member,
                      const QKeySequence &shortcut, const QString& name );
Mathias Soeken's avatar
Mathias Soeken committed
60 61
  void drawScale( QPainter &painter );
  void drawBackground( QPainter &painter );
62 63
  void drawScaleText( QPainter &painter, int x, const QString &text );
  void drawScaleTick( QPainter &painter, int x, int length );
64
  void drawResizeHandle( QPainter &painter, Qt::Edge edge );
Aurélien Gâteau's avatar
Aurélien Gâteau committed
65 66
  void drawIndicatorOverlay( QPainter &painter, int xy );
  void drawIndicatorText( QPainter &painter, int xy );
67 68
  void updateScaleDirectionMenuItem();

69
  QRect beginRect() const;
Aurélien Gâteau's avatar
Aurélien Gâteau committed
70
  QRect midRect() const;
71 72 73 74 75
  QRect endRect() const;
  Qt::CursorShape resizeCursor() const;
  bool nativeMove() const;
  void startNativeMove( QMouseEvent *e );
  void stopNativeMove( QMouseEvent *e );
Aurélien Gâteau's avatar
Aurélien Gâteau committed
76
  QString indicatorText() const;
77 78 79 80 81 82 83

  enum RulerState {
    StateNone,
    StateMove,
    StateBegin,
    StateEnd
  };
Aurélien Gâteau's avatar
Aurélien Gâteau committed
84
  QCursor mCrossCursor;
85
  RulerState mRulerState;
Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
86 87
  QPoint mLastClickPos;
  QPoint mDragOffset;
88
  bool mHorizontal;
Christoph Feck's avatar
Christoph Feck committed
89
  QMenu *mMenu;
Mathias Soeken's avatar
Mathias Soeken committed
90
  QAction *mCloseAction;
91
  QAction *mScaleDirectionAction;
92 93
  QAction *mCenterOriginAction;
  QAction *mOffsetAction;
94 95
  QColor mColor;
  QFont mScaleFont;
96
  bool mAlwaysOnTopLayer;
97 98
  bool mClicked;
  bool mLeftToRight;
99
  int mOffset;
100
  bool mRelativeScale;
101
  KActionCollection *mActionCollection;
102
  int mOpacity;
Mathias Soeken's avatar
Mathias Soeken committed
103
  KRulerSystemTray *mTrayIcon;
Mathias Soeken's avatar
Mathias Soeken committed
104

105 106
  void setHorizontal( bool horizontal );

Aurélien Gâteau's avatar
Aurélien Gâteau committed
107
  bool isResizing() const;
Aurélien Gâteau's avatar
Aurélien Gâteau committed
108
  int length() const;
Aurélien Gâteau's avatar
Aurélien Gâteau committed
109 110
  QPoint localCursorPos() const;

Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
111
public slots:
112
  void rotate();
Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
113
  void showMenu();
114
  void switchDirection();
115 116
  void centerOrigin();
  void slotOffset();
117
  void slotOpacity( int value );
118
  void slotKeyBindings();
119
  void slotPreferences();
120
  void switchRelativeScale( bool checked );
121
  void saveSettings();
122
  void slotClose();
Laurent Montel's avatar
Laurent Montel committed
123
  void slotQuit();
Mathias Soeken's avatar
Mathias Soeken committed
124
  void loadConfig();
Carsten Pfeiffer's avatar
Carsten Pfeiffer committed
125 126
};
#endif