KDE: Add kwin theme lib to kali-themes-common package

This commit is contained in:
Daniel Ruiz de Alegría
2021-10-05 12:10:40 +02:00
parent eee6ca8a13
commit e234afaa94
41 changed files with 15 additions and 4 deletions
@@ -0,0 +1,187 @@
//////////////////////////////////////////////////////////////////////////////
// breezeconfigurationui.cpp
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezeconfigwidget.h"
#include "breezeexceptionlist.h"
#include <KLocalizedString>
#include <QDBusConnection>
#include <QDBusMessage>
namespace Breeze
{
//_________________________________________________________
ConfigWidget::ConfigWidget( QWidget* parent, const QVariantList &args ):
KCModule(parent, args),
m_configuration( KSharedConfig::openConfig( QStringLiteral( "breezerc" ) ) ),
m_changed( false )
{
// configuration
m_ui.setupUi( this );
// track ui changes
connect( m_ui.titleAlignment, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( m_ui.buttonSize, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( m_ui.outlineCloseButton, &QAbstractButton::clicked, this, &ConfigWidget::updateChanged );
connect( m_ui.drawBorderOnMaximizedWindows, &QAbstractButton::clicked, this, &ConfigWidget::updateChanged );
connect( m_ui.drawSizeGrip, &QAbstractButton::clicked, this, &ConfigWidget::updateChanged );
connect( m_ui.drawBackgroundGradient, &QAbstractButton::clicked, this, &ConfigWidget::updateChanged );
connect( m_ui.drawTitleBarSeparator, &QAbstractButton::clicked, this, &ConfigWidget::updateChanged );
// track shadows changes
connect( m_ui.shadowSize, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( m_ui.shadowStrength, SIGNAL(valueChanged(int)), SLOT(updateChanged()) );
connect( m_ui.shadowColor, &KColorButton::changed, this, &ConfigWidget::updateChanged );
// track exception changes
connect( m_ui.exceptions, &ExceptionListWidget::changed, this, &ConfigWidget::updateChanged );
}
//_________________________________________________________
void ConfigWidget::load()
{
// create internal settings and load from rc files
m_internalSettings = InternalSettingsPtr( new InternalSettings() );
m_internalSettings->load();
// assign to ui
m_ui.titleAlignment->setCurrentIndex( m_internalSettings->titleAlignment() );
m_ui.buttonSize->setCurrentIndex( m_internalSettings->buttonSize() );
m_ui.drawBorderOnMaximizedWindows->setChecked( m_internalSettings->drawBorderOnMaximizedWindows() );
m_ui.outlineCloseButton->setChecked( m_internalSettings->outlineCloseButton() );
m_ui.drawSizeGrip->setChecked( m_internalSettings->drawSizeGrip() );
m_ui.drawBackgroundGradient->setChecked( m_internalSettings->drawBackgroundGradient() );
m_ui.drawTitleBarSeparator->setChecked( m_internalSettings->drawTitleBarSeparator() );
// load shadows
if( m_internalSettings->shadowSize() <= InternalSettings::ShadowVeryLarge ) m_ui.shadowSize->setCurrentIndex( m_internalSettings->shadowSize() );
else m_ui.shadowSize->setCurrentIndex( InternalSettings::ShadowLarge );
m_ui.shadowStrength->setValue( qRound(qreal(m_internalSettings->shadowStrength()*100)/255 ) );
m_ui.shadowColor->setColor( m_internalSettings->shadowColor() );
// load exceptions
ExceptionList exceptions;
exceptions.readConfig( m_configuration );
m_ui.exceptions->setExceptions( exceptions.get() );
setChanged( false );
}
//_________________________________________________________
void ConfigWidget::save()
{
// create internal settings and load from rc files
m_internalSettings = InternalSettingsPtr( new InternalSettings() );
m_internalSettings->load();
// apply modifications from ui
m_internalSettings->setTitleAlignment( m_ui.titleAlignment->currentIndex() );
m_internalSettings->setButtonSize( m_ui.buttonSize->currentIndex() );
m_internalSettings->setOutlineCloseButton( m_ui.outlineCloseButton->isChecked() );
m_internalSettings->setDrawBorderOnMaximizedWindows( m_ui.drawBorderOnMaximizedWindows->isChecked() );
m_internalSettings->setDrawSizeGrip( m_ui.drawSizeGrip->isChecked() );
m_internalSettings->setDrawBackgroundGradient( m_ui.drawBackgroundGradient->isChecked() );
m_internalSettings->setDrawTitleBarSeparator(m_ui.drawTitleBarSeparator->isChecked());
m_internalSettings->setShadowSize( m_ui.shadowSize->currentIndex() );
m_internalSettings->setShadowStrength( qRound( qreal(m_ui.shadowStrength->value()*255)/100 ) );
m_internalSettings->setShadowColor( m_ui.shadowColor->color() );
// save configuration
m_internalSettings->save();
// get list of exceptions and write
InternalSettingsList exceptions( m_ui.exceptions->exceptions() );
ExceptionList( exceptions ).writeConfig( m_configuration );
// sync configuration
m_configuration->sync();
setChanged( false );
// needed to tell kwin to reload when running from external kcmshell
{
QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig");
QDBusConnection::sessionBus().send(message);
}
// needed for breeze style to reload shadows
{
QDBusMessage message( QDBusMessage::createSignal("/BreezeDecoration", "org.kde.Breeze.Style", "reparseConfiguration") );
QDBusConnection::sessionBus().send(message);
}
}
//_________________________________________________________
void ConfigWidget::defaults()
{
// create internal settings and load from rc files
m_internalSettings = InternalSettingsPtr( new InternalSettings() );
m_internalSettings->setDefaults();
// assign to ui
m_ui.titleAlignment->setCurrentIndex( m_internalSettings->titleAlignment() );
m_ui.buttonSize->setCurrentIndex( m_internalSettings->buttonSize() );
m_ui.outlineCloseButton->setChecked( m_internalSettings->outlineCloseButton() );
m_ui.drawBorderOnMaximizedWindows->setChecked( m_internalSettings->drawBorderOnMaximizedWindows() );
m_ui.drawSizeGrip->setChecked( m_internalSettings->drawSizeGrip() );
m_ui.drawBackgroundGradient->setChecked( m_internalSettings->drawBackgroundGradient() );
m_ui.drawTitleBarSeparator->setChecked( m_internalSettings->drawTitleBarSeparator() );
m_ui.shadowSize->setCurrentIndex( m_internalSettings->shadowSize() );
m_ui.shadowStrength->setValue( qRound(qreal(m_internalSettings->shadowStrength()*100)/255 ) );
m_ui.shadowColor->setColor( m_internalSettings->shadowColor() );
}
//_______________________________________________
void ConfigWidget::updateChanged()
{
// check configuration
if( !m_internalSettings ) return;
// track modifications
bool modified( false );
if (m_ui.drawTitleBarSeparator->isChecked() != m_internalSettings->drawTitleBarSeparator()) modified = true;
if( m_ui.titleAlignment->currentIndex() != m_internalSettings->titleAlignment() ) modified = true;
else if( m_ui.buttonSize->currentIndex() != m_internalSettings->buttonSize() ) modified = true;
else if( m_ui.outlineCloseButton->isChecked() != m_internalSettings->outlineCloseButton() ) modified = true;
else if( m_ui.drawBorderOnMaximizedWindows->isChecked() != m_internalSettings->drawBorderOnMaximizedWindows() ) modified = true;
else if( m_ui.drawSizeGrip->isChecked() != m_internalSettings->drawSizeGrip() ) modified = true;
else if( m_ui.drawBackgroundGradient->isChecked() != m_internalSettings->drawBackgroundGradient() ) modified = true;
// shadows
else if( m_ui.shadowSize->currentIndex() != m_internalSettings->shadowSize() ) modified = true;
else if( qRound( qreal(m_ui.shadowStrength->value()*255)/100 ) != m_internalSettings->shadowStrength() ) modified = true;
else if( m_ui.shadowColor->color() != m_internalSettings->shadowColor() ) modified = true;
// exceptions
else if( m_ui.exceptions->isChanged() ) modified = true;
setChanged( modified );
}
//_______________________________________________
void ConfigWidget::setChanged( bool value )
{
emit changed( value );
}
}
@@ -0,0 +1,77 @@
#ifndef breezeconfigwidget_h
#define breezeconfigwidget_h
//////////////////////////////////////////////////////////////////////////////
// breezeconfigurationui.h
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "ui_breezeconfigurationui.h"
#include "breezeexceptionlistwidget.h"
#include "breezesettings.h"
#include "breeze.h"
#include <KCModule>
#include <KSharedConfig>
#include <QWidget>
#include <QSharedPointer>
namespace Breeze
{
//_____________________________________________
class ConfigWidget: public KCModule
{
Q_OBJECT
public:
//* constructor
explicit ConfigWidget( QWidget*, const QVariantList& );
//* destructor
virtual ~ConfigWidget() = default;
//* default
void defaults() override;
//* load configuration
void load() override;
//* save configuration
void save() override;
protected Q_SLOTS:
//* update changed state
virtual void updateChanged();
protected:
//* set changed state
void setChanged( bool );
private:
//* ui
Ui_BreezeConfigurationUI m_ui;
//* kconfiguration object
KSharedConfig::Ptr m_configuration;
//* internal exception
InternalSettingsPtr m_internalSettings;
//* changed state
bool m_changed;
};
}
#endif
@@ -0,0 +1,166 @@
//////////////////////////////////////////////////////////////////////////////
// breezedetectwidget.cpp
// Note: this class is a stripped down version of
// /kdebase/workspace/kwin/kcmkwin/kwinrules/detectwidget.cpp
// SPDX-FileCopyrightText: 2004 Lubos Lunak <l.lunak@kde.org>
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezedetectwidget.h"
#include "breeze.h"
#include <KWindowInfo>
#include <QPushButton>
#include <QMouseEvent>
#include <config-breeze.h>
#if BREEZE_HAVE_X11
#include <QX11Info>
#include <xcb/xcb.h>
#endif
namespace Breeze
{
//_________________________________________________________
DetectDialog::DetectDialog( QWidget* parent ):
QDialog( parent )
{
// setup
m_ui.setupUi( this );
connect( m_ui.buttonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked, this, &QWidget::close );
m_ui.windowClassCheckBox->setChecked( true );
#if BREEZE_HAVE_X11
if (QX11Info::isPlatformX11()) {
// create atom
xcb_connection_t* connection( QX11Info::connection() );
const QString atomName( QStringLiteral( "WM_STATE" ) );
xcb_intern_atom_cookie_t cookie( xcb_intern_atom( connection, false, atomName.size(), qPrintable( atomName ) ) );
QScopedPointer<xcb_intern_atom_reply_t, QScopedPointerPodDeleter> reply( xcb_intern_atom_reply( connection, cookie, nullptr) );
m_wmStateAtom = reply ? reply->atom : 0;
}
#endif
}
//_________________________________________________________
void DetectDialog::detect( WId window )
{
if( window == 0 ) selectWindow();
else readWindow( window );
}
//_________________________________________________________
void DetectDialog::readWindow( WId window )
{
if( window == 0 )
{
emit detectionDone( false );
return;
}
m_info.reset(new KWindowInfo( window, NET::WMAllProperties, NET::WM2AllProperties ));
if( !m_info->valid())
{
emit detectionDone( false );
return;
}
const QString wmClassClass( QString::fromUtf8( m_info->windowClassClass() ) );
const QString wmClassName( QString::fromUtf8( m_info->windowClassName() ) );
m_ui.windowClass->setText( QStringLiteral( "%1 (%2 %3)" ).arg( wmClassClass ).arg( wmClassName ).arg( wmClassClass ) );
m_ui.windowTitle->setText( m_info->name() );
emit detectionDone( exec() == QDialog::Accepted );
}
//_________________________________________________________
void DetectDialog::selectWindow()
{
// use a dialog, so that all user input is blocked
// use WX11BypassWM and moving away so that it's not actually visible
// grab only mouse, so that keyboard can be used e.g. for switching windows
m_grabber = new QDialog( nullptr, Qt::X11BypassWindowManagerHint );
m_grabber->move( -1000, -1000 );
m_grabber->setModal( true );
m_grabber->show();
// need to explicitly override cursor for Qt5
qApp->setOverrideCursor( Qt::CrossCursor );
m_grabber->grabMouse( Qt::CrossCursor );
m_grabber->installEventFilter( this );
}
//_________________________________________________________
bool DetectDialog::eventFilter( QObject* o, QEvent* e )
{
// check object and event type
if( o != m_grabber ) return false;
if( e->type() != QEvent::MouseButtonRelease ) return false;
// need to explicitly release cursor for Qt5
qApp->restoreOverrideCursor();
// delete old m_grabber
delete m_grabber;
m_grabber = nullptr;
// check button
if( static_cast< QMouseEvent* >( e )->button() != Qt::LeftButton ) return true;
// read window information
readWindow( findWindow() );
return true;
}
//_________________________________________________________
WId DetectDialog::findWindow()
{
#if BREEZE_HAVE_X11
if (!QX11Info::isPlatformX11()) {
return 0;
}
// check atom
if( !m_wmStateAtom ) return 0;
xcb_connection_t* connection( QX11Info::connection() );
xcb_window_t parent( QX11Info::appRootWindow() );
// why is there a loop of only 10 here
for( int i = 0; i < 10; ++i )
{
// query pointer
xcb_query_pointer_cookie_t pointerCookie( xcb_query_pointer( connection, parent ) );
QScopedPointer<xcb_query_pointer_reply_t, QScopedPointerPodDeleter> pointerReply( xcb_query_pointer_reply( connection, pointerCookie, nullptr ) );
if( !( pointerReply && pointerReply->child ) ) return 0;
const xcb_window_t child( pointerReply->child );
xcb_get_property_cookie_t cookie( xcb_get_property( connection, 0, child, m_wmStateAtom, XCB_GET_PROPERTY_TYPE_ANY, 0, 0 ) );
QScopedPointer<xcb_get_property_reply_t, QScopedPointerPodDeleter> reply( xcb_get_property_reply( connection, cookie, nullptr ) );
if( reply && reply->type ) return child;
else parent = child;
}
#endif
return 0;
}
}
@@ -0,0 +1,97 @@
#ifndef breezedetectwidget_h
#define breezedetectwidget_h
//////////////////////////////////////////////////////////////////////////////
// breezedetectwidget.h
// Note: this class is a stripped down version of
// /kdebase/workspace/kwin/kcmkwin/kwinrules/detectwidget.h
// SPDX-FileCopyrightText: 2004 Lubos Lunak <l.lunak@kde.org>
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezesettings.h"
#include "ui_breezedetectwidget.h"
#include <QByteArray>
#include <QCheckBox>
#include <QDialog>
#include <QEvent>
#include <QLabel>
#include <kwindowsystem.h>
namespace Breeze
{
class DetectDialog : public QDialog
{
Q_OBJECT
public:
//* constructor
explicit DetectDialog( QWidget* );
//* read window properties or select one from mouse grab
void detect( WId window );
//* selected class
QByteArray selectedClass() const;
//* window information
const KWindowInfo& windowInfo() const
{ return *(m_info.data()); }
//* exception type
InternalSettings::EnumExceptionType exceptionType() const
{
if( m_ui.windowClassCheckBox->isChecked() ) return InternalSettings::ExceptionWindowClassName;
else if( m_ui.windowTitleCheckBox->isChecked() ) return InternalSettings::ExceptionWindowTitle;
else return InternalSettings::ExceptionWindowClassName;
}
Q_SIGNALS:
void detectionDone( bool );
protected:
bool eventFilter( QObject* o, QEvent* e ) override;
private:
//* select window from grab
void selectWindow();
//* read window properties
void readWindow( WId window );
//* find window under cursor
WId findWindow();
//* execute
void executeDialog();
//* ui
Ui::BreezeDetectWidget m_ui;
//* invisible dialog used to grab mouse
QDialog* m_grabber = nullptr;
//* current window information
QScopedPointer<KWindowInfo> m_info;
//* wm state atom
quint32 m_wmStateAtom = 0;
};
} // namespace
#endif
@@ -0,0 +1,168 @@
//////////////////////////////////////////////////////////////////////////////
// breezeexceptiondialog.cpp
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezeexceptiondialog.h"
#include "breezedetectwidget.h"
#include "config-breeze.h"
#if BREEZE_HAVE_X11
#include <QX11Info>
#endif
namespace Breeze
{
//___________________________________________
ExceptionDialog::ExceptionDialog( QWidget* parent ):
QDialog( parent )
{
m_ui.setupUi( this );
connect( m_ui.buttonBox->button( QDialogButtonBox::Cancel ), &QAbstractButton::clicked, this, &QWidget::close );
// store checkboxes from ui into list
m_checkboxes.insert( BorderSize, m_ui.borderSizeCheckBox );
// detect window properties
connect( m_ui.detectDialogButton, &QAbstractButton::clicked, this, &ExceptionDialog::selectWindowProperties );
// connections
connect( m_ui.exceptionType, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
connect( m_ui.exceptionEditor, &QLineEdit::textChanged, this, &ExceptionDialog::updateChanged );
connect( m_ui.borderSizeComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) );
for( CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter )
{ connect( iter.value(), &QAbstractButton::clicked, this, &ExceptionDialog::updateChanged ); }
connect( m_ui.hideTitleBar, &QAbstractButton::clicked, this, &ExceptionDialog::updateChanged );
// hide detection dialog on non X11 platforms
#if BREEZE_HAVE_X11
if( !QX11Info::isPlatformX11() ) m_ui.detectDialogButton->hide();
#else
m_ui.detectDialogButton->hide();
#endif
}
//___________________________________________
void ExceptionDialog::setException( InternalSettingsPtr exception )
{
// store exception internally
m_exception = exception;
// type
m_ui.exceptionType->setCurrentIndex(m_exception->exceptionType() );
m_ui.exceptionEditor->setText( m_exception->exceptionPattern() );
m_ui.borderSizeComboBox->setCurrentIndex( m_exception->borderSize() );
m_ui.hideTitleBar->setChecked( m_exception->hideTitleBar() );
// mask
for( CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter )
{ iter.value()->setChecked( m_exception->mask() & iter.key() ); }
setChanged( false );
}
//___________________________________________
void ExceptionDialog::save()
{
m_exception->setExceptionType( m_ui.exceptionType->currentIndex() );
m_exception->setExceptionPattern( m_ui.exceptionEditor->text() );
m_exception->setBorderSize( m_ui.borderSizeComboBox->currentIndex() );
m_exception->setHideTitleBar( m_ui.hideTitleBar->isChecked() );
// mask
unsigned int mask = None;
for( CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter )
{ if( iter.value()->isChecked() ) mask |= iter.key(); }
m_exception->setMask( mask );
setChanged( false );
}
//___________________________________________
void ExceptionDialog::updateChanged()
{
bool modified( false );
if( m_exception->exceptionType() != m_ui.exceptionType->currentIndex() ) modified = true;
else if( m_exception->exceptionPattern() != m_ui.exceptionEditor->text() ) modified = true;
else if( m_exception->borderSize() != m_ui.borderSizeComboBox->currentIndex() ) modified = true;
else if( m_exception->hideTitleBar() != m_ui.hideTitleBar->isChecked() ) modified = true;
else
{
// check mask
for( CheckBoxMap::iterator iter = m_checkboxes.begin(); iter != m_checkboxes.end(); ++iter )
{
if( iter.value()->isChecked() != (bool)( m_exception->mask() & iter.key() ) )
{
modified = true;
break;
}
}
}
setChanged( modified );
}
//___________________________________________
void ExceptionDialog::selectWindowProperties()
{
// create widget
if( !m_detectDialog )
{
m_detectDialog = new DetectDialog( this );
connect( m_detectDialog, &DetectDialog::detectionDone, this, &ExceptionDialog::readWindowProperties );
}
m_detectDialog->detect(0);
}
//___________________________________________
void ExceptionDialog::readWindowProperties( bool valid )
{
Q_CHECK_PTR( m_detectDialog );
if( valid )
{
// type
m_ui.exceptionType->setCurrentIndex( m_detectDialog->exceptionType() );
// window info
const KWindowInfo& info( m_detectDialog->windowInfo() );
switch( m_detectDialog->exceptionType() )
{
default:
case InternalSettings::ExceptionWindowClassName:
m_ui.exceptionEditor->setText( QString::fromUtf8( info.windowClassClass() ) );
break;
case InternalSettings::ExceptionWindowTitle:
m_ui.exceptionEditor->setText( info.name() );
break;
}
}
delete m_detectDialog;
m_detectDialog = nullptr;
}
}
@@ -0,0 +1,98 @@
#ifndef breezeexceptiondialog_h
#define breezeexceptiondialog_h
//////////////////////////////////////////////////////////////////////////////
// breezeexceptiondialog.h
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "ui_breezeexceptiondialog.h"
#include "breeze.h"
#include <QCheckBox>
#include <QMap>
namespace Breeze
{
class DetectDialog;
//* breeze exceptions list
class ExceptionDialog: public QDialog
{
Q_OBJECT
public:
//* constructor
explicit ExceptionDialog( QWidget* parent );
//* destructor
virtual ~ExceptionDialog()
{}
//* set exception
void setException( InternalSettingsPtr );
//* save exception
void save();
//* true if changed
virtual bool isChanged() const
{ return m_changed; }
Q_SIGNALS:
//* emitted when changed
void changed( bool );
protected:
//* set changed state
virtual void setChanged( bool value )
{
m_changed = value;
emit changed( value );
}
protected Q_SLOTS:
//* check whether configuration is changed and emit appropriate signal if yes
virtual void updateChanged();
private Q_SLOTS:
//* select window properties from grabbed pointers
void selectWindowProperties();
//* read properties of selected window
void readWindowProperties( bool );
private:
//* map mask and checkbox
using CheckBoxMap=QMap< ExceptionMask, QCheckBox*>;
Ui::BreezeExceptionDialog m_ui;
//* map mask and checkbox
CheckBoxMap m_checkboxes;
//* internal exception
InternalSettingsPtr m_exception;
//* detection dialog
DetectDialog* m_detectDialog = nullptr;
//* changed state
bool m_changed = false;
};
}
#endif
@@ -0,0 +1,329 @@
//////////////////////////////////////////////////////////////////////////////
// breezeexceptionlistwidget.cpp
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezeexceptionlistwidget.h"
#include "breezeexceptiondialog.h"
#include <KLocalizedString>
#include <QMessageBox>
#include <QPointer>
#include <QIcon>
//__________________________________________________________
namespace Breeze
{
//__________________________________________________________
ExceptionListWidget::ExceptionListWidget( QWidget* parent ):
QWidget( parent )
{
// ui
m_ui.setupUi( this );
// list
m_ui.exceptionListView->setAllColumnsShowFocus( true );
m_ui.exceptionListView->setRootIsDecorated( false );
m_ui.exceptionListView->setSortingEnabled( false );
m_ui.exceptionListView->setModel( &model() );
m_ui.exceptionListView->sortByColumn( ExceptionModel::ColumnType, Qt::AscendingOrder );
m_ui.exceptionListView->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Ignored ) );
m_ui.moveUpButton->setIcon( QIcon::fromTheme( QStringLiteral( "arrow-up" ) ) );
m_ui.moveDownButton->setIcon( QIcon::fromTheme( QStringLiteral( "arrow-down" ) ) );
m_ui.addButton->setIcon( QIcon::fromTheme( QStringLiteral( "list-add" ) ) );
m_ui.removeButton->setIcon( QIcon::fromTheme( QStringLiteral( "list-remove" ) ) );
m_ui.editButton->setIcon( QIcon::fromTheme( QStringLiteral( "edit-rename" ) ) );
connect( m_ui.addButton, &QAbstractButton::clicked, this, &ExceptionListWidget::add );
connect( m_ui.editButton, &QAbstractButton::clicked, this, &ExceptionListWidget::edit );
connect( m_ui.removeButton, &QAbstractButton::clicked, this, &ExceptionListWidget::remove );
connect( m_ui.moveUpButton, &QAbstractButton::clicked, this, &ExceptionListWidget::up );
connect( m_ui.moveDownButton, &QAbstractButton::clicked, this, &ExceptionListWidget::down );
connect( m_ui.exceptionListView, &QAbstractItemView::activated, this, &ExceptionListWidget::edit );
connect( m_ui.exceptionListView, &QAbstractItemView::clicked, this, &ExceptionListWidget::toggle );
connect( m_ui.exceptionListView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ExceptionListWidget::updateButtons );
updateButtons();
resizeColumns();
}
//__________________________________________________________
void ExceptionListWidget::setExceptions( const InternalSettingsList& exceptions )
{
model().set( exceptions );
resizeColumns();
setChanged( false );
}
//__________________________________________________________
InternalSettingsList ExceptionListWidget::exceptions()
{
return model().get();
setChanged( false );
}
//__________________________________________________________
void ExceptionListWidget::updateButtons()
{
bool hasSelection( !m_ui.exceptionListView->selectionModel()->selectedRows().empty() );
m_ui.removeButton->setEnabled( hasSelection );
m_ui.editButton->setEnabled( hasSelection );
m_ui.moveUpButton->setEnabled( hasSelection && !m_ui.exceptionListView->selectionModel()->isRowSelected( 0, QModelIndex() ) );
m_ui.moveDownButton->setEnabled( hasSelection && !m_ui.exceptionListView->selectionModel()->isRowSelected( model().rowCount()-1, QModelIndex() ) );
}
//_______________________________________________________
void ExceptionListWidget::add()
{
QPointer<ExceptionDialog> dialog = new ExceptionDialog( this );
dialog->setWindowTitle( i18n( "New Exception - Breeze Settings" ) );
InternalSettingsPtr exception( new InternalSettings() );
exception->load();
dialog->setException( exception );
// run dialog and check existence
if( !dialog->exec() )
{
delete dialog;
return;
}
dialog->save();
delete dialog;
// check exceptions
if( !checkException( exception ) ) return;
// create new item
model().add( exception );
setChanged( true );
// make sure item is selected
QModelIndex index( model().index( exception ) );
if( index != m_ui.exceptionListView->selectionModel()->currentIndex() )
{
m_ui.exceptionListView->selectionModel()->select( index, QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Rows );
m_ui.exceptionListView->selectionModel()->setCurrentIndex( index, QItemSelectionModel::Current|QItemSelectionModel::Rows );
}
resizeColumns();
}
//_______________________________________________________
void ExceptionListWidget::edit()
{
// retrieve selection
QModelIndex current( m_ui.exceptionListView->selectionModel()->currentIndex() );
if( ! model().contains( current ) ) return;
InternalSettingsPtr exception( model().get( current ) );
// create dialog
QPointer<ExceptionDialog> dialog( new ExceptionDialog( this ) );
dialog->setWindowTitle( i18n( "Edit Exception - Breeze Settings" ) );
dialog->setException( exception );
// map dialog
if( !dialog->exec() )
{
delete dialog;
return;
}
// check modifications
if( !dialog->isChanged() ) return;
// retrieve exception
dialog->save();
delete dialog;
// check new exception validity
checkException( exception );
resizeColumns();
setChanged( true );
}
//_______________________________________________________
void ExceptionListWidget::remove()
{
// confirmation dialog
{
QMessageBox messageBox( QMessageBox::Question, i18n("Question - Breeze Settings" ), i18n("Remove selected exception?"), QMessageBox::Yes | QMessageBox::Cancel );
messageBox.button( QMessageBox::Yes )->setText( i18n("Remove") );
messageBox.setDefaultButton( QMessageBox::Cancel );
if( messageBox.exec() == QMessageBox::Cancel ) return;
}
// remove
model().remove( model().get( m_ui.exceptionListView->selectionModel()->selectedRows() ) );
resizeColumns();
updateButtons();
setChanged( true );
}
//_______________________________________________________
void ExceptionListWidget::toggle( const QModelIndex& index )
{
if( !model().contains( index ) ) return;
if( index.column() != ExceptionModel::ColumnEnabled ) return;
// get matching exception
InternalSettingsPtr exception( model().get( index ) );
exception->setEnabled( !exception->enabled() );
setChanged( true );
}
//_______________________________________________________
void ExceptionListWidget::up()
{
InternalSettingsList selection( model().get( m_ui.exceptionListView->selectionModel()->selectedRows() ) );
if( selection.empty() ) { return; }
// retrieve selected indexes in list and store in model
QModelIndexList selectedIndices( m_ui.exceptionListView->selectionModel()->selectedRows() );
InternalSettingsList selectedExceptions( model().get( selectedIndices ) );
InternalSettingsList currentException( model().get() );
InternalSettingsList newExceptions;
for( InternalSettingsList::const_iterator iter = currentException.constBegin(); iter != currentException.constEnd(); ++iter )
{
// check if new list is not empty, current index is selected and last index is not.
// if yes, move.
if(
!( newExceptions.empty() ||
selectedIndices.indexOf( model().index( *iter ) ) == -1 ||
selectedIndices.indexOf( model().index( newExceptions.back() ) ) != -1
) )
{
InternalSettingsPtr last( newExceptions.back() );
newExceptions.removeLast();
newExceptions.append( *iter );
newExceptions.append( last );
} else newExceptions.append( *iter );
}
model().set( newExceptions );
// restore selection
m_ui.exceptionListView->selectionModel()->select( model().index( selectedExceptions.front() ), QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Rows );
for( InternalSettingsList::const_iterator iter = selectedExceptions.constBegin(); iter != selectedExceptions.constEnd(); ++iter )
{ m_ui.exceptionListView->selectionModel()->select( model().index( *iter ), QItemSelectionModel::Select|QItemSelectionModel::Rows ); }
setChanged( true );
}
//_______________________________________________________
void ExceptionListWidget::down()
{
InternalSettingsList selection( model().get( m_ui.exceptionListView->selectionModel()->selectedRows() ) );
if( selection.empty() )
{ return; }
// retrieve selected indexes in list and store in model
QModelIndexList selectedIndices( m_ui.exceptionListView->selectionModel()->selectedIndexes() );
InternalSettingsList selectedExceptions( model().get( selectedIndices ) );
InternalSettingsList currentExceptions( model().get() );
InternalSettingsList newExceptions;
InternalSettingsListIterator iter( currentExceptions );
iter.toBack();
while( iter.hasPrevious() )
{
InternalSettingsPtr current( iter.previous() );
// check if new list is not empty, current index is selected and last index is not.
// if yes, move.
if(
!( newExceptions.empty() ||
selectedIndices.indexOf( model().index( current ) ) == -1 ||
selectedIndices.indexOf( model().index( newExceptions.front() ) ) != -1
) )
{
InternalSettingsPtr first( newExceptions.front() );
newExceptions.removeFirst();
newExceptions.prepend( current );
newExceptions.prepend( first );
} else newExceptions.prepend( current );
}
model().set( newExceptions );
// restore selection
m_ui.exceptionListView->selectionModel()->select( model().index( selectedExceptions.front() ), QItemSelectionModel::Clear|QItemSelectionModel::Select|QItemSelectionModel::Rows );
for( InternalSettingsList::const_iterator iter = selectedExceptions.constBegin(); iter != selectedExceptions.constEnd(); ++iter )
{ m_ui.exceptionListView->selectionModel()->select( model().index( *iter ), QItemSelectionModel::Select|QItemSelectionModel::Rows ); }
setChanged( true );
}
//_______________________________________________________
void ExceptionListWidget::resizeColumns() const
{
m_ui.exceptionListView->resizeColumnToContents( ExceptionModel::ColumnEnabled );
m_ui.exceptionListView->resizeColumnToContents( ExceptionModel::ColumnType );
m_ui.exceptionListView->resizeColumnToContents( ExceptionModel::ColumnRegExp );
}
//_______________________________________________________
bool ExceptionListWidget::checkException( InternalSettingsPtr exception )
{
while( exception->exceptionPattern().isEmpty() || !QRegExp( exception->exceptionPattern() ).isValid() )
{
QMessageBox::warning( this, i18n( "Warning - Breeze Settings" ), i18n("Regular Expression syntax is incorrect") );
QPointer<ExceptionDialog> dialog( new ExceptionDialog( this ) );
dialog->setException( exception );
if( dialog->exec() == QDialog::Rejected )
{
delete dialog;
return false;
}
dialog->save();
delete dialog;
}
return true;
}
}
@@ -0,0 +1,108 @@
#ifndef breezeexceptionlistwidget_h
#define breezeexceptionlistwidget_h
//////////////////////////////////////////////////////////////////////////////
// breezeexceptionlistwidget.h
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "ui_breezeexceptionlistwidget.h"
#include "breezeexceptionmodel.h"
//* QDialog used to commit selected files
namespace Breeze
{
class ExceptionListWidget: public QWidget
{
//* Qt meta object
Q_OBJECT
public:
//* constructor
explicit ExceptionListWidget( QWidget* = nullptr );
//* set exceptions
void setExceptions( const InternalSettingsList& );
//* get exceptions
InternalSettingsList exceptions();
//* true if changed
virtual bool isChanged() const
{ return m_changed; }
Q_SIGNALS:
//* emitted when changed
void changed( bool );
protected:
//* model
const ExceptionModel& model() const
{ return m_model; }
//* model
ExceptionModel& model()
{ return m_model; }
protected Q_SLOTS:
//* update button states
virtual void updateButtons();
//* add
virtual void add();
//* edit
virtual void edit();
//* remove
virtual void remove();
//* toggle
virtual void toggle( const QModelIndex& );
//* move up
virtual void up();
//* move down
virtual void down();
protected:
//* resize columns
void resizeColumns() const;
//* check exception
bool checkException( InternalSettingsPtr );
//* set changed state
virtual void setChanged( bool value )
{
m_changed = value;
emit changed( value );
}
private:
//* model
ExceptionModel m_model;
//* ui
Ui_BreezeExceptionListWidget m_ui;
//* changed state
bool m_changed = false;
};
}
#endif
@@ -0,0 +1,91 @@
//////////////////////////////////////////////////////////////////////////////
// breezeexceptionmodel.cpp
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezeexceptionmodel.h"
#include <KLocalizedString>
namespace Breeze
{
//_______________________________________________
const QString ExceptionModel::m_columnTitles[ ExceptionModel::nColumns ] =
{
QStringLiteral( "" ),
i18n("Exception Type"),
i18n("Regular Expression")
};
//__________________________________________________________________
QVariant ExceptionModel::data( const QModelIndex& index, int role ) const
{
// check index, role and column
if( !index.isValid() ) return QVariant();
// retrieve associated file info
const InternalSettingsPtr& configuration( get(index) );
// return text associated to file and column
if( role == Qt::DisplayRole )
{
switch( index.column() )
{
case ColumnType:
{
switch( configuration->exceptionType() )
{
case InternalSettings::ExceptionWindowTitle:
return i18n( "Window Title" );
default:
case InternalSettings::ExceptionWindowClassName:
return i18n( "Window Class Name" );
}
}
case ColumnRegExp: return configuration->exceptionPattern();
default: return QVariant();
break;
}
} else if( role == Qt::CheckStateRole && index.column() == ColumnEnabled ) {
return configuration->enabled() ? Qt::Checked : Qt::Unchecked;
} else if( role == Qt::ToolTipRole && index.column() == ColumnEnabled ) {
return i18n("Enable/disable this exception");
}
return QVariant();
}
//__________________________________________________________________
QVariant ExceptionModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if(
orientation == Qt::Horizontal &&
role == Qt::DisplayRole &&
section >= 0 &&
section < nColumns )
{ return m_columnTitles[section]; }
// return empty
return QVariant();
}
}
@@ -0,0 +1,65 @@
#ifndef breezeexceptionmodel_h
#define breezeexceptionmodel_h
//////////////////////////////////////////////////////////////////////////////
// breezeexceptionmodel.h
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezelistmodel.h"
#include "breezesettings.h"
#include "breeze.h"
namespace Breeze
{
//* qlistview for object counters
class ExceptionModel: public ListModel<InternalSettingsPtr>
{
public:
//* number of columns
enum { nColumns = 3 };
//* column type enumeration
enum ColumnType {
ColumnEnabled,
ColumnType,
ColumnRegExp
};
//*@name methods reimplemented from base class
//@{
//* return data for a given index
QVariant data(const QModelIndex &index, int role) const override;
//* header data
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
//* number of columns for a given index
int columnCount(const QModelIndex& ) const override
{ return nColumns; }
//@}
protected:
//* sort
void privateSort( int, Qt::SortOrder ) override
{}
private:
//* column titles
static const QString m_columnTitles[ nColumns ];
};
}
#endif
@@ -0,0 +1,52 @@
//////////////////////////////////////////////////////////////////////////////
// itemmodel.cpp
// -------------------
//
// SPDX-FileCopyrightText: 2009-2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezeitemmodel.h"
namespace Breeze
{
//_______________________________________________________________
ItemModel::ItemModel( QObject* parent ):
QAbstractItemModel( parent )
{}
//____________________________________________________________
void ItemModel::sort( int column, Qt::SortOrder order )
{
// store column and order
m_sortColumn = column;
m_sortOrder = order;
// emit signals and call private methods
emit layoutAboutToBeChanged();
privateSort( column, order );
emit layoutChanged();
}
//____________________________________________________________
QModelIndexList ItemModel::indexes( int column, const QModelIndex& parent ) const
{
QModelIndexList out;
int rows( rowCount( parent ) );
for( int row = 0; row < rows; row++ )
{
QModelIndex index( this->index( row, column, parent ) );
if( !index.isValid() ) continue;
out.append( index );
out += indexes( column, index );
}
return out;
}
}
@@ -0,0 +1,97 @@
#ifndef ItemModel_h
#define ItemModel_h
//////////////////////////////////////////////////////////////////////////////
// itemmodel.h
// -------------------
//
// SPDX-FileCopyrightText: 2009-2010 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include <QAbstractItemModel>
namespace Breeze
{
//* Job model. Stores job information for display in lists
class ItemModel : public QAbstractItemModel
{
public:
//* constructor
explicit ItemModel(QObject *parent = nullptr);
//* destructor
virtual ~ItemModel()
{}
//* return all indexes in model starting from parent [recursive]
QModelIndexList indexes( int column = 0, const QModelIndex& parent = QModelIndex() ) const;
//*@name sorting
//@{
//* sort
virtual void sort()
{ sort( sortColumn(), sortOrder() ); }
//* sort
void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override;
//* current sorting column
const int& sortColumn() const
{ return m_sortColumn; }
//* current sort order
const Qt::SortOrder& sortOrder() const
{ return m_sortOrder; }
//@}
protected:
//* this sort columns without calling the layout changed callbacks
void privateSort()
{ privateSort( m_sortColumn, m_sortOrder ); }
//* private sort, with no signals emitted
virtual void privateSort( int column, Qt::SortOrder order ) = 0;
//* used to sort items in list
class SortFTor
{
public:
//* constructor
explicit SortFTor( const int& type, Qt::SortOrder order = Qt::AscendingOrder ):
_type( type ),
_order( order )
{}
protected:
//* column
int _type;
//* order
Qt::SortOrder _order;
};
private:
//* sorting column
int m_sortColumn = 0;
//* sorting order
Qt::SortOrder m_sortOrder = Qt::AscendingOrder;
};
}
#endif
@@ -0,0 +1,349 @@
#ifndef ListModel_h
#define ListModel_h
//////////////////////////////////////////////////////////////////////////////
// listmodel.h
// -------------------
//
// SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
//
// SPDX-License-Identifier: MIT
//////////////////////////////////////////////////////////////////////////////
#include "breezeitemmodel.h"
#include <QSet>
#include <QList>
#include <algorithm>
namespace Breeze
{
//! Job model. Stores job information for display in lists
template<class T> class ListModel : public ItemModel
{
public:
//! value type
typedef T ValueType;
//! reference
typedef T& Reference;
//! pointer
typedef T* Pointer;
//! value list and iterators
typedef QList<ValueType> List;
typedef QListIterator<ValueType> ListIterator;
typedef QMutableListIterator<ValueType> MutableListIterator;
//! list of vector
// typedef QSet<ValueType> Set;
//! constructor
ListModel(QObject *parent = nullptr):
ItemModel( parent )
{}
//! destructor
virtual ~ListModel()
{}
//!@name methods reimplemented from base class
//@{
//! flags
Qt::ItemFlags flags(const QModelIndex &index) const override
{
if (!index.isValid()) return Qt::NoItemFlags;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
//! unique index for given row, column and parent index
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
{
// check if index is valid
if( !hasIndex( row, column, parent ) ) return QModelIndex();
// return invalid index if parent is valid
if( parent.isValid() ) return QModelIndex();
// check against _values
return ( row < (int) _values.size() ) ? createIndex( row, column ):QModelIndex();
}
//! index of parent
QModelIndex parent(const QModelIndex &) const override
{ return QModelIndex(); }
//! number of rows below given index
int rowCount(const QModelIndex &parent = QModelIndex()) const override
{ return parent.isValid() ? 0:_values.size(); }
//@}
//!@name selection
//@{
//! clear internal list selected items
virtual void clearSelectedIndexes()
{ _selection.clear(); }
//! store index internal selection state
virtual void setIndexSelected( const QModelIndex& index, bool value )
{
if( value ) _selection.push_back( get(index) );
else _selection.erase( std::remove( _selection.begin(), _selection.end(), get(index) ), _selection.end() );
}
//! get list of internal selected items
virtual QModelIndexList selectedIndexes() const
{
QModelIndexList out;
for( typename List::const_iterator iter = _selection.begin(); iter != _selection.end(); iter++ )
{
QModelIndex index( ListModel::index( *iter ) );
if( index.isValid() ) out.push_back( index );
}
return out;
}
//@}
//!@name interface
//@{
//! add value
virtual void add( const ValueType& value )
{
emit layoutAboutToBeChanged();
_add( value );
privateSort();
emit layoutChanged();
}
//! add values
virtual void add( const List& values )
{
// check if not empty
// this avoids sending useless signals
if( values.empty() ) return;
emit layoutAboutToBeChanged();
for( typename List::const_iterator iter = values.begin(); iter != values.end(); iter++ )
{ _add( *iter ); }
privateSort();
emit layoutChanged();
}
//! insert values
virtual void insert( const QModelIndex& index, const ValueType& value )
{
emit layoutAboutToBeChanged();
_insert( index, value );
emit layoutChanged();
}
//! insert values
virtual void insert( const QModelIndex& index, const List& values )
{
emit layoutAboutToBeChanged();
// need to loop in reverse order so that the "values" ordering is preserved
ListIterator iter( values );
iter.toBack();
while( iter.hasPrevious() )
{ _insert( index, iter.previous() ); }
emit layoutChanged();
}
//! insert values
virtual void replace( const QModelIndex& index, const ValueType& value )
{
if( !index.isValid() ) add( value );
else {
emit layoutAboutToBeChanged();
setIndexSelected( index, false );
_values[index.row()] = value;
setIndexSelected( index, true );
emit layoutChanged();
}
}
//! remove
virtual void remove( const ValueType& value )
{
emit layoutAboutToBeChanged();
_remove( value );
emit layoutChanged();
}
//! remove
virtual void remove( const List& values )
{
// check if not empty
// this avoids sending useless signals
if( values.empty() ) return;
emit layoutAboutToBeChanged();
for( typename List::const_iterator iter = values.begin(); iter != values.end(); iter++ )
{ _remove( *iter ); }
emit layoutChanged();
}
//! clear
virtual void clear()
{ set( List() ); }
//! update values from list
/*!
values that are not found in current are removed
new values are set to the end.
This is slower than the "set" method, but the selection is not cleared in the process
*/
virtual void update( List values )
{
emit layoutAboutToBeChanged();
// store values to be removed
List removed_values;
// update values that are common to both lists
for( typename List::iterator iter = _values.begin(); iter != _values.end(); iter++ )
{
// see if iterator is in list
typename List::iterator found_iter( std::find( values.begin(), values.end(), *iter ) );
if( found_iter == values.end() ) removed_values.push_back( *iter );
else {
*iter = *found_iter;
values.erase( found_iter );
}
}
// remove values that have not been found in new list
for( typename List::const_iterator iter = removed_values.constBegin(); iter != removed_values.constEnd(); iter++ )
{ _remove( *iter ); }
// add remaining values
for( typename List::const_iterator iter = values.constBegin(); iter != values.constEnd(); iter++ )
{ _add( *iter ); }
privateSort();
emit layoutChanged();
}
//! set all values
virtual void set( const List& values )
{
emit layoutAboutToBeChanged();
_values = values;
_selection.clear();
privateSort();
emit layoutChanged();
}
//! return all values
const List& get( void ) const
{ return _values; }
//! return value for given index
virtual ValueType get( const QModelIndex& index ) const
{ return (index.isValid() && index.row() < int(_values.size()) ) ? _values[index.row()]:ValueType(); }
//! return value for given index
virtual ValueType& get( const QModelIndex& index )
{
Q_ASSERT( index.isValid() && index.row() < int( _values.size() ) );
return _values[index.row()];
}
//! return all values
List get( const QModelIndexList& indexes ) const
{
List out;
for( QModelIndexList::const_iterator iter = indexes.begin(); iter != indexes.end(); iter++ )
{ if( iter->isValid() && iter->row() < int(_values.size()) ) out.push_back( get( *iter ) ); }
return out;
}
//! return index associated to a given value
virtual QModelIndex index( const ValueType& value, int column = 0 ) const
{
for( int row = 0; row < _values.size(); ++row )
{ if( value == _values[row] ) return index( row, column ); }
return QModelIndex();
}
//@}
//! return true if model contains given index
virtual bool contains( const QModelIndex& index ) const
{ return index.isValid() && index.row() < _values.size(); }
protected:
//! return all values
List& _get( void )
{ return _values; }
//! add, without update
virtual void _add( const ValueType& value )
{
typename List::iterator iter = std::find( _values.begin(), _values.end(), value );
if( iter == _values.end() ) _values.push_back( value );
else *iter = value;
}
//! add, without update
virtual void _insert( const QModelIndex& index, const ValueType& value )
{
if( !index.isValid() ) add( value );
int row = 0;
typename List::iterator iter( _values.begin() );
for( ;iter != _values.end() && row != index.row(); iter++, row++ )
{}
_values.insert( iter, value );
}
//! remove, without update
virtual void _remove( const ValueType& value )
{
_values.erase( std::remove( _values.begin(), _values.end(), value ), _values.end() );
_selection.erase( std::remove( _selection.begin(), _selection.end(), value ), _selection.end() );
}
private:
//! values
List _values;
//! selection
List _selection;
};
}
#endif
@@ -0,0 +1,341 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BreezeConfigurationUI</class>
<widget class="QWidget" name="BreezeConfigurationUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>428</width>
<height>418</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Tit&amp;le alignment:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>titleAlignment</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>B&amp;utton size:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>buttonSize</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="buttonSize">
<item>
<property name="text">
<string>Tiny</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Small</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Medium</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Very Large</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="titleAlignment">
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>Center</string>
</property>
</item>
<item>
<property name="text">
<string>Center (Full Width)</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="drawSizeGrip">
<property name="text">
<string>Add handle to resize windows with no border</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="3">
<widget class="QCheckBox" name="drawTitleBarSeparator">
<property name="text">
<string>Draw separator under active window's titlebar</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="drawBorderOnMaximizedWindows">
<property name="text">
<string>Allow resizing maximized windows from window edges</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="outlineCloseButton">
<property name="text">
<string>Draw a circle around close button</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="drawBackgroundGradient">
<property name="text">
<string>Draw titlebar background gradient</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
<string>Shadows</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Si&amp;ze:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>shadowSize</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="shadowSize">
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">None</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Small</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Medium</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Button size:">Very Large</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string comment="strength of the shadow (from transparent to opaque)">S&amp;trength:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>shadowStrength</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="shadowStrength">
<property name="suffix">
<string>%</string>
</property>
<property name="minimum">
<number>10</number>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Color:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KColorButton" name="shadowColor"/>
</item>
<item row="3" column="0" colspan="3">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>Window-Specific Overrides</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="Breeze::ExceptionListWidget" name="exceptions" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
</customwidget>
<customwidget>
<class>Breeze::ExceptionListWidget</class>
<extends>QWidget</extends>
<header>config/breezeexceptionlistwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>titleAlignment</tabstop>
<tabstop>buttonSize</tabstop>
<tabstop>outlineCloseButton</tabstop>
<tabstop>drawBorderOnMaximizedWindows</tabstop>
<tabstop>drawBackgroundGradient</tabstop>
<tabstop>drawSizeGrip</tabstop>
<tabstop>drawTitleBarSeparator</tabstop>
<tabstop>shadowSize</tabstop>
<tabstop>shadowStrength</tabstop>
<tabstop>shadowColor</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,146 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BreezeDetectWidget</class>
<widget class="QDialog" name="BreezeDetectWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>239</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Information about Selected Window</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Class: </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="windowClass">
<property name="text">
<string notr="true">TextLabel</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Title: </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="windowTitle">
<property name="text">
<string notr="true">TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Window Property Selection</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QRadioButton" name="windowClassCheckBox">
<property name="text">
<string>Use window class (whole application)</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="windowTitleCheckBox">
<property name="locale">
<locale language="French" country="France"/>
</property>
<property name="text">
<string>Use window title</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>BreezeDetectWidget</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>BreezeDetectWidget</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@@ -0,0 +1,231 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BreezeExceptionDialog</class>
<widget class="QDialog" name="BreezeExceptionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>362</width>
<height>321</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Window Identification</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;Matching window property: </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>exceptionType</cstring>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Regular expression &amp;to match: </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>exceptionEditor</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="detectDialogButton">
<property name="text">
<string>Detect Window Properties</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="exceptionEditor">
<property name="showClearButton" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="exceptionType">
<item>
<property name="text">
<string>Window Class Name</string>
</property>
</item>
<item>
<property name="text">
<string>Window Title</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Decoration Options</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="borderSizeCheckBox">
<property name="text">
<string>Border size:</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="hideTitleBar">
<property name="text">
<string>Hide window title bar</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="borderSizeComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">No Border</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">No Side Borders</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Tiny</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Normal</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Very Large</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Very Huge</string>
</property>
</item>
<item>
<property name="text">
<string comment="@item:inlistbox Border size:">Oversized</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>BreezeExceptionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>252</x>
<y>342</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>BreezeExceptionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>320</x>
<y>342</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>borderSizeCheckBox</sender>
<signal>toggled(bool)</signal>
<receiver>borderSizeComboBox</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>125</x>
<y>162</y>
</hint>
<hint type="destinationlabel">
<x>316</x>
<y>163</y>
</hint>
</hints>
</connection>
</connections>
</ui>
@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BreezeExceptionListWidget</class>
<widget class="QWidget" name="BreezeExceptionListWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>473</width>
<height>182</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0" rowspan="6">
<widget class="QTreeView" name="exceptionListView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>100</height>
</size>
</property>
</widget>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="moveUpButton">
<property name="text">
<string>Move Up</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="moveDownButton">
<property name="text">
<string>Move Down</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit</string>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>exceptionListView</tabstop>
<tabstop>moveUpButton</tabstop>
<tabstop>moveDownButton</tabstop>
<tabstop>addButton</tabstop>
<tabstop>removeButton</tabstop>
<tabstop>editButton</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>