1 | /* |
2 | This file is part of the KDE project. |
3 | |
4 | Copyright (c) 2011 Lionel Chauvin <megabigbug@yahoo.fr> |
5 | Copyright (c) 2011,2012 Cédric Bellegarde <gnumdk@gmail.com> |
6 | |
7 | Permission is hereby granted, free of charge, to any person obtaining a |
8 | copy of this software and associated documentation files (the "Software"), |
9 | to deal in the Software without restriction, including without limitation |
10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
11 | and/or sell copies of the Software, and to permit persons to whom the |
12 | Software is furnished to do so, subject to the following conditions: |
13 | |
14 | The above copyright notice and this permission notice shall be included in |
15 | all copies or substantial portions of the Software. |
16 | |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | DEALINGS IN THE SOFTWARE. |
24 | */ |
25 | |
26 | #include "menubutton.h" |
27 | |
28 | #include <QAction> |
29 | #include <QMenu> |
30 | #include <QGraphicsDropShadowEffect> |
31 | |
32 | #include <Plasma/Theme> |
33 | |
34 | MenuButton::(QGraphicsWidget *parent): |
35 | Plasma::ToolButton(parent), |
36 | m_enterEvent(false), |
37 | m_menu(0) |
38 | { |
39 | QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(); |
40 | shadow->setBlurRadius(5); |
41 | shadow->setOffset(QPointF(1, 1)); |
42 | shadow->setColor(Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor)); |
43 | setGraphicsEffect(shadow); |
44 | } |
45 | |
46 | void MenuButton::(bool hovered) |
47 | { |
48 | if (hovered) { |
49 | hoverEnterEvent(0); |
50 | } else { |
51 | hoverLeaveEvent(0); |
52 | } |
53 | } |
54 | |
55 | QSizeF MenuButton::(Qt::SizeHint which, const QSizeF& constraint) const |
56 | { |
57 | QSizeF sh = Plasma::ToolButton::sizeHint(which, constraint); |
58 | if (which == Qt::MinimumSize || which == Qt::PreferredSize) { |
59 | sh.setHeight(nativeWidget()->fontMetrics().height() + bottomMargin()); |
60 | } |
61 | return sh; |
62 | } |
63 | |
64 | qreal MenuButton::() const |
65 | { |
66 | qreal left, right, top, bottom; |
67 | getContentsMargins(&left, &right, &top, &bottom); |
68 | return bottom; |
69 | } |
70 | |
71 | void MenuButton::(QGraphicsSceneHoverEvent *e) |
72 | { |
73 | m_enterEvent = true; |
74 | Plasma::ToolButton::hoverEnterEvent(e); |
75 | } |
76 | |
77 | void MenuButton::(QGraphicsSceneHoverEvent *e) |
78 | { |
79 | if (m_enterEvent) { |
80 | m_enterEvent = false; |
81 | Plasma::ToolButton::hoverLeaveEvent(e); |
82 | } |
83 | } |
84 | |
85 | #include "menubutton.moc" |