1
//////////////////////////////////////////////////////////////////////////////
2
// oxygenexceptiondialog.cpp
5
// Copyright (c) 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
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:
14
// The above copyright notice and this permission notice shall be included in
15
// all copies or substantial portions of the Software.
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
24
//////////////////////////////////////////////////////////////////////////////
26
#include "oxygenexceptiondialog.h"
27
#include "oxygenexceptiondialog.moc"
28
#include "oxygendetectwidget.h"
36
//___________________________________________
37
ExceptionDialog::ExceptionDialog( QWidget* parent ):
43
setButtons( Ok|Cancel );
44
QWidget* local( new QWidget( this ) );
46
setMainWidget( local );
49
ui.exceptionType->insertItems( 0, QStringList()
50
<< Exception::typeName( Exception::WindowClassName, true )
51
<< Exception::typeName( Exception::WindowTitle, true )
54
connect( ui.detectDialogButton, SIGNAL( clicked( void ) ), SLOT( selectWindowProperties() ) );
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 )
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 ) ) );
73
ui.blendColorComboBox->insertItems(0, QStringList()
74
<< Exception::blendColorName( Exception::NoBlending, true )
75
<< Exception::blendColorName( Exception::RadialBlending, true )
76
<< Exception::blendColorName( Exception::BlendFromStyle, true )
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 ) ) );
83
ui.sizeGripComboBox->insertItems(0, QStringList()
84
<< Configuration::sizeGripModeName( Configuration::SizeGripNever, true )
85
<< Configuration::sizeGripModeName( Configuration::SizeGripWhenNeeded, true )
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 ) ) );
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 ) ) );
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 ) ) );
104
//___________________________________________
105
void ExceptionDialog::setException( Exception exception )
108
// store exception internally
109
_exception = exception;
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() );
122
for( CheckBoxMap::iterator iter = _checkBoxes.begin(); iter != _checkBoxes.end(); ++iter )
123
{ iter->second->setChecked( exception.mask() & iter->first ); }
127
//___________________________________________
128
Exception ExceptionDialog::exception( void ) const
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 ) );
138
switch( ui.separatorComboBox->currentIndex() )
141
case 0: exception.setSeparatorMode( Configuration::SeparatorNever ); break;
142
case 1: exception.setSeparatorMode( Configuration::SeparatorActive ); break;
143
case 2: exception.setSeparatorMode( Configuration::SeparatorAlways ); break;
146
exception.setDrawTitleOutline( ui.titleOutlineComboBox->currentText() == i18nc( "outline window title", "Enabled" ) );
147
exception.setHideTitleBar( ui.hideTitleBar->isChecked() );
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; }
154
exception.setMask( mask );
159
//___________________________________________
160
void ExceptionDialog::selectWindowProperties( void )
166
_detectDialog = new DetectDialog( this );
167
connect( _detectDialog, SIGNAL( detectionDone( bool ) ), SLOT( readWindowProperties( bool ) ) );
170
_detectDialog->detect(0);
174
//___________________________________________
175
void ExceptionDialog::readWindowProperties( bool valid )
177
assert( _detectDialog );
182
ui.exceptionType->setCurrentIndex( ui.exceptionType->findText( Exception::typeName( _detectDialog->exceptionType(), true ) ) );
185
const KWindowInfo& info( _detectDialog->windowInfo() );
187
switch( _detectDialog->exceptionType() )
189
case Exception::WindowClassName:
190
ui.exceptionEditor->setText( info.windowClassClass() );
193
case Exception::WindowTitle:
194
ui.exceptionEditor->setText( info.name() );
197
default: assert( false );
203
delete _detectDialog;