~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/clients/oxygen/config/oxygenexceptiondialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//////////////////////////////////////////////////////////////////////////////
 
2
// oxygenexceptiondialog.cpp
 
3
// -------------------
 
4
//
 
5
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
 
6
//
 
7
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
8
// of this software and associated documentation files (the "Software"), to
 
9
// deal in the Software without restriction, including without limitation the
 
10
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 
11
// sell copies of the Software, and to permit persons to whom the Software is
 
12
// 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 THE
 
20
// 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 DEALINGS
 
23
// IN THE SOFTWARE.
 
24
//////////////////////////////////////////////////////////////////////////////
 
25
 
 
26
#include "oxygenexceptiondialog.h"
 
27
#include "oxygenexceptiondialog.moc"
 
28
#include "oxygendetectwidget.h"
 
29
 
 
30
#include <cassert>
 
31
 
 
32
 
 
33
namespace Oxygen
 
34
{
 
35
 
 
36
    //___________________________________________
 
37
    ExceptionDialog::ExceptionDialog( QWidget* parent ):
 
38
        KDialog( parent ),
 
39
        _detectDialog(0)
 
40
    {
 
41
 
 
42
        // define buttons
 
43
        setButtons( Ok|Cancel );
 
44
        QWidget* local( new QWidget( this ) );
 
45
        ui.setupUi( local );
 
46
        setMainWidget( local );
 
47
 
 
48
        // exception type
 
49
        ui.exceptionType->insertItems( 0, QStringList()
 
50
            << Exception::typeName( Exception::WindowClassName, true )
 
51
            << Exception::typeName( Exception::WindowTitle, true )
 
52
            );
 
53
 
 
54
        connect( ui.detectDialogButton, SIGNAL( clicked( void ) ), SLOT( selectWindowProperties() ) );
 
55
 
 
56
        // border size
 
57
        ui.frameBorderComboBox->insertItems(0, QStringList()
 
58
            << Configuration::frameBorderName( Configuration::BorderNone, true )
 
59
            << Configuration::frameBorderName( Configuration::BorderNoSide, true )
 
60
            << Configuration::frameBorderName( Configuration::BorderTiny, true )
 
61
            << Configuration::frameBorderName( Configuration::BorderDefault, true )
 
62
            << Configuration::frameBorderName( Configuration::BorderLarge, true )
 
63
            << Configuration::frameBorderName( Configuration::BorderVeryLarge, true )
 
64
            << Configuration::frameBorderName( Configuration::BorderHuge, true )
 
65
            << Configuration::frameBorderName( Configuration::BorderVeryHuge, true )
 
66
            << Configuration::frameBorderName( Configuration::BorderOversized, true )
 
67
            );
 
68
        ui.frameBorderComboBox->setEnabled( false );
 
69
        _checkBoxes.insert( std::make_pair( Exception::FrameBorder, ui.frameBorderCheckBox ) );
 
70
        connect( ui.frameBorderCheckBox, SIGNAL( toggled( bool ) ), ui.frameBorderComboBox, SLOT( setEnabled( bool ) ) );
 
71
 
 
72
        // blend color
 
73
        ui.blendColorComboBox->insertItems(0, QStringList()
 
74
            << Exception::blendColorName( Exception::NoBlending, true )
 
75
            << Exception::blendColorName( Exception::RadialBlending, true )
 
76
            << Exception::blendColorName( Exception::BlendFromStyle, true )
 
77
            );
 
78
        ui.blendColorComboBox->setEnabled( false );
 
79
        _checkBoxes.insert( std::make_pair( Exception::BlendColor, ui.blendColorCheckBox ) );
 
80
        connect( ui.blendColorCheckBox, SIGNAL( toggled( bool ) ), ui.blendColorComboBox, SLOT( setEnabled( bool ) ) );
 
81
 
 
82
        // size grip
 
83
        ui.sizeGripComboBox->insertItems(0, QStringList()
 
84
            << Configuration::sizeGripModeName( Configuration::SizeGripNever, true )
 
85
            << Configuration::sizeGripModeName( Configuration::SizeGripWhenNeeded, true )
 
86
            );
 
87
        ui.sizeGripComboBox->setEnabled( false );
 
88
        _checkBoxes.insert( std::make_pair( Exception::SizeGripMode, ui.sizeGripCheckBox ) );
 
89
        connect( ui.sizeGripCheckBox, SIGNAL( toggled( bool ) ), ui.sizeGripComboBox, SLOT( setEnabled( bool ) ) );
 
90
 
 
91
        // outline active window title
 
92
        ui.titleOutlineComboBox->insertItems(0, QStringList() << i18nc( "outline window title", "Enabled" ) << i18nc( "outline window title", "Disabled" ) );
 
93
        ui.titleOutlineComboBox->setEnabled( false );
 
94
        _checkBoxes.insert( std::make_pair( Exception::TitleOutline, ui.titleOutlineCheckBox ) );
 
95
        connect( ui.titleOutlineCheckBox, SIGNAL( toggled( bool ) ), ui.titleOutlineComboBox, SLOT( setEnabled( bool ) ) );
 
96
 
 
97
        // separator
 
98
        ui.separatorComboBox->setEnabled( false );
 
99
        _checkBoxes.insert( std::make_pair( Exception::DrawSeparator, ui.separatorCheckBox ) );
 
100
        connect( ui.separatorCheckBox, SIGNAL( toggled( bool ) ), ui.separatorComboBox, SLOT( setEnabled( bool ) ) );
 
101
 
 
102
    }
 
103
 
 
104
    //___________________________________________
 
105
    void ExceptionDialog::setException( Exception exception )
 
106
    {
 
107
 
 
108
        // store exception internally
 
109
        _exception = exception;
 
110
 
 
111
        // type
 
112
        ui.exceptionType->setCurrentIndex( ui.exceptionType->findText( exception.typeName( true ) ) );
 
113
        ui.exceptionEditor->setText( exception.regExp().pattern() );
 
114
        ui.frameBorderComboBox->setCurrentIndex( ui.frameBorderComboBox->findText( exception.frameBorderName( true ) ) );
 
115
        ui.blendColorComboBox->setCurrentIndex( ui.blendColorComboBox->findText( exception.blendColorName( true ) ) );
 
116
        ui.sizeGripComboBox->setCurrentIndex( ui.sizeGripComboBox->findText( exception.sizeGripModeName( true ) ) );
 
117
        ui.separatorComboBox->setCurrentIndex( exception.separatorMode() );
 
118
        ui.titleOutlineComboBox->setCurrentIndex( ui.titleOutlineComboBox->findText( exception.drawTitleOutline() ? i18nc( "outline window title", "Enabled" ) : i18nc( "outline window title", "Disabled" ) ) );
 
119
        ui.hideTitleBar->setChecked( exception.hideTitleBar() );
 
120
 
 
121
        // mask
 
122
        for( CheckBoxMap::iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
 
123
        { iter->second->setChecked( exception.mask() & iter->first ); }
 
124
 
 
125
    }
 
126
 
 
127
    //___________________________________________
 
128
    Exception ExceptionDialog::exception( void ) const
 
129
    {
 
130
        Exception exception( _exception );
 
131
        exception.setType( Exception::type( ui.exceptionType->currentText(), true ) );
 
132
        exception.regExp().setPattern( ui.exceptionEditor->text() );
 
133
        exception.setFrameBorder( Exception::frameBorder( ui.frameBorderComboBox->currentText(), true ) );
 
134
        exception.setBlendColor( Exception::blendColor( ui.blendColorComboBox->currentText(), true ) );
 
135
        exception.setSizeGripMode( Exception::sizeGripMode( ui.sizeGripComboBox->currentText(), true ) );
 
136
 
 
137
        // flags
 
138
        switch( ui.separatorComboBox->currentIndex() )
 
139
        {
 
140
            default:
 
141
            case 0: exception.setSeparatorMode( Configuration::SeparatorNever ); break;
 
142
            case 1: exception.setSeparatorMode( Configuration::SeparatorActive ); break;
 
143
            case 2: exception.setSeparatorMode( Configuration::SeparatorAlways ); break;
 
144
        }
 
145
 
 
146
        exception.setDrawTitleOutline( ui.titleOutlineComboBox->currentText() == i18nc( "outline window title", "Enabled" ) );
 
147
        exception.setHideTitleBar( ui.hideTitleBar->isChecked() );
 
148
 
 
149
        // mask
 
150
        unsigned int mask = Exception::None;
 
151
        for( CheckBoxMap::const_iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
 
152
        { if( iter->second->isChecked() ) mask |= iter->first; }
 
153
 
 
154
        exception.setMask( mask );
 
155
        return exception;
 
156
 
 
157
    }
 
158
 
 
159
    //___________________________________________
 
160
    void ExceptionDialog::selectWindowProperties( void )
 
161
    {
 
162
 
 
163
        // create widget
 
164
        if( !_detectDialog )
 
165
        {
 
166
            _detectDialog = new DetectDialog( this );
 
167
            connect( _detectDialog, SIGNAL( detectionDone( bool ) ), SLOT( readWindowProperties( bool ) ) );
 
168
        }
 
169
 
 
170
        _detectDialog->detect(0);
 
171
 
 
172
    }
 
173
 
 
174
    //___________________________________________
 
175
    void ExceptionDialog::readWindowProperties( bool valid )
 
176
    {
 
177
        assert( _detectDialog );
 
178
        if( valid )
 
179
        {
 
180
 
 
181
            // type
 
182
            ui.exceptionType->setCurrentIndex( ui.exceptionType->findText( Exception::typeName( _detectDialog->exceptionType(), true ) ) );
 
183
 
 
184
            // window info
 
185
            const KWindowInfo& info( _detectDialog->windowInfo() );
 
186
 
 
187
            switch( _detectDialog->exceptionType() )
 
188
            {
 
189
                case Exception::WindowClassName:
 
190
                ui.exceptionEditor->setText( info.windowClassClass() );
 
191
                break;
 
192
 
 
193
                case Exception::WindowTitle:
 
194
                ui.exceptionEditor->setText( info.name() );
 
195
                break;
 
196
 
 
197
                default: assert( false );
 
198
 
 
199
            }
 
200
 
 
201
        }
 
202
 
 
203
        delete _detectDialog;
 
204
        _detectDialog = 0;
 
205
 
 
206
    }
 
207
 
 
208
}