Emit error signal when login fails
[situare] / src / ui / fullscreenbutton.cpp
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Kaj Wallin - kaj.wallin@ixonos.com
6         Pekka Nissinen - pekka.nissinen@ixonos.com
7
8     Situare is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License
10     version 2 as published by the Free Software Foundation.
11
12     Situare is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with Situare; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20     USA.
21 */
22
23 #include <QDebug>
24 #include <QPainter>
25 #include <QTimer>
26
27 #include "math.h"
28
29 #include "fullscreenbutton.h"
30
31 const int ROUNDING_ARC_START_ANGLE = 90;    ///< Start angle of the arc
32 const int ROUNDING_ARC_LENGTH = 90;         ///< Length of the arc (degree)
33 const int ROUNDING_ARC_RADIUS = 5;          ///< Roundness of the rounded edge
34
35 const qreal OPACITY = 0.13;                 ///< Opacity of the background in percents
36
37 FullScreenButton::FullScreenButton(QWidget *parent) :
38     QToolButton(parent)
39 {
40     qDebug() << __PRETTY_FUNCTION__;
41
42     const int HIDING_DELAY_MS = 5000;
43
44     setIcon(QIcon::fromTheme(QLatin1String("general_fullsize")));
45     setFixedSize(sizeHint());
46
47     // Normal background
48     m_normalColor = new QColor(Qt::black);
49     m_normalColor->setAlpha(floor(OPACITY * 255));
50
51     // Selected bakcground
52     m_selectedGradient = new QLinearGradient(0, 0, 0, this->height());
53     m_selectedGradient->setColorAt(0.02, QColor(0, 113, 181));
54     m_selectedGradient->setColorAt(0.25, QColor(24, 142, 214));
55     m_selectedGradient->setColorAt(0.5, QColor(41, 162, 239));
56     m_selectedGradient->setColorAt(0.75, QColor(82, 195, 255));
57     m_selectedGradient->setColorAt(0.98, QColor(115, 215, 255));
58
59     // Item shape path
60     m_backgroundPath.moveTo(this->width(), 0);              // Top right corner
61     m_backgroundPath.lineTo(ROUNDING_ARC_RADIUS, 0);
62     m_backgroundPath.arcTo(0, 0, ROUNDING_ARC_RADIUS * 2, ROUNDING_ARC_RADIUS * 2,
63                            ROUNDING_ARC_START_ANGLE, ROUNDING_ARC_LENGTH);
64     m_backgroundPath.lineTo(0, this->height());             // Bottom left corner
65     m_backgroundPath.lineTo(this->width(), this->height()); // Bottom right corner
66     m_backgroundPath.closeSubpath();                        // Back to the beginning
67
68     // Timer for hiding the button automatically after a delay
69     m_hidingTimer = new QTimer(this);
70     if (m_hidingTimer) {
71         m_hidingTimer->setSingleShot(true);
72         m_hidingTimer->setInterval(HIDING_DELAY_MS);
73
74         connect(m_hidingTimer, SIGNAL(timeout()),
75                 this, SLOT(hide()));
76     }
77 }
78
79 FullScreenButton::~FullScreenButton()
80 {
81     qDebug() << __PRETTY_FUNCTION__;
82
83     delete m_normalColor;
84     delete m_selectedGradient;
85 }
86
87 void FullScreenButton::invoke()
88 {
89     qDebug() << __PRETTY_FUNCTION__;
90
91     if (isHidden())
92         show();
93
94     if (m_hidingTimer)
95         m_hidingTimer->start();
96 }
97
98 void FullScreenButton::paintEvent(QPaintEvent *event)
99 {
100     qDebug() << __PRETTY_FUNCTION__;
101
102     Q_UNUSED(event);
103
104     QPainter painter(this);
105     painter.setRenderHint(QPainter::Antialiasing);
106
107     if(isDown())
108         painter.fillPath(m_backgroundPath, QBrush(*m_selectedGradient));
109     else
110         painter.fillPath(m_backgroundPath, QBrush(*m_normalColor));
111
112     icon().paint(&painter, this->rect());
113 }