File: SvgConfiguration.cpp

package info (click to toggle)
qtop 2.3.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,976 kB
  • sloc: cpp: 40,477; makefile: 7
file content (215 lines) | stat: -rw-r--r-- 6,989 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/******************************************************************************
*
* Copyright (C) 2002 Hugo PEREIRA <mailto: hugo.pereira@free.fr>
*
* This 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.
*
* This software is distributed in the hope that it will be useful, but WITHOUT
* Any WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program.  If not, see <http://www.gnu.org/licenses/>.
*
*******************************************************************************/

#include "SvgConfiguration.h"

#include "CustomDialog.h"
#include "Debug.h"
#include "GridLayout.h"
#include "OptionListBox.h"
#include "OptionCheckBox.h"
#include "OptionComboBox.h"
#include "TransparencyConfiguration.h"
#include "XmlOptions.h"

#include <QGroupBox>
#include <QButtonGroup>
#include <QLabel>
#include <QStackedWidget>

namespace Svg
{
    //! use to select background style
    class StyleOptionWidget: public CustomComboBox, public OptionWidget
    {

        Q_OBJECT

        public:

        //! constructor
        explicit StyleOptionWidget( QWidget* parent ):
            CustomComboBox( parent ),
            OptionWidget( "DUMMY_OPTION", this )
        {

            setEditable( false );

            addItem( tr( "Flat" ) );
            addItem( tr( "Decorated" ) );

            #if defined(Q_OS_LINUX)
            addItem( tr( "System (KDE only)" ) );
            #endif

            setCurrentIndex(0);

        }

        //! destructor
        virtual ~StyleOptionWidget()
        {}

        //! read
        virtual void read( const Options& options )
        {
            if( options.get<bool>( "USE_SVG" ) )
            {

                #if defined(Q_OS_LINUX)
                if( options.get<bool>( "SVG_USE_PLASMA_INTERFACE" ) ) setCurrentIndex(2);
                else
                #endif
                { setCurrentIndex(1); }

            } else setCurrentIndex(0);

            if( !_connected() )
            {
                connect( this, SIGNAL(currentIndexChanged(int)), SIGNAL(modified()) );
                _setConnected();
            }

        }

        //! write
        virtual void write( Options& options ) const
        {
            options.set<bool>( "USE_SVG", currentIndex() != 0 );
            #if defined(Q_OS_LINUX)
            options.set<bool>( "SVG_USE_PLASMA_INTERFACE", currentIndex() == 2 );
            #endif
        }

        Q_SIGNALS:

        //! modified
        void modified();

    };

}

// need to be included after definition of StyleOptionWidget
#include "SvgConfiguration.moc"

namespace Svg
{

    //______________________________________________________________________
    SvgConfiguration::SvgConfiguration( QWidget* parent ):
        QWidget( parent ),
        OptionWidgetList( this ),
        Counter( "Svg::SvgConfiguration" )
    {

        Debug::Throw( "SvgConfiguration::SvgConfiguration.\n" );

        QVBoxLayout* vLayout = new QVBoxLayout;
        vLayout->setMargin(0);
        setLayout( vLayout );

        QHBoxLayout* hLayout = new QHBoxLayout;
        hLayout->setMargin( 2 );
        vLayout->addLayout( hLayout );

        QLabel* label;
        hLayout->addWidget( label = new QLabel( tr( "Background style:" ), this ) );

        StyleOptionWidget* styleWidget;
        hLayout->addWidget( styleWidget = new StyleOptionWidget( this ) );
        addOptionWidget( styleWidget );
        label->setBuddy( styleWidget );

        hLayout->addStretch(1);

        // stacked widget
        QStackedWidget* stackedWidget;
        vLayout->addWidget( stackedWidget = new QStackedWidget( this ) );

        // flat background configuration
        QWidget* box;
        stackedWidget->addWidget( box = new QGroupBox( tr( "Flat Background Settings" ) ) );
        box->setLayout( vLayout = new QVBoxLayout );

        Transparency::TransparencyConfiguration* transparencyConfiguration;
        vLayout->addWidget( transparencyConfiguration = new Transparency::TransparencyConfiguration( box, Transparency::TransparencyConfiguration::Background ));
        transparencyConfiguration->layout()->setMargin(0);
        addOptionWidget( transparencyConfiguration );
        vLayout->addStretch(1);

        // svg
        stackedWidget->addWidget( box = new QGroupBox( tr( "Decorated Background Settings" ) ) );
        box->setLayout( vLayout = new QVBoxLayout );

        // SVG file
        vLayout->addWidget( label = new QLabel( tr( "Svg files:" ), box ) );

        OptionListBox *listbox = new OptionListBox( box, "SVG_BACKGROUND" );
        listbox->setBrowsable( true );
        listbox->setToolTip( tr( "Pathname to load background svg" ) );
        vLayout->addWidget( listbox );
        addOptionWidget( listbox );
        label->setBuddy( listbox );

        // plasma interface
        #if defined(Q_OS_LINUX)
        stackedWidget->addWidget( box = new QGroupBox( tr( "System Background Settings" ) ) );
        box->setLayout( vLayout = new QVBoxLayout );

        hLayout = new QHBoxLayout;
        hLayout->setMargin(0);
        vLayout->addLayout( hLayout );

        GridLayout* gridLayout = new GridLayout;
        gridLayout->setSpacing(5);
        gridLayout->setMargin(0);
        gridLayout->setMaxCount(2);
        gridLayout->setColumnAlignment( 0, Qt::AlignVCenter|Qt::AlignRight );
        hLayout->addLayout( gridLayout );
        hLayout->addStretch( 1 );

        gridLayout->addWidget( label = new QLabel( tr( "Image path:" ), box ) );

        OptionComboBox* plasmaImagePath;
        gridLayout->addWidget( plasmaImagePath = new OptionComboBox( box, "SVG_PLASMA_IMAGE_PATH" ) );
        plasmaImagePath->setUseValue( false );
        plasmaImagePath->addItems( QStringList()
            << "dialogs/background"
            << "widgets/background"
            << "widgets/translucentbackground" );
        plasmaImagePath->setToolTip( tr( "Relative path of the svg file used for the background" ) );
        addOptionWidget( plasmaImagePath );
        label->setBuddy( plasmaImagePath );

        gridLayout->addWidget( label = new QLabel( tr( "Draw overlay" ), box ) );
        OptionCheckBox* checkbox;
        gridLayout->addWidget( checkbox = new OptionCheckBox( QString(), box, "SVG_DRAW_OVERLAY" ) );
        checkbox->setToolTip( tr( "If checked, overlay pictures, if any, found in the SVG file, are drawn on top of the background" ) );
        addOptionWidget( checkbox );
        label->setBuddy( checkbox );

        vLayout->addStretch(1);
        #endif

        connect( styleWidget, SIGNAL(currentIndexChanged(int)), stackedWidget, SLOT(setCurrentIndex(int)));

    }

}