1
2 /*
3 Copyright (c) 2003-2007 Clarence Dang <dang@kde.org>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 1. Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #define DEBUG_KP_TOOL_WIDGET_OPAQUE_OR_TRANSPARENT 0
29
30
31 #include "widgets/toolbars/options/kpToolWidgetOpaqueOrTransparent.h"
32
33 #include "kpLogCategories.h"
34 #include <KLocalizedString>
35
36
37 //---------------------------------------------------------------------
38
kpToolWidgetOpaqueOrTransparent(QWidget * parent,const QString & name)39 kpToolWidgetOpaqueOrTransparent::kpToolWidgetOpaqueOrTransparent (QWidget *parent, const QString &name)
40 : kpToolWidgetBase (parent, name)
41 {
42 addOption (QStringLiteral(":/icons/option_opaque"), i18n ("Opaque")/*tooltip*/);
43 startNewOptionRow ();
44 addOption (QStringLiteral(":/icons/option_transparent"), i18n ("Transparent")/*tooltip*/);
45
46 finishConstruction (0, 0);
47 }
48
49 //---------------------------------------------------------------------
50
51 kpToolWidgetOpaqueOrTransparent::~kpToolWidgetOpaqueOrTransparent () = default;
52
53 //---------------------------------------------------------------------
54
55
56 // public
isOpaque() const57 bool kpToolWidgetOpaqueOrTransparent::isOpaque () const
58 {
59 return (selected () == 0);
60 }
61
62 // public
isTransparent() const63 bool kpToolWidgetOpaqueOrTransparent::isTransparent () const
64 {
65 return (!isOpaque ());
66 }
67
68 // public
setOpaque(bool yes)69 void kpToolWidgetOpaqueOrTransparent::setOpaque (bool yes)
70 {
71 #if DEBUG_KP_TOOL_WIDGET_OPAQUE_OR_TRANSPARENT && 1
72 qCDebug(kpLogWidgets) << "kpToolWidgetOpaqueOrTransparent::setOpaque(" << yes << ")";
73 #endif
74 setSelected (yes ? 0 : 1, 0, false/*don't save*/);
75 }
76
77 // public
setTransparent(bool yes)78 void kpToolWidgetOpaqueOrTransparent::setTransparent (bool yes)
79 {
80 #if DEBUG_KP_TOOL_WIDGET_OPAQUE_OR_TRANSPARENT && 1
81 qCDebug(kpLogWidgets) << "kpToolWidgetOpaqueOrTransparent::setTransparent(" << yes << ")";
82 #endif
83 setSelected (yes ? 1 : 0, 0, false/*don't save*/);
84 }
85
86
87 // protected slot virtual [base kpToolWidgetBase]
setSelected(int row,int col,bool saveAsDefault)88 bool kpToolWidgetOpaqueOrTransparent::setSelected (int row, int col, bool saveAsDefault)
89 {
90 #if DEBUG_KP_TOOL_WIDGET_OPAQUE_OR_TRANSPARENT && 1
91 qCDebug(kpLogWidgets) << "kpToolWidgetOpaqueOrTransparent::setSelected("
92 << row << "," << col << ")";
93 #endif
94 const bool ret = kpToolWidgetBase::setSelected (row, col, saveAsDefault);
95 if (ret) {
96 emit isOpaqueChanged (isOpaque ());
97 }
98 return ret;
99 }
100
101
102