SVN_SILENT made messages (.desktop file)
[kdegames.git] / kbattleship / src / button.h
blob2122643aa52f63fb8e188ab4599be397d94af3ac
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 */
10 #ifndef BUTTON_H
11 #define BUTTON_H
13 #include <QIcon>
14 #include <QFont>
15 #include <QSize>
16 #include <QPointer>
17 #include "welcomescreen.h"
18 #include "animation.h"
20 class ButtonAnimation;
21 class QWidget;
23 class EditorFactory
25 public:
26 virtual ~EditorFactory()
30 virtual QWidget* createEditor(QWidget* parent) = 0;
34 class Button : public QObject, public KGameCanvasPixmap
36 Q_OBJECT
37 enum {
38 BRIGHTNESS_NORMAL = 0,
39 BRIGHTNESS_HOVER = 120,
40 BRIGHTNESS_DOWN = 180
42 QIcon m_icon;
43 QFont m_font;
44 QString m_text;
45 QSize m_size;
46 int m_text_width;
48 bool m_fixed_width;
49 bool m_down;
50 bool m_hover;
51 double m_brightness;
52 QPointer<ButtonAnimation> m_animation;
54 QWidget* m_editor;
56 QPoint textPos() const;
57 void computeSize();
58 void updateEditor();
59 public:
60 Button(WelcomeScreen* parent, const QIcon& icon,
61 const QFont& font, const QString& text);
62 virtual ~Button();
64 virtual void repaint();
66 QSize size() const;
67 QWidget* editor() { return m_editor; }
69 void onMousePress(const QPoint& p);
70 void onMouseRelease(const QPoint& p);
71 void onMouseMove(const QPoint& p);
72 void onMouseLeave();
73 bool onClicked();
75 void setText(const QString& text);
76 void setBrightness(double value);
77 double brightness() const;
79 KGameCanvasPixmap* extractIcon();
80 void setEditor(EditorFactory& factory);
81 void removeEditor();
82 void setWidth(int width);
83 signals:
84 void clicked();
85 void needsUpdate();
88 class ButtonAnimation : public Animation
90 Q_OBJECT
91 public:
92 Button* m_button;
93 int m_brightness;
94 static double m_speed;
95 double m_current;
96 int m_last;
97 public:
98 ButtonAnimation(Button* button, int brightness);
99 ~ButtonAnimation();
100 virtual void start(int t);
101 virtual bool step(int t);
102 virtual void abort();
104 void setBrightness(int value);
107 #endif // BUTTON_H