diff --git a/CMakeLists.txt b/CMakeLists.txt index cd53c1dd..6eb4ce2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,103 +1,103 @@ project(oxygen) set(PROJECT_VERSION "5.16.80") set(PROJECT_VERSION_MAJOR 5) cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) include(GenerateExportHeader) include(WriteBasicConfigVersionFile) include(FeatureSummary) set(OXYGEN_USE_KDE4 ${USE_KDE4}) if(OXYGEN_USE_KDE4) ############ Language and toolchain features ############ copied from ECM if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel" AND NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") endif() endif() ################# Qt/KDE ################# if(OXYGEN_USE_KDE4) find_package(KDE4 REQUIRED) include(KDE4Defaults) include(MacroLibrary) add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) include_directories(${KDE4_INCLUDES}) ### XCB find_package(PkgConfig) pkg_check_modules(XCB xcb x11-xcb) add_feature_info("x11-xcb" XCB_FOUND "Required to pass style properties to native Windows on X11 Platform") set_feature_info("x11-xcb" "Required to pass style properties to native Windows on X11 Platform" "http://xcb.freedesktop.org") set(OXYGEN_HAVE_X11 ${XCB_FOUND}) set(OXYGEN_HAVE_KWAYLAND FALSE) add_subdirectory(liboxygen) add_subdirectory(kstyle) else() find_package(ECM 0.0.9 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR}) find_package(Qt5 REQUIRED CONFIG COMPONENTS Widgets DBus Quick) find_package(KF5 REQUIRED COMPONENTS I18n Config GuiAddons WidgetsAddons Service Completion FrameworkIntegration WindowSystem) find_package(XCB COMPONENTS XCB) set_package_properties(XCB PROPERTIES DESCRIPTION "X protocol C-language Binding" URL "http://xcb.freedesktop.org" TYPE OPTIONAL PURPOSE "Required to pass style properties to native Windows on X11 Platform" ) find_package(KF5Wayland CONFIG) set(OXYGEN_HAVE_KWAYLAND ${KF5Wayland_FOUND}) if(NOT APPLE) set(OXYGEN_HAVE_X11 ${XCB_XCB_FOUND}) if (XCB_XCB_FOUND) find_package(Qt5 REQUIRED CONFIG COMPONENTS X11Extras) endif() endif() include(ECMInstallIcons) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) add_subdirectory(liboxygen) add_subdirectory(kstyle) - add_subdirectory(color-schemes) + add_subdirectory(color-schemes) add_subdirectory(cursors) add_subdirectory(sounds) add_subdirectory(kdecoration) install(DIRECTORY lookandfeel/ DESTINATION ${KDE_INSTALL_DATADIR}/plasma/look-and-feel/org.kde.oxygen PATTERN "Messages.sh" EXCLUDE PATTERN "CMakeLists.txt" EXCLUDE) # po/ dir added by packaging scripts if(EXISTS ${CMAKE_SOURCE_DIR}/po AND IS_DIRECTORY ${CMAKE_SOURCE_DIR}/po) find_package(KF5I18n CONFIG REQUIRED) ki18n_install(po) endif() endif() feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/kdecoration/config/oxygenanimationconfigwidget.h b/kdecoration/config/oxygenanimationconfigwidget.h index 4fe4cffd..3e3d880d 100644 --- a/kdecoration/config/oxygenanimationconfigwidget.h +++ b/kdecoration/config/oxygenanimationconfigwidget.h @@ -1,85 +1,82 @@ #ifndef oxygenanimationconfigwidget_h #define oxygenanimationconfigwidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenanimationconfigwidget.h // animation configuration item // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseanimationconfigwidget.h" #include "oxygen.h" namespace Oxygen { // forward declaration class GenericAnimationConfigItem; //* container to configure animations individually class AnimationConfigWidget: public BaseAnimationConfigWidget { Q_OBJECT public: //* constructor explicit AnimationConfigWidget( QWidget* = nullptr ); - //* destructor - virtual ~AnimationConfigWidget( void ) = default; - //* configuration void setInternalSettings( InternalSettingsPtr internalSettings ) { m_internalSettings = internalSettings; } public Q_SLOTS: //* read current configuration void load( void ) override; //* save current configuration void save( void ) override; protected Q_SLOTS: //* check whether configuration is changed and emit appropriate signal if yes void updateChanged() override; private: //* internal exception InternalSettingsPtr m_internalSettings; //*@name animations //@{ GenericAnimationConfigItem* m_buttonAnimations = nullptr; GenericAnimationConfigItem* m_shadowAnimations = nullptr; //@} }; } #endif diff --git a/kdecoration/config/oxygenconfigwidget.h b/kdecoration/config/oxygenconfigwidget.h index d9d7ae58..86dc0853 100644 --- a/kdecoration/config/oxygenconfigwidget.h +++ b/kdecoration/config/oxygenconfigwidget.h @@ -1,106 +1,101 @@ #ifndef oxygenconfigwidget_h #define oxygenconfigwidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenconfigurationui.h // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "ui_oxygenconfigurationui.h" #include "oxygenexceptionlistwidget.h" #include "oxygensettings.h" #include "oxygenshadowconfigwidget.h" #include "oxygen.h" #include #include #include #include namespace Oxygen { //_____________________________________________ class ConfigWidget: public KCModule { Q_OBJECT public: //* constructor explicit ConfigWidget( QWidget*, const QVariantList& ); - //* destructor - virtual ~ConfigWidget( void ) = default; - //* default void defaults() override; //* load configuration void load( void ) override; //* save configuration void save( void ) override; //* true if changed - virtual bool isChanged( void ) const + bool isChanged( void ) const { return m_changed; } //* exceptions ExceptionListWidget* exceptionListWidget( void ) const { return m_ui.exceptions; } - protected Q_SLOTS: + private Q_SLOTS: //* update changed state - virtual void updateChanged(); + void updateChanged(); - protected: + private: //* set changed state - virtual void setChanged( bool value ) + void setChanged( bool value ) { m_changed = value; emit changed( value ); } - private: - //* ui Ui_OxygenConfigurationUI m_ui; //* kconfiguration object KSharedConfig::Ptr m_configuration; //* internal exception InternalSettingsPtr m_internalSettings; //* changed state - bool m_changed; + bool m_changed = false; }; } #endif diff --git a/kdecoration/config/oxygendetectwidget.cpp b/kdecoration/config/oxygendetectwidget.cpp index 6faf9c8d..e2efd16e 100644 --- a/kdecoration/config/oxygendetectwidget.cpp +++ b/kdecoration/config/oxygendetectwidget.cpp @@ -1,185 +1,184 @@ ////////////////////////////////////////////////////////////////////////////// // oxygendetectwidget.cpp // Note: this class is a stripped down version of // /kdebase/workspace/kwin/kcmkwin/kwinrules/detectwidget.cpp // Copyright (c) 2004 Lubos Lunak // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygendetectwidget.h" -#include "oxygendetectwidget.moc" #include "oxygen.h" #include #include #include #include #if OXYGEN_HAVE_X11 #include #include #endif namespace Oxygen { //_________________________________________________________ DetectDialog::DetectDialog( QWidget* parent ): QDialog( parent ) { // setup m_ui.setupUi( this ); connect( m_ui.buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL(clicked()), this, SLOT(close()) ); m_ui.windowClassCheckBox->setChecked( true ); #if OXYGEN_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 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 ); return; } //_________________________________________________________ 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( 0, 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 explicitely release cursor for Qt5 qApp->restoreOverrideCursor(); // delete old m_grabber delete m_grabber; m_grabber = 0; // check button if( static_cast< QMouseEvent* >( e )->button() != Qt::LeftButton ) return true; // read window information readWindow( findWindow() ); return true; } //_________________________________________________________ WId DetectDialog::findWindow() { #if OXYGEN_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 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 reply( xcb_get_property_reply( connection, cookie, nullptr ) ); if( reply && reply->type ) return child; else parent = child; } #endif return 0; } } diff --git a/kdecoration/config/oxygenexceptiondialog.cpp b/kdecoration/config/oxygenexceptiondialog.cpp index 69ea7343..9d5d41dd 100644 --- a/kdecoration/config/oxygenexceptiondialog.cpp +++ b/kdecoration/config/oxygenexceptiondialog.cpp @@ -1,185 +1,184 @@ ////////////////////////////////////////////////////////////////////////////// // oxygenexceptiondialog.cpp // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenexceptiondialog.h" -#include "oxygenexceptiondialog.moc" #include "oxygendetectwidget.h" #include "config-oxygen.h" #if OXYGEN_HAVE_X11 #include #endif namespace Oxygen { //___________________________________________ ExceptionDialog::ExceptionDialog( QWidget* parent ): QDialog( parent ) { m_ui.setupUi( this ); connect( m_ui.buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL(clicked()), this, SLOT(close()) ); // store checkboxes from ui into list m_checkboxes.insert( BorderSize, m_ui.borderSizeCheckBox ); // detect window properties connect( m_ui.detectDialogButton, SIGNAL(clicked()), SLOT(selectWindowProperties()) ); // connections connect( m_ui.exceptionType, SIGNAL(currentIndexChanged(int)), SLOT(updateChanged()) ); connect( m_ui.exceptionEditor, SIGNAL(textChanged(QString)), SLOT(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(), SIGNAL(clicked()), SLOT(updateChanged()) ); } connect( m_ui.hideTitleBar, SIGNAL(clicked()), SLOT(updateChanged()) ); // hide detection dialog on non X11 platforms #if OXYGEN_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( void ) { 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( void ) { 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( void ) { // create widget if( !m_detectDialog ) { m_detectDialog = new DetectDialog( this ); connect( m_detectDialog, SIGNAL(detectionDone(bool)), SLOT(readWindowProperties(bool)) ); } 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 = 0; } } diff --git a/kdecoration/config/oxygenexceptiondialog.h b/kdecoration/config/oxygenexceptiondialog.h index 26c20070..8c1739ee 100644 --- a/kdecoration/config/oxygenexceptiondialog.h +++ b/kdecoration/config/oxygenexceptiondialog.h @@ -1,114 +1,108 @@ #ifndef oxygenexceptiondialog_h #define oxygenexceptiondialog_h ////////////////////////////////////////////////////////////////////////////// // oxygenexceptiondialog.h // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "ui_oxygenexceptiondialog.h" #include "oxygen.h" #include #include namespace Oxygen { class DetectDialog; //* oxygen exceptions list class ExceptionDialog: public QDialog { Q_OBJECT public: //* constructor explicit ExceptionDialog( QWidget* parent ); - //* destructor - virtual ~ExceptionDialog( void ) - {} - //* set exception void setException( InternalSettingsPtr ); //* save exception void save( void ); //* true if changed - virtual bool isChanged( void ) const + bool isChanged( void ) const { return m_changed; } Q_SIGNALS: //* emmited when changed void changed( bool ); protected: //* set changed state - virtual void setChanged( bool value ) + void setChanged( bool value ) { m_changed = value; emit changed( value ); } - protected Q_SLOTS: + private Q_SLOTS: //* check whether configuration is changed and emit appropriate signal if yes - virtual void updateChanged(); - - private Q_SLOTS: + void updateChanged(); //* select window properties from grabbed pointers void selectWindowProperties( void ); //* read properties of selected window void readWindowProperties( bool ); private: //* map mask and checkbox using CheckBoxMap=QMap< ExceptionMask, QCheckBox*>; Ui::OxygenExceptionDialog 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 diff --git a/kdecoration/config/oxygenexceptionlistwidget.cpp b/kdecoration/config/oxygenexceptionlistwidget.cpp index 67db275a..efbdfa9f 100644 --- a/kdecoration/config/oxygenexceptionlistwidget.cpp +++ b/kdecoration/config/oxygenexceptionlistwidget.cpp @@ -1,356 +1,355 @@ ////////////////////////////////////////////////////////////////////////////// // oxygenexceptionlistwidget.cpp // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenexceptionlistwidget.h" -#include "oxygenexceptionlistwidget.moc" #include "oxygenexceptiondialog.h" #include #include #include #include //__________________________________________________________ namespace Oxygen { //__________________________________________________________ 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 ); 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, SIGNAL(clicked()), SLOT(add()) ); connect( m_ui.editButton, SIGNAL(clicked()), SLOT(edit()) ); connect( m_ui.removeButton, SIGNAL(clicked()), SLOT(remove()) ); connect( m_ui.moveUpButton, SIGNAL(clicked()), SLOT(up()) ); connect( m_ui.moveDownButton, SIGNAL(clicked()), SLOT(down()) ); connect( m_ui.exceptionListView, SIGNAL(activated(QModelIndex)), SLOT(edit()) ); connect( m_ui.exceptionListView, SIGNAL(clicked(QModelIndex)), SLOT(toggle(QModelIndex)) ); connect( m_ui.exceptionListView->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(updateButtons()) ); updateButtons(); resizeColumns(); } //__________________________________________________________ void ExceptionListWidget::setExceptions( const InternalSettingsList& exceptions ) { model().set( exceptions ); resizeColumns(); setChanged( false ); } //__________________________________________________________ InternalSettingsList ExceptionListWidget::exceptions( void ) { return model().get(); setChanged( false ); } //__________________________________________________________ void ExceptionListWidget::updateButtons( void ) { 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( void ) { QPointer dialog = new ExceptionDialog( this ); dialog->setWindowTitle( i18n( "New Exception - Oxygen 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(); return; } //_______________________________________________________ void ExceptionListWidget::edit( void ) { // retrieve selection QModelIndex current( m_ui.exceptionListView->selectionModel()->currentIndex() ); if( ! model().contains( current ) ) return; InternalSettingsPtr exception( model().get( current ) ); // create dialog QPointer dialog( new ExceptionDialog( this ) ); dialog->setWindowTitle( i18n( "Edit Exception - Oxygen 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 ); return; } //_______________________________________________________ void ExceptionListWidget::remove( void ) { // confirmation dialog { QMessageBox messageBox( QMessageBox::Question, i18n("Question - Oxygen 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 ); return; } //_______________________________________________________ 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 ); return; } //_______________________________________________________ void ExceptionListWidget::up( void ) { 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 ); return; } //_______________________________________________________ void ExceptionListWidget::down( void ) { 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 ); return; } //_______________________________________________________ void ExceptionListWidget::resizeColumns( void ) 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 - Oxygen Settings" ), i18n("Regular Expression syntax is incorrect") ); QPointer dialog( new ExceptionDialog( this ) ); dialog->setException( exception ); if( dialog->exec() == QDialog::Rejected ) { delete dialog; return false; } dialog->save(); delete dialog; } return true; } } diff --git a/kdecoration/config/oxygenexceptionlistwidget.h b/kdecoration/config/oxygenexceptionlistwidget.h index cefbc30a..3d6fafcc 100644 --- a/kdecoration/config/oxygenexceptionlistwidget.h +++ b/kdecoration/config/oxygenexceptionlistwidget.h @@ -1,124 +1,120 @@ #ifndef oxygenexceptionlistwidget_h #define oxygenexceptionlistwidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenexceptionlistwidget.h // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "ui_oxygenexceptionlistwidget.h" #include "oxygenexceptionmodel.h" //* QDialog used to commit selected files namespace Oxygen { class ExceptionListWidget: public QWidget { //* Qt meta object Q_OBJECT public: //* constructor - explicit ExceptionListWidget( QWidget* = 0 ); + explicit ExceptionListWidget( QWidget* = nullptr ); //* set exceptions void setExceptions( const InternalSettingsList& ); //* get exceptions InternalSettingsList exceptions( void ); //* true if changed - virtual bool isChanged( void ) const + bool isChanged( void ) 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: + private Q_SLOTS: //* update button states - virtual void updateButtons( void ); + void updateButtons( void ); //* add - virtual void add( void ); + void add( void ); //* edit - virtual void edit( void ); + void edit( void ); //* remove - virtual void remove( void ); + void remove( void ); //* toggle - virtual void toggle( const QModelIndex& ); + void toggle( const QModelIndex& ); //* move up - virtual void up( void ); + void up( void ); //* move down - virtual void down( void ); + void down( void ); - protected: + private: //* resize columns void resizeColumns( void ) const; //* check exception bool checkException( InternalSettingsPtr ); //* set changed state virtual void setChanged( bool value ) { m_changed = value; emit changed( value ); } - private: + //* model + const ExceptionModel& model() const + { return m_model; } + + //* model + ExceptionModel& model() + { return m_model; } //* model ExceptionModel m_model; //* ui Ui_OxygenExceptionListWidget m_ui; //* changed state bool m_changed = false; }; } #endif diff --git a/kdecoration/config/oxygenitemmodel.h b/kdecoration/config/oxygenitemmodel.h index bbc5a671..38869ce1 100644 --- a/kdecoration/config/oxygenitemmodel.h +++ b/kdecoration/config/oxygenitemmodel.h @@ -1,113 +1,109 @@ #ifndef ItemModel_h #define ItemModel_h ////////////////////////////////////////////////////////////////////////////// // itemmodel.h // ------------------- // // Copyright (c) 2009-2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include namespace Oxygen { //* Job model. Stores job information for display in lists class ItemModel : public QAbstractItemModel { public: //* constructor explicit ItemModel(QObject *parent = 0); - //* 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( void ) { sort( sortColumn(), sortOrder() ); } //* sort void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override; //* current sorting column const int& sortColumn( void ) const { return m_sortColumn; } //* current sort order const Qt::SortOrder& sortOrder( void ) const { return m_sortOrder; } //@} protected: //* this sort columns without calling the layout changed callbacks void privateSort( void ) { privateSort( m_sortColumn, m_sortOrder ); } //* private sort, with no signals emmitted 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 diff --git a/kdecoration/oxygenbutton.h b/kdecoration/oxygenbutton.h index 2506d271..b929c78c 100644 --- a/kdecoration/oxygenbutton.h +++ b/kdecoration/oxygenbutton.h @@ -1,182 +1,179 @@ #ifndef oxygenbutton_h #define oxygenbutton_h /* * Copyright 2006, 2007 Riccardo Iaconelli * Copyright 2006, 2007 Casper Boemann * Copyright 2009 Hugo Pereira Da Costa * Copyright 2015 David Edmundson * * This program 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 . */ #include "oxygenanimation.h" #include "oxygen.h" #include "oxygendecohelper.h" #include "oxygendecoration.h" #include namespace Oxygen { class Button : public KDecoration2::DecorationButton { Q_OBJECT //* declare active state opacity Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) public: //* constructor explicit Button(QObject *parent, const QVariantList &args); - //* destructor - virtual ~Button() = default; - //* button creation static Button *create(KDecoration2::DecorationButtonType type, KDecoration2::Decoration *decoration, QObject *parent); //* render - virtual void paint(QPainter *painter, const QRect &repaintRegion) override; + void paint(QPainter *painter, const QRect &repaintRegion) override; //* flag enum Flag { FlagNone, FlagStandalone, FlagFirstInList, FlagLastInList }; //* flag void setFlag( Flag value ) { m_flag = value; } //* standalone buttons bool isStandAlone() const { return m_flag == FlagStandalone; } //* offset void setOffset( const QPointF& value ) { m_offset = value; } //* horizontal offset, for rendering void setHorizontalOffset( qreal value ) { m_offset.setX( value ); } //* vertical offset, for rendering void setVerticalOffset( qreal value ) { m_offset.setY( value ); } //* set icon size void setIconSize( const QSize& value ) { m_iconSize = value; } //*@name active state change animation //@{ void setOpacity( qreal value ) { if( m_opacity == value ) return; m_opacity = value; update(); } qreal opacity( void ) const { return m_opacity; } //@} protected: //* draw icon void drawIcon( QPainter* ); //*@name colors //@{ QColor foregroundColor( const QPalette& ) const; QColor foregroundColor( const QPalette& palette, bool active ) const; QColor backgroundColor( const QPalette& ) const; QColor backgroundColor( const QPalette& palette, bool active ) const; //@} //* true if animation is in progress bool isAnimated( void ) const { return m_animation->state() == QPropertyAnimation::Running; } //* true if button is active bool isActive( void ) const; //*@name button properties //@{ - //! true if button if of menu type + //* true if button if of menu type bool isMenuButton( void ) const { return type() == KDecoration2::DecorationButtonType::Menu || type() == KDecoration2::DecorationButtonType::ApplicationMenu; } - //! true if button is of toggle type + //* true if button is of toggle type bool isToggleButton( void ) const { return type() == KDecoration2::DecorationButtonType::OnAllDesktops || type() == KDecoration2::DecorationButtonType::KeepAbove || type() == KDecoration2::DecorationButtonType::KeepBelow; } - //! true if button if of close type + //* true if button if of close type bool isCloseButton( void ) const { return type() == KDecoration2::DecorationButtonType::Close; } - //! true if button has decoration + //* true if button has decoration bool hasDecoration( void ) const { return !isMenuButton();} //@} private Q_SLOTS: //* apply configuration changes void reconfigure(); //* animation state void updateAnimationState(bool); private: //* private constructor explicit Button(KDecoration2::DecorationButtonType type, Decoration *decoration, QObject *parent); Flag m_flag = FlagNone; //* glow animation QPropertyAnimation* m_animation; //* vertical offset (for rendering) QPointF m_offset; //* icon size QSize m_iconSize; //* glow intensity qreal m_opacity; }; } //namespace #endif diff --git a/kdecoration/oxygendecohelper.h b/kdecoration/oxygendecohelper.h index 16562b93..ae391ebf 100644 --- a/kdecoration/oxygendecohelper.h +++ b/kdecoration/oxygendecohelper.h @@ -1,61 +1,57 @@ #ifndef oxygendecohelper_h #define oxygendecohelper_h /* * Copyright 2013 Hugo Pereira Da Costa * Copyright 2008 Long Huynh Huu * Copyright 2007 Matthew Woehlke * Copyright 2007 Casper Boemann * Copyright 2015 David Edmundson * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "oxygenhelper.h" #include //* helper class /*! contains utility functions used at multiple places in oxygen style */ namespace Oxygen { class DecoHelper : public Helper { public: //* constructor explicit DecoHelper(); - //* destructor - virtual ~DecoHelper() - {} - //* reset all caches void invalidateCaches() override; //* windeco buttons - virtual QPixmap windecoButton(const QColor &color, const QColor& glow, bool sunken, int size = 21); + QPixmap windecoButton(const QColor &color, const QColor& glow, bool sunken, int size = 21); private: //* windeco buttons Cache _windecoButtonCache; }; } #endif // __OXYGEN_STYLE_HELPER_H diff --git a/kdecoration/oxygendecoration.h b/kdecoration/oxygendecoration.h index e0cbc592..7509de55 100644 --- a/kdecoration/oxygendecoration.h +++ b/kdecoration/oxygendecoration.h @@ -1,192 +1,192 @@ #ifndef OXYGEN_DECORATION_H #define OXYGEN_DECORATION_H /* * Copyright 2014 Martin Gräßlin * Copyright 2014 Hugo Pereira Da Costa * Copyright 2015 David Edmundson * * This program 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) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program 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 . */ #include "oxygen.h" #include "oxygensettings.h" #include #include #include #include #include #include namespace KDecoration2 { class DecorationButton; class DecorationButtonGroup; } namespace Oxygen { class SizeGrip; class Decoration : public KDecoration2::Decoration { Q_OBJECT //* declare active state opacity Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) public: //* constructor explicit Decoration(QObject *parent = nullptr, const QVariantList &args = QVariantList()); //* destructor - virtual ~Decoration(); + ~Decoration() override; //* paint void paint(QPainter *painter, const QRect &repaintRegion) override; //* internal settings InternalSettingsPtr internalSettings() const { return m_internalSettings; } //* caption height int captionHeight() const; //* button height int buttonHeight() const; //*@name active state change animation //@{ bool isAnimated( void ) const { return m_animation->state() == QPropertyAnimation::Running; } void setOpacity( qreal ); qreal opacity( void ) const { return m_opacity; } //@} //*@name colors //@{ QColor titleBarColor(const QPalette&) const; QColor titleBarColor(const QPalette&, bool active) const; QColor fontColor(const QPalette&) const; QColor fontColor(const QPalette& palette, bool active ) const; QColor contrastColor(const QPalette& palette ) const; QColor contrastColor(const QColor& color ) const; //@} public Q_SLOTS: void init() override; private Q_SLOTS: void reconfigure(); void recalculateBorders(); void updateButtonsGeometry(); void updateButtonsGeometryDelayed(); void updateTitleBar(); void updateAnimationState(); void updateSizeGripVisibility(); void updateShadow(); private: //* return the rect in which caption will be drawn QPair captionRect( void ) const; void createButtons(); //* window background void renderWindowBackground( QPainter*, const QRect&, const QPalette& ) const; //* window border void renderWindowBorder( QPainter*, const QRect&, const QPalette& ) const; //* title text void renderTitleText( QPainter*, const QPalette& ) const; //* corners void renderCorners( QPainter*, const QRect&, const QPalette& ) const; //*@name border size //@{ int borderSize(bool bottom = false) const; inline bool hasNoBorders( void ) const; inline bool hasNoSideBorders( void ) const; //@} //*@name maximization modes //@{ inline bool isMaximized( void ) const; inline bool isMaximizedHorizontally( void ) const; inline bool isMaximizedVertically( void ) const; inline bool hideTitleBar( void ) const; //@} //*@name size grip //@{ void createSizeGrip( void ); void deleteSizeGrip( void ); SizeGrip* sizeGrip( void ) const { return m_sizeGrip; } //@} InternalSettingsPtr m_internalSettings; QList m_buttons; KDecoration2::DecorationButtonGroup *m_leftButtons = nullptr; KDecoration2::DecorationButtonGroup *m_rightButtons = nullptr; //* size grip widget SizeGrip *m_sizeGrip = nullptr; //* active state change animation QPropertyAnimation *m_animation; //* active state change opacity qreal m_opacity = 0; }; bool Decoration::hasNoBorders( void ) const { if( m_internalSettings && m_internalSettings->mask() & BorderSize ) return m_internalSettings->borderSize() == InternalSettings::BorderNone; else return settings()->borderSize() == KDecoration2::BorderSize::None; } bool Decoration::hasNoSideBorders( void ) const { if( m_internalSettings && m_internalSettings->mask() & BorderSize ) return m_internalSettings->borderSize() == InternalSettings::BorderNoSides; else return settings()->borderSize() == KDecoration2::BorderSize::NoSides; } bool Decoration::isMaximized( void ) const { return client().data()->isMaximized() && !m_internalSettings->drawBorderOnMaximizedWindows(); } bool Decoration::isMaximizedHorizontally( void ) const { return client().data()->isMaximizedHorizontally() && !m_internalSettings->drawBorderOnMaximizedWindows(); } bool Decoration::isMaximizedVertically( void ) const { return client().data()->isMaximizedVertically() && !m_internalSettings->drawBorderOnMaximizedWindows(); } bool Decoration::hideTitleBar( void ) const { return m_internalSettings->hideTitleBar() && !client().data()->isShaded(); } } #endif diff --git a/kdecoration/oxygenexceptionlist.h b/kdecoration/oxygenexceptionlist.h index 57a6be0f..e6d61acd 100644 --- a/kdecoration/oxygenexceptionlist.h +++ b/kdecoration/oxygenexceptionlist.h @@ -1,79 +1,79 @@ #ifndef oxygenexceptionlist_h #define oxygenexceptionlist_h ////////////////////////////////////////////////////////////////////////////// // oxygenexceptionlist.h // window decoration exceptions // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygensettings.h" #include "oxygen.h" #include namespace Oxygen { - //! oxygen exceptions list + //* oxygen exceptions list class ExceptionList { public: - //! constructor from list + //* constructor from list explicit ExceptionList( const InternalSettingsList& exceptions = InternalSettingsList() ): _exceptions( exceptions ) {} - //! exceptions + //* exceptions const InternalSettingsList& get( void ) const { return _exceptions; } - //! read from KConfig + //* read from KConfig void readConfig( KSharedConfig::Ptr ); - //! write to kconfig + //* write to kconfig void writeConfig( KSharedConfig::Ptr ); protected: - //! generate exception group name for given exception index + //* generate exception group name for given exception index static QString exceptionGroupName( int index ); - //! read configuration + //* read configuration static void readConfig( KCoreConfigSkeleton*, KConfig*, const QString& ); - //! write configuration + //* write configuration static void writeConfig( KCoreConfigSkeleton*, KConfig*, const QString& ); private: - //! exceptions + //* exceptions InternalSettingsList _exceptions; }; } #endif diff --git a/kdecoration/oxygensizegrip.cpp b/kdecoration/oxygensizegrip.cpp index b99f4e86..a9513b02 100644 --- a/kdecoration/oxygensizegrip.cpp +++ b/kdecoration/oxygensizegrip.cpp @@ -1,310 +1,305 @@ /************************************************************************* * Copyright (C) 2014 by Hugo Pereira Da Costa * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ #include "oxygensizegrip.h" -#include "oxygensizegrip.moc" #include #include #include #include #include #if OXYGEN_HAVE_X11 #include #endif namespace Oxygen { //* scoped pointer convenience typedef template using ScopedPointer = QScopedPointer; //_____________________________________________ SizeGrip::SizeGrip( Decoration* decoration ):QWidget(nullptr) ,m_decoration( decoration ) { setAttribute(Qt::WA_NoSystemBackground ); setAutoFillBackground( false ); // cursor setCursor( Qt::SizeFDiagCursor ); // size setFixedSize( QSize( GripSize, GripSize ) ); // mask QPolygon p; p << QPoint( 0, GripSize ) << QPoint( GripSize, 0 ) << QPoint( GripSize, GripSize ) << QPoint( 0, GripSize ); setMask( QRegion( p ) ); // embed embed(); updatePosition(); // connections auto c = decoration->client().data(); connect( c, &KDecoration2::DecoratedClient::widthChanged, this, &SizeGrip::updatePosition ); connect( c, &KDecoration2::DecoratedClient::heightChanged, this, &SizeGrip::updatePosition ); connect( c, &KDecoration2::DecoratedClient::activeChanged, this, &SizeGrip::updateActiveState ); // show show(); } - //_____________________________________________ - SizeGrip::~SizeGrip( void ) - {} - //_____________________________________________ void SizeGrip::updateActiveState( void ) { #if OXYGEN_HAVE_X11 if( QX11Info::isPlatformX11() ) { const quint32 value = XCB_STACK_MODE_ABOVE; xcb_configure_window( QX11Info::connection(), winId(), XCB_CONFIG_WINDOW_STACK_MODE, &value ); xcb_map_window( QX11Info::connection(), winId() ); } #endif update(); } //_____________________________________________ void SizeGrip::embed( void ) { #if OXYGEN_HAVE_X11 if( !QX11Info::isPlatformX11() ) return; auto c = m_decoration.data()->client().data(); xcb_window_t windowId = c->windowId(); if( windowId ) { /* find client's parent we want the size grip to be at the same level as the client in the stack */ xcb_window_t current = windowId; auto connection = QX11Info::connection(); xcb_query_tree_cookie_t cookie = xcb_query_tree_unchecked( connection, current ); ScopedPointer tree(xcb_query_tree_reply( connection, cookie, nullptr ) ); if( !tree.isNull() && tree->parent ) current = tree->parent; // reparent xcb_reparent_window( connection, winId(), current, 0, 0 ); setWindowTitle( "Oxygen::SizeGrip" ); } else { hide(); } #endif } //_____________________________________________ void SizeGrip::paintEvent( QPaintEvent* ) { if( !m_decoration ) return; // get relevant colors const QColor backgroundColor( m_decoration->client().data()->palette().color(QPalette::Window) ); // create and configure painter QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing ); painter.setPen( Qt::NoPen ); painter.setBrush( backgroundColor ); // polygon QPolygon p; p << QPoint( 0, GripSize ) << QPoint( GripSize, 0 ) << QPoint( GripSize, GripSize ) << QPoint( 0, GripSize ); painter.drawPolygon( p ); } //_____________________________________________ void SizeGrip::mousePressEvent( QMouseEvent* event ) { switch (event->button()) { case Qt::RightButton: { hide(); QTimer::singleShot(5000, this, SLOT(show())); break; } case Qt::MidButton: { hide(); break; } case Qt::LeftButton: if( rect().contains( event->pos() ) ) { sendMoveResizeEvent( event->pos() ); } break; default: break; } return; } //_______________________________________________________________________________ void SizeGrip::updatePosition( void ) { #if OXYGEN_HAVE_X11 if( !QX11Info::isPlatformX11() ) return; auto c = m_decoration.data()->client().data(); QPoint position( c->width() - GripSize - Offset, c->height() - GripSize - Offset ); quint32 values[2] = { quint32(position.x()), quint32(position.y()) }; xcb_configure_window( QX11Info::connection(), winId(), XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values ); #endif } //_____________________________________________ void SizeGrip::sendMoveResizeEvent( QPoint position ) { #if OXYGEN_HAVE_X11 if( !QX11Info::isPlatformX11() ) return; // pointer to connection auto connection( QX11Info::connection() ); // client auto c = m_decoration.data()->client().data(); /* get root position matching position need to use xcb because the embedding of the widget breaks QT's mapToGlobal and other methods */ QPoint rootPosition( position ); xcb_get_geometry_cookie_t cookie( xcb_get_geometry( connection, winId() ) ); ScopedPointer reply( xcb_get_geometry_reply( connection, cookie, 0x0 ) ); if( reply ) { // translate coordinates xcb_translate_coordinates_cookie_t coordCookie( xcb_translate_coordinates( connection, winId(), reply.data()->root, -reply.data()->border_width, -reply.data()->border_width ) ); ScopedPointer< xcb_translate_coordinates_reply_t> coordReply( xcb_translate_coordinates_reply( connection, coordCookie, 0x0 ) ); if( coordReply ) { rootPosition.rx() += coordReply.data()->dst_x; rootPosition.ry() += coordReply.data()->dst_y; } } // move/resize atom if( !m_moveResizeAtom ) { // create atom if not found const QString atomName( "_NET_WM_MOVERESIZE" ); xcb_intern_atom_cookie_t cookie( xcb_intern_atom( connection, false, atomName.size(), qPrintable( atomName ) ) ); ScopedPointer reply( xcb_intern_atom_reply( connection, cookie, 0x0 ) ); m_moveResizeAtom = reply ? reply->atom:0; } if( !m_moveResizeAtom ) return; // button release event xcb_button_release_event_t releaseEvent; memset(&releaseEvent, 0, sizeof(releaseEvent)); releaseEvent.response_type = XCB_BUTTON_RELEASE; releaseEvent.event = winId(); releaseEvent.child = XCB_WINDOW_NONE; releaseEvent.root = QX11Info::appRootWindow(); releaseEvent.event_x = position.x(); releaseEvent.event_y = position.y(); releaseEvent.root_x = rootPosition.x(); releaseEvent.root_y = rootPosition.y(); releaseEvent.detail = XCB_BUTTON_INDEX_1; releaseEvent.state = XCB_BUTTON_MASK_1; releaseEvent.time = XCB_CURRENT_TIME; releaseEvent.same_screen = true; xcb_send_event( connection, false, winId(), XCB_EVENT_MASK_BUTTON_RELEASE, reinterpret_cast(&releaseEvent)); xcb_ungrab_pointer( connection, XCB_TIME_CURRENT_TIME ); // move resize event xcb_client_message_event_t clientMessageEvent; memset(&clientMessageEvent, 0, sizeof(clientMessageEvent)); clientMessageEvent.response_type = XCB_CLIENT_MESSAGE; clientMessageEvent.type = m_moveResizeAtom; clientMessageEvent.format = 32; clientMessageEvent.window = c->windowId(); clientMessageEvent.data.data32[0] = rootPosition.x(); clientMessageEvent.data.data32[1] = rootPosition.y(); clientMessageEvent.data.data32[2] = 4; // bottom right clientMessageEvent.data.data32[3] = Qt::LeftButton; clientMessageEvent.data.data32[4] = 0; xcb_send_event( connection, false, QX11Info::appRootWindow(), XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT, reinterpret_cast(&clientMessageEvent) ); xcb_flush( connection ); #endif } } diff --git a/kdecoration/oxygensizegrip.h b/kdecoration/oxygensizegrip.h index f0176806..c4f1547a 100644 --- a/kdecoration/oxygensizegrip.h +++ b/kdecoration/oxygensizegrip.h @@ -1,100 +1,97 @@ #ifndef oxygensizegrip_h #define oxygensizegrip_h /************************************************************************* * Copyright (C) 2014 by Hugo Pereira Da Costa * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ #include "oxygendecoration.h" #include "config-oxygen.h" #include #include #include #include #if OXYGEN_HAVE_X11 #include #endif namespace Oxygen { //* implements size grip for all widgets class SizeGrip: public QWidget { Q_OBJECT public: //* constructor explicit SizeGrip( Decoration* ); - //* constructor - virtual ~SizeGrip( void ); - - protected Q_SLOTS: - - //* update background color - void updateActiveState( void ); - - //* update position - void updatePosition( void ); - - //* embed into parent widget - void embed( void ); - protected: //*@name event handlers //@{ //* paint - virtual void paintEvent( QPaintEvent* ) override; + void paintEvent( QPaintEvent* ) override; //* mouse press - virtual void mousePressEvent( QMouseEvent* ) override; + void mousePressEvent( QMouseEvent* ) override; //@} + private Q_SLOTS: + + //* update background color + void updateActiveState( void ); + + //* update position + void updatePosition( void ); + + //* embed into parent widget + void embed( void ); + private: //* send resize event void sendMoveResizeEvent( QPoint ); //* grip size enum { Offset = 0, GripSize = 14 }; //* decoration QPointer m_decoration; //* move/resize atom #if OXYGEN_HAVE_X11 xcb_atom_t m_moveResizeAtom = 0; #endif }; } #endif diff --git a/kstyle/animations/oxygenanimationdata.h b/kstyle/animations/oxygenanimationdata.h index a3faa59f..c9474f43 100644 --- a/kstyle/animations/oxygenanimationdata.h +++ b/kstyle/animations/oxygenanimationdata.h @@ -1,113 +1,119 @@ #ifndef oxygen_animationdata_h #define oxygen_animationdata_h ////////////////////////////////////////////////////////////////////////////// // oxygenanimationdata.h // base class data container needed for widget animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygen.h" #include "oxygenanimation.h" #include #include #include #include namespace Oxygen { - //! base class + //* base class class AnimationData: public QObject { Q_OBJECT public: - //! constructor + //* constructor AnimationData( QObject* parent, QWidget* target ): - QObject( parent ), - _target( target ), - _enabled( true ) - { Q_ASSERT( _target ); } - - //! destructor - virtual ~AnimationData( void ) + QObject( parent ), + _target( target ) {} - //! duration + //*@name accessors + //@{ + + //* enable state + virtual bool enabled( void ) const + { return _enabled; } + + //* target + const WeakPointer& target( void ) const + { return _target; } + + + //@} + + //*@name modifiers + //@{ + + //* duration virtual void setDuration( int ) = 0; - //! steps + //* steps static void setSteps( int value ) { _steps = value; } - //! enability - virtual bool enabled( void ) const - { return _enabled; } - - //! enability + //* enability virtual void setEnabled( bool value ) { _enabled = value; } - //! target - const WeakPointer& target( void ) const - { return _target; } + //@} - //! invalid opacity + //* invalid opacity static const qreal OpacityInvalid; protected: - //! setup animation + //* setup animation virtual void setupAnimation( const Animation::Pointer& animation, const QByteArray& property ); - //! apply step + //* apply step virtual qreal digitize( const qreal& value ) const { if( _steps > 0 ) return std::floor( value*_steps )/_steps; else return value; } - //! trigger target update + //* trigger target update virtual void setDirty( void ) const { if( _target ) _target.data()->update(); } private: - //! guarded target + //* guarded target WeakPointer _target; - //! enability - bool _enabled; + //* enability + bool _enabled = true; - //! steps + //* steps static int _steps; }; } #endif diff --git a/kstyle/animations/oxygenanimations.cpp b/kstyle/animations/oxygenanimations.cpp index 6b58d9da..6c386298 100644 --- a/kstyle/animations/oxygenanimations.cpp +++ b/kstyle/animations/oxygenanimations.cpp @@ -1,382 +1,382 @@ ////////////////////////////////////////////////////////////////////////////// // oxygenanimations.cpp // container for all animation engines // ------------------- // // Copyright (c) 2006, 2007 Riccardo Iaconelli // Copyright (c) 2006, 2007 Casper Boemann // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimations.h" #include "oxygenpropertynames.h" #include "oxygenstyleconfigdata.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Oxygen { //____________________________________________________________ Animations::Animations( QObject* parent ): QObject( parent ) { - _widgetEnabilityEngine = new WidgetStateEngine( this ); + _widgetEnableStateEngine = new WidgetStateEngine( this ); _spinBoxEngine = new SpinBoxEngine( this ); _comboBoxEngine = new WidgetStateEngine( this ); _toolButtonEngine = new WidgetStateEngine( this ); _toolBoxEngine = new ToolBoxEngine( this ); _busyIndicatorEngine = new BusyIndicatorEngine( this ); registerEngine( _dockSeparatorEngine = new DockSeparatorEngine( this ) ); registerEngine( _headerViewEngine = new HeaderViewEngine( this ) ); registerEngine( _widgetStateEngine = new WidgetStateEngine( this ) ); registerEngine( _progressBarEngine = new ProgressBarEngine( this ) ); registerEngine( _menuBarEngine = new MenuBarEngineV1( this ) ); registerEngine( _menuEngine = new MenuEngineV1( this ) ); registerEngine( _scrollBarEngine = new ScrollBarEngine( this ) ); registerEngine( _inputWidgetEngine = new WidgetStateEngine( this ) ); registerEngine( _splitterEngine = new SplitterEngine( this ) ); registerEngine( _tabBarEngine = new TabBarEngine( this ) ); registerEngine( _toolBarEngine = new ToolBarEngine( this ) ); registerEngine( _mdiWindowEngine = new MdiWindowEngine( this ) ); } //____________________________________________________________ void Animations::setupEngines( void ) { // animation steps AnimationData::setSteps( StyleConfigData::animationSteps() ); { // default enability, duration and maxFrame bool animationsEnabled( StyleConfigData::animationsEnabled() ); // enability - _widgetEnabilityEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); + _widgetEnableStateEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _widgetStateEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _inputWidgetEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _comboBoxEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _toolButtonEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _toolBoxEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _splitterEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _scrollBarEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _spinBoxEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _tabBarEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _dockSeparatorEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _headerViewEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _mdiWindowEngine->setEnabled( animationsEnabled && StyleConfigData::genericAnimationsEnabled() ); _progressBarEngine->setEnabled( animationsEnabled && StyleConfigData::progressBarAnimationsEnabled() ); // busy indicator _busyIndicatorEngine->setEnabled( StyleConfigData::progressBarAnimated() ); // menubar engine int menuBarAnimationType( StyleConfigData::menuBarAnimationType() ); if( menuBarAnimationType == StyleConfigData::MB_FADE && !qobject_cast( _menuBarEngine ) ) { if( _menuBarEngine ) { MenuBarEngineV1* newEngine = new MenuBarEngineV1( this, _menuBarEngine ); registerEngine( newEngine ); _menuBarEngine->deleteLater(); _menuBarEngine = newEngine; } else registerEngine( _menuBarEngine = new MenuBarEngineV1( this ) ); } else if( menuBarAnimationType == StyleConfigData::MB_FOLLOW_MOUSE && !qobject_cast( _menuBarEngine ) ) { if( _menuBarEngine ) { MenuBarEngineV2* newEngine = new MenuBarEngineV2( this, _menuBarEngine ); registerEngine( newEngine ); _menuBarEngine->deleteLater(); _menuBarEngine = newEngine; } else registerEngine( _menuBarEngine = new MenuBarEngineV1( this ) ); } // menu engine int menuAnimationType( StyleConfigData::menuAnimationType() ); if( menuAnimationType == StyleConfigData::ME_FADE && !qobject_cast( _menuEngine ) ) { if( _menuEngine ) { MenuEngineV1* newEngine = new MenuEngineV1( this, _menuEngine ); registerEngine( newEngine ); _menuEngine->deleteLater(); _menuEngine = newEngine; } else registerEngine( _menuEngine = new MenuEngineV1( this ) ); } else if( menuAnimationType == StyleConfigData::ME_FOLLOW_MOUSE && !qobject_cast( _menuEngine ) ) { if( _menuEngine ) { MenuEngineV2* newEngine = new MenuEngineV2( this, _menuEngine ); registerEngine( newEngine ); _menuEngine->deleteLater(); _menuEngine = newEngine; } else registerEngine( _menuEngine = new MenuEngineV1( this ) ); } _menuBarEngine->setEnabled( animationsEnabled && menuBarAnimationType != StyleConfigData::MB_NONE ); _menuEngine->setEnabled( animationsEnabled && menuAnimationType != StyleConfigData::ME_NONE ); // toolbar engine int toolBarAnimationType( StyleConfigData::toolBarAnimationType() ); if( toolBarAnimationType == StyleConfigData::TB_NONE || toolBarAnimationType == StyleConfigData::TB_FOLLOW_MOUSE ) { // disable toolbar engine _toolBarEngine->setEnabled( animationsEnabled && toolBarAnimationType == StyleConfigData::TB_FOLLOW_MOUSE ); // unregister all toolbuttons that belong to a toolbar foreach( QWidget* widget, _widgetStateEngine->registeredWidgets( AnimationHover|AnimationFocus ) ) { if( qobject_cast( widget ) && qobject_cast( widget->parentWidget() ) ) { _widgetStateEngine->unregisterWidget( widget ); } } } else if( toolBarAnimationType == StyleConfigData::TB_FADE ) { // disable toolbar engine _toolBarEngine->setEnabled( false ); // retrieve all registered toolbars BaseEngine::WidgetList widgets( _toolBarEngine->registeredWidgets() ); foreach( QWidget* widget, widgets ) { // get all toolbuttons foreach( QObject* child, widget->children() ) { if( QToolButton* toolButton = qobject_cast( child ) ) { _widgetStateEngine->registerWidget( toolButton, AnimationHover ); } } } } } { // durations - _widgetEnabilityEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); + _widgetEnableStateEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _widgetStateEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _inputWidgetEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _comboBoxEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _toolButtonEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _toolBoxEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _splitterEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _scrollBarEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _spinBoxEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _tabBarEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _dockSeparatorEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _headerViewEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _mdiWindowEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _progressBarEngine->setDuration( StyleConfigData::progressBarAnimationsDuration() ); _busyIndicatorEngine->setDuration( StyleConfigData::progressBarBusyStepDuration() ); _toolBarEngine->setDuration( StyleConfigData::genericAnimationsDuration() ); _toolBarEngine->setFollowMouseDuration( StyleConfigData::toolBarAnimationsDuration() ); _menuBarEngine->setDuration( StyleConfigData::menuBarAnimationsDuration() ); _menuBarEngine->setFollowMouseDuration( StyleConfigData::menuBarFollowMouseAnimationsDuration() ); _menuEngine->setDuration( StyleConfigData::menuAnimationsDuration() ); _menuEngine->setFollowMouseDuration( StyleConfigData::menuFollowMouseAnimationsDuration() ); } } //____________________________________________________________ void Animations::registerWidget( QWidget* widget ) const { if( !widget ) return; // check against noAnimations propery QVariant propertyValue( widget->property( PropertyNames::noAnimations ) ); if( propertyValue.isValid() && propertyValue.toBool() ) return; // these are needed to not register animations for kwin widgets if( widget->objectName() == QStringLiteral( "decoration widget" ) ) return; if( widget->inherits( "KCommonDecorationButton" ) ) return; if( widget->inherits( "QShapedPixmapWidget" ) ) return; // all widgets are registered to the enability engine. - _widgetEnabilityEngine->registerWidget( widget, AnimationEnable ); + _widgetEnableStateEngine->registerWidget( widget, AnimationEnable ); // install animation timers // for optimization, one should put with most used widgets here first if( qobject_cast(widget) ) { _toolButtonEngine->registerWidget( widget, AnimationHover ); bool isInToolBar( qobject_cast(widget->parent()) ); if( isInToolBar ) { if( StyleConfigData::toolBarAnimationType() == StyleConfigData::TB_FADE ) { _widgetStateEngine->registerWidget( widget, AnimationHover ); } } else _widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } else if( qobject_cast(widget) ) { if( qobject_cast( widget->parent() ) ) { _toolBoxEngine->registerWidget( widget ); } _widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } else if( qobject_cast(widget) ) { _widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } // groupboxes else if( QGroupBox* groupBox = qobject_cast( widget ) ) { if( groupBox->isCheckable() ) { _widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } } // scrollbar else if( qobject_cast( widget ) ) { _scrollBarEngine->registerWidget( widget ); } else if( qobject_cast( widget ) ) { _widgetStateEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } else if( qobject_cast( widget ) ) { _progressBarEngine->registerWidget( widget ); _busyIndicatorEngine->registerWidget( widget ); } else if( qobject_cast( widget ) ) { _splitterEngine->registerWidget( widget ); } else if( qobject_cast( widget ) ) { _dockSeparatorEngine->registerWidget( widget ); } else if( qobject_cast( widget ) ) { _headerViewEngine->registerWidget( widget ); } // menu else if( qobject_cast( widget ) ) { _menuEngine->registerWidget( widget ); } else if( qobject_cast( widget ) ) { _menuBarEngine->registerWidget( widget ); } else if( qobject_cast( widget ) ) { _tabBarEngine->registerWidget( widget ); } else if( qobject_cast( widget ) ) { _toolBarEngine->registerWidget( widget ); } // editors else if( qobject_cast( widget ) ) { _comboBoxEngine->registerWidget( widget, AnimationHover ); _inputWidgetEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } else if( qobject_cast( widget ) ) { _spinBoxEngine->registerWidget( widget ); _inputWidgetEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } else if( qobject_cast( widget ) ) { _inputWidgetEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } else if( qobject_cast( widget ) ) { _inputWidgetEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } else if( widget->inherits( "KTextEditor::View" ) ) { _inputWidgetEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } // lists else if( qobject_cast( widget ) ) { _inputWidgetEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } // scrollarea else if( QAbstractScrollArea* scrollArea = qobject_cast( widget ) ) { if( scrollArea->frameShadow() == QFrame::Sunken && (widget->focusPolicy()&Qt::StrongFocus) ) { _inputWidgetEngine->registerWidget( widget, AnimationHover|AnimationFocus ); } } // mdi subwindows else if( qobject_cast( widget ) ) { _mdiWindowEngine->registerWidget( widget ); } return; } //____________________________________________________________ void Animations::unregisterWidget( QWidget* widget ) const { if( !widget ) return; /* these are the engines that have not been stored inside the list, because they can be register widgets in combination with other engines */ - _widgetEnabilityEngine->unregisterWidget( widget ); + _widgetEnableStateEngine->unregisterWidget( widget ); _spinBoxEngine->unregisterWidget( widget ); _comboBoxEngine->unregisterWidget( widget ); _toolButtonEngine->unregisterWidget( widget ); _toolBoxEngine->unregisterWidget( widget ); _busyIndicatorEngine->unregisterWidget( widget ); // the following allows some optimization of widget unregistration // it assumes that a widget can be registered atmost in one of the // engines stored in the list. foreach( const BaseEngine::Pointer& engine, _engines ) { if( engine && engine.data()->unregisterWidget( widget ) ) break; } } //_______________________________________________________________ void Animations::unregisterEngine( QObject* object ) { int index( _engines.indexOf( qobject_cast(object) ) ); if( index >= 0 ) _engines.removeAt( index ); } //_______________________________________________________________ void Animations::registerEngine( BaseEngine* engine ) { _engines.append( engine ); connect( engine, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterEngine(QObject*)) ); } } diff --git a/kstyle/animations/oxygenanimations.h b/kstyle/animations/oxygenanimations.h index da94330a..e1a65ae7 100644 --- a/kstyle/animations/oxygenanimations.h +++ b/kstyle/animations/oxygenanimations.h @@ -1,217 +1,214 @@ #ifndef oxygenanimations_h #define oxygenanimations_h ////////////////////////////////////////////////////////////////////////////// // oxygenanimations.h // container for all animation engines // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbusyindicatorengine.h" #include "oxygendockseparatorengine.h" #include "oxygenheaderviewengine.h" #include "oxygenmdiwindowengine.h" #include "oxygenmenubarengine.h" #include "oxygenmenuengine.h" #include "oxygenprogressbarengine.h" #include "oxygenscrollbarengine.h" #include "oxygenspinboxengine.h" #include "oxygensplitterengine.h" #include "oxygentabbarengine.h" #include "oxygentoolbarengine.h" #include "oxygentoolboxengine.h" #include "oxygenwidgetstateengine.h" #include #include namespace Oxygen { - //! stores engines + //* stores engines class Animations: public QObject { Q_OBJECT public: - //! constructor + //* constructor explicit Animations( QObject* ); - //! destructor - virtual ~Animations( void ) - {} - - //! register animations corresponding to given widget, depending on its type. + //* register animations corresponding to given widget, depending on its type. void registerWidget( QWidget* widget ) const; /*! unregister all animations associated to a widget */ void unregisterWidget( QWidget* widget ) const; - //! enability engine - WidgetStateEngine& widgetEnabilityEngine( void ) const - { return *_widgetEnabilityEngine; } + //* enable state engine + WidgetStateEngine& widgetEnableStateEngine( void ) const + { return *_widgetEnableStateEngine; } - //! abstractButton engine + //* abstractButton engine WidgetStateEngine& widgetStateEngine( void ) const { return *_widgetStateEngine; } - //! editable combobox arrow hover engine + //* editable combobox arrow hover engine WidgetStateEngine& comboBoxEngine( void ) const { return *_comboBoxEngine; } - //! Tool buttons arrow hover engine + //* Tool buttons arrow hover engine WidgetStateEngine& toolButtonEngine( void ) const { return *_toolButtonEngine; } - //! item view engine + //* item view engine WidgetStateEngine& inputWidgetEngine( void ) const { return *_inputWidgetEngine; } - //! splitter engine + //* splitter engine SplitterEngine& splitterEngine( void ) const { return *_splitterEngine; } - //! busy indicator + //* busy indicator BusyIndicatorEngine& busyIndicatorEngine( void ) const { return *_busyIndicatorEngine; } - //! dock separators engine + //* dock separators engine DockSeparatorEngine& dockSeparatorEngine( void ) const { return *_dockSeparatorEngine; } - //! header view engine + //* header view engine HeaderViewEngine& headerViewEngine( void ) const { return *_headerViewEngine; } - //! progressbar engine + //* progressbar engine ProgressBarEngine& progressBarEngine( void ) const { return *_progressBarEngine; } - //! menubar engine + //* menubar engine MenuBarBaseEngine& menuBarEngine( void ) const { return *_menuBarEngine; } - //! menu engine + //* menu engine MenuBaseEngine& menuEngine( void ) const { return *_menuEngine; } - //! scrollbar engine + //* scrollbar engine ScrollBarEngine& scrollBarEngine( void ) const { return *_scrollBarEngine; } - //! spinbox engine + //* spinbox engine SpinBoxEngine& spinBoxEngine( void ) const { return *_spinBoxEngine; } - //! tabbar + //* tabbar TabBarEngine& tabBarEngine( void ) const { return *_tabBarEngine; } - //! toolbar + //* toolbar ToolBarEngine& toolBarEngine( void ) const { return *_toolBarEngine; } - //! toolbox + //* toolbox ToolBoxEngine& toolBoxEngine( void ) const { return *_toolBoxEngine; } - //! mdi windows + //* mdi windows MdiWindowEngine& mdiWindowEngine( void ) const { return *_mdiWindowEngine; } - //! setup engines + //* setup engines void setupEngines( void ); protected Q_SLOTS: - //! enregister engine + //* enregister engine void unregisterEngine( QObject* ); + private: - //! register new engine + //* register new engine void registerEngine( BaseEngine* engine ); - //! busy indicator + //* busy indicator BusyIndicatorEngine* _busyIndicatorEngine; - //! dock separator handle hover effect + //* dock separator handle hover effect DockSeparatorEngine* _dockSeparatorEngine; - //! headerview hover effect + //* headerview hover effect HeaderViewEngine* _headerViewEngine; - //! widget enability engine - WidgetStateEngine* _widgetEnabilityEngine; + //* widget enable state engine + WidgetStateEngine* _widgetEnableStateEngine; - //! abstract button engine + //* abstract button engine WidgetStateEngine* _widgetStateEngine; - //! editable combobox arrow hover effect + //* editable combobox arrow hover effect WidgetStateEngine* _comboBoxEngine; - //! mennu toolbutton arrow hover effect + //* mennu toolbutton arrow hover effect WidgetStateEngine* _toolButtonEngine; - //! item view engine + //* item view engine WidgetStateEngine* _inputWidgetEngine; - //! QSplitter engine + //* QSplitter engine SplitterEngine* _splitterEngine; - //! progressbar engine + //* progressbar engine ProgressBarEngine* _progressBarEngine; - //! menubar engine + //* menubar engine MenuBarBaseEngine* _menuBarEngine; - //! menu engine + //* menu engine MenuBaseEngine* _menuEngine; - //! scrollbar engine + //* scrollbar engine ScrollBarEngine* _scrollBarEngine; - //! spinbox engine + //* spinbox engine SpinBoxEngine* _spinBoxEngine; - //! tabbar engine + //* tabbar engine TabBarEngine* _tabBarEngine; - //! toolbar engine + //* toolbar engine ToolBarEngine* _toolBarEngine; - //! toolbar engine + //* toolbar engine ToolBoxEngine* _toolBoxEngine; - //! mdi window + //* mdi window MdiWindowEngine* _mdiWindowEngine; - //! keep list of existing engines + //* keep list of existing engines QList< BaseEngine::Pointer > _engines; }; } #endif diff --git a/kstyle/animations/oxygenbaseengine.h b/kstyle/animations/oxygenbaseengine.h index d9facdaf..c99cbedf 100644 --- a/kstyle/animations/oxygenbaseengine.h +++ b/kstyle/animations/oxygenbaseengine.h @@ -1,98 +1,103 @@ #ifndef oxygenbaseengine_h #define oxygenbaseengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenbaseengine.h // base engine // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygen.h" #include #include namespace Oxygen { - //! base class for all animation engines - /*! it is used to store configuration values used by all animations stored in the engine */ + //* base class for all animation engines + /** it is used to store configuration values used by all animations stored in the engine */ class BaseEngine: public QObject { Q_OBJECT public: using Pointer = WeakPointer; - //! constructor + //* constructor explicit BaseEngine( QObject* parent ): - QObject( parent ), - _enabled( true ), - _duration( 200 ) + QObject( parent ) {} - //! destructor - virtual ~BaseEngine( void ) - {} - //! enability - virtual void setEnabled( bool value ) - { _enabled = value; } + //*@name accessors + //@{ - //! enability + //* enability virtual bool enabled( void ) const { return _enabled; } - //! duration - virtual void setDuration( int value ) - { _duration = value; } - - //! duration + //* duration virtual int duration( void ) const { return _duration; } - //! unregister widget - virtual bool unregisterWidget( QObject* object ) = 0; - - //! list of widgets + //* list of widgets using WidgetList = QSet; - //! returns registered widgets + //* returns registered widgets virtual WidgetList registeredWidgets( void ) const { return WidgetList(); } + //@} + + //*@name modifiers + //@{ + + //* enability + virtual void setEnabled( bool value ) + { _enabled = value; } + + //* duration + virtual void setDuration( int value ) + { _duration = value; } + + //* unregister widget + virtual bool unregisterWidget( QObject* object ) = 0; + + //@} + private: - //! engine enability - bool _enabled; + //* engine enability + bool _enabled = true; - //! animation duration - int _duration; + //* animation duration + int _duration = 200; }; } #endif diff --git a/kstyle/animations/oxygenbusyindicatordata.h b/kstyle/animations/oxygenbusyindicatordata.h index 81cb17f3..3f39ad41 100644 --- a/kstyle/animations/oxygenbusyindicatordata.h +++ b/kstyle/animations/oxygenbusyindicatordata.h @@ -1,87 +1,82 @@ #ifndef oxygenbusyindicatordata_h #define oxygenbusyindicatordata_h ////////////////////////////////////////////////////////////////////////////// // oxygenbusyindicatordata.h // data container for progressbar busy indicator // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include namespace Oxygen { class BusyIndicatorData: public QObject { Q_OBJECT public: //* constructor explicit BusyIndicatorData( QObject* parent ): - QObject( parent ), - _animated( false ) - {} - - //* destructor - virtual ~BusyIndicatorData( void ) + QObject( parent ) {} //*@name accessors //@{ //* animated bool isAnimated( void ) const { return _animated; } //@} //*@name modifiers //@{ //* enabled void setEnabled( bool ) {} //* enabled void setDuration( int ) {} //* animated void setAnimated( bool value ) { _animated = value; } //@} private: //* animated - bool _animated; + bool _animated = false; }; } #endif diff --git a/kstyle/animations/oxygenbusyindicatorengine.h b/kstyle/animations/oxygenbusyindicatorengine.h index afa3f3c4..9a9df19c 100644 --- a/kstyle/animations/oxygenbusyindicatorengine.h +++ b/kstyle/animations/oxygenbusyindicatorengine.h @@ -1,109 +1,104 @@ #ifndef oxygenbusyindicatorengine_h #define oxygenbusyindicatorengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenbusyindicatorengine.h // handle progress bar busy indicator // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimation.h" #include "oxygenbaseengine.h" #include "oxygenbusyindicatordata.h" #include "oxygendatamap.h" namespace Oxygen { //* handles progress bar animations class BusyIndicatorEngine: public BaseEngine { Q_OBJECT //* declare opacity property Q_PROPERTY( qreal value READ value WRITE setValue ) public: //* constructor explicit BusyIndicatorEngine( QObject* ); - //* destructor - virtual ~BusyIndicatorEngine( void ) = default; - //*@name accessors //@{ //* true if widget is animated - virtual bool isAnimated( const QObject* ); + bool isAnimated( const QObject* ); //* value - virtual qreal value( void ) const + qreal value( void ) const { return _value; } //@} //*@name modifiers //@{ //* register progressbar - virtual bool registerWidget( QObject* ); + bool registerWidget( QObject* ); //* duration - void setDuration( int ) ; + void setDuration( int ) override; //* set object as animated - virtual void setAnimated( const QObject*, bool ); + void setAnimated( const QObject*, bool ); //* opacity - virtual void setValue( qreal value ); + void setValue( qreal value ); //@} public Q_SLOTS: //* remove widget from map - bool unregisterWidget( QObject* ) ; + bool unregisterWidget( QObject* ) override; - protected: + private: //* returns data associated to widget DataMap::Value data( const QObject* ); - private: - //* map widgets to progressbar data DataMap _data; //* animation Animation::Pointer _animation; //* value qreal _value = 0; }; } #endif diff --git a/kstyle/animations/oxygendatamap.h b/kstyle/animations/oxygendatamap.h index 152a2a1f..e82bf57d 100644 --- a/kstyle/animations/oxygendatamap.h +++ b/kstyle/animations/oxygendatamap.h @@ -1,177 +1,176 @@ #ifndef oxygendatamap_h #define oxygendatamap_h ////////////////////////////////////////////////////////////////////////////// // oxygendatamap.h // stores event filters and maps widgets to timelines for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygen.h" #include #include #include namespace Oxygen { - //! data map - /*! it maps templatized data object to associated object */ + //* data map + /** it maps templatized data object to associated object */ template< typename K, typename T > class BaseDataMap: public QMap< const K*, WeakPointer > { public: using Key = const K*; using Value = WeakPointer; - //! constructor + //* constructor BaseDataMap( void ): QMap(), _enabled( true ), _lastKey( NULL ) {} - //! destructor - virtual ~BaseDataMap( void ) - {} + //* destructor + virtual ~BaseDataMap( void ) = default; - //! insertion - virtual typename QMap< Key, Value >::iterator insert( const Key& key, const Value& value, bool enabled = true ) + //* insertion + typename QMap< Key, Value >::iterator insert( const Key& key, const Value& value, bool enabled = true ) { if( value ) value.data()->setEnabled( enabled ); return QMap< Key, Value >::insert( key, value ); } - //! find value + //* find value Value find( Key key ) { if( !( enabled() && key ) ) return Value(); if( key == _lastKey ) return _lastValue; else { Value out; typename QMap::iterator iter( QMap::find( key ) ); if( iter != QMap::end() ) out = iter.value(); _lastKey = key; _lastValue = out; return out; } } - //! unregister widget + //* unregister widget bool unregisterWidget( Key key ) { // check key if( !key ) return false; // clear last value if needed if( key == _lastKey ) { if( _lastValue ) _lastValue.clear(); _lastKey = NULL; } // find key in map typename QMap::iterator iter( QMap::find( key ) ); if( iter == QMap::end() ) return false; // delete value from map if found if( iter.value() ) iter.value().data()->deleteLater(); QMap::erase( iter ); return true; } - //! maxFrame + //* maxFrame void setEnabled( bool enabled ) { _enabled = enabled; foreach( const Value& value, *this ) { if( value ) value.data()->setEnabled( enabled ); } } - //! enability + //* enability bool enabled( void ) const { return _enabled; } - //! duration + //* duration void setDuration( int duration ) const { foreach( const Value& value, *this ) { if( value ) value.data()->setDuration( duration ); } } private: - //! enability + //* enability bool _enabled; - //! last key + //* last key Key _lastKey; - //! last value + //* last value Value _lastValue; }; - //! standard data map, using QObject as a key + //* standard data map, using QObject as a key template< typename T > class DataMap: public BaseDataMap< QObject, T > { public: - //! constructor + //* constructor DataMap( void ) {} - //! destructor + //* destructor virtual ~DataMap( void ) {} }; - //! QPaintDevice based dataMap + //* QPaintDevice based dataMap template< typename T > class PaintDeviceDataMap: public BaseDataMap< QPaintDevice, T > { public: - //! constructor + //* constructor PaintDeviceDataMap( void ) {} - //! destructor + //* destructor virtual ~PaintDeviceDataMap( void ) {} }; } #endif diff --git a/kstyle/animations/oxygendockseparatordata.h b/kstyle/animations/oxygendockseparatordata.h index 75bb1410..0b7cdc4e 100644 --- a/kstyle/animations/oxygendockseparatordata.h +++ b/kstyle/animations/oxygendockseparatordata.h @@ -1,170 +1,166 @@ #ifndef oxygendockseparator_data_h #define oxygendockseparator_data_h ////////////////////////////////////////////////////////////////////////////// // oxygendockseparatordata.h // generic data container for widgetstate hover (mouse-over) animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygengenericdata.h" #include "oxygenanimation.h" namespace Oxygen { - //! dock widget splitters hover effect + //* dock widget splitters hover effect class DockSeparatorData: public AnimationData { Q_OBJECT - //! declare opacity property + //* declare opacity property Q_PROPERTY( qreal verticalOpacity READ verticalOpacity WRITE setVerticalOpacity ) Q_PROPERTY( qreal horizontalOpacity READ horizontalOpacity WRITE setHorizontalOpacity ) public: - //! constructor + //* constructor DockSeparatorData( QObject* parent, QWidget* target, int duration ); - //! destructor - virtual ~DockSeparatorData( void ) - {} - //@} /*! returns true if hover has Changed and starts timer accordingly */ - virtual void updateRect( const QRect&, const Qt::Orientation&, bool hovered ); + void updateRect( const QRect&, const Qt::Orientation&, bool hovered ); - //! returns true if current splitter is animated - virtual bool isAnimated( QRect r, const Qt::Orientation& orientation ) const + //* returns true if current splitter is animated + bool isAnimated( QRect r, const Qt::Orientation& orientation ) const { return orientation == Qt::Vertical ? _verticalData.isAnimated( r ):_horizontalData.isAnimated( r ); } - //! opacity for given orientation + //* opacity for given orientation qreal opacity( const Qt::Orientation& orientation ) const { return orientation == Qt::Vertical ? verticalOpacity():horizontalOpacity(); } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { horizontalAnimation().data()->setDuration( duration ); verticalAnimation().data()->setDuration( duration ); } - //!@name horizontal splitter data + //*@name horizontal splitter data //@{ Animation::Pointer horizontalAnimation( void ) const { return _horizontalData._animation; } const QRect& horizontalRect( void ) const { return _horizontalData._rect; } void setHorizontalRect( const QRect& r ) { _horizontalData._rect = r; } qreal horizontalOpacity( void ) const { return _horizontalData._opacity; } void setHorizontalOpacity( qreal value ) { value = digitize( value ); if( _horizontalData._opacity == value ) return; _horizontalData._opacity = value; if( target() && !horizontalRect().isEmpty() ) target().data()->update( horizontalRect() ); } //@} - //!@name vertical splitter data + //*@name vertical splitter data //@{ Animation::Pointer verticalAnimation( void ) const { return _verticalData._animation; } const QRect& verticalRect( void ) const { return _verticalData._rect; } void setVerticalRect( const QRect& r ) { _verticalData._rect = r; } qreal verticalOpacity( void ) const { return _verticalData._opacity; } void setVerticalOpacity( qreal value ) { value = digitize( value ); if( _verticalData._opacity == value ) return; _verticalData._opacity = value; if( target() && !verticalRect().isEmpty() ) target().data()->update( verticalRect() ); } //@} private: - //! stores data needed for animation + //* stores data needed for animation class Data { public: - //! constructor + //* constructor Data( void ): _opacity( AnimationData::OpacityInvalid ) {} - //! true if is animated + //* true if is animated bool isAnimated( QRect r ) const { return r == _rect && _animation.data()->isRunning(); } - //! animation pointer + //* animation pointer Animation::Pointer _animation; - //! opacity variable + //* opacity variable qreal _opacity; - //! stores active separator rect + //* stores active separator rect QRect _rect; }; - //! horizontal + //* horizontal Data _horizontalData; - //! vertical + //* vertical Data _verticalData; }; } #endif diff --git a/kstyle/animations/oxygendockseparatorengine.h b/kstyle/animations/oxygendockseparatorengine.h index 133496f9..a17450b4 100644 --- a/kstyle/animations/oxygendockseparatorengine.h +++ b/kstyle/animations/oxygendockseparatorengine.h @@ -1,112 +1,108 @@ #ifndef oxygendockseparatorengine_h #define oxygendockseparatorengine_h ////////////////////////////////////////////////////////////////////////////// // oxygendockseparatorengine.h // stores event filters and maps widgets to timelines for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygendockseparatordata.h" namespace Oxygen { - //! stores dockseparator hovered action and timeLine + //* stores dockseparator hovered action and timeLine class DockSeparatorEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit DockSeparatorEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~DockSeparatorEngine( void ) - {} - - //! register dockseparator - virtual bool registerWidget( QWidget* ); + //* register dockseparator + bool registerWidget( QWidget* ); - //! update rect and hover value for data matching widget - virtual void updateRect( const QObject* object, const QRect& r, const Qt::Orientation orientation, bool hovered ) + //* update rect and hover value for data matching widget + void updateRect( const QObject* object, const QRect& r, const Qt::Orientation orientation, bool hovered ) { if( DataMap::Value data = _data.find( object ) ) { data.data()->updateRect( r, orientation, hovered ); } } - //! returns true if object is animated - virtual bool isAnimated( const QObject* object, const QRect& r, const Qt::Orientation orientation ) + //* returns true if object is animated + bool isAnimated( const QObject* object, const QRect& r, const Qt::Orientation orientation ) { if( DataMap::Value data = _data.find( object ) ) { return data.data()->isAnimated( r, orientation ); } else return false; } - //! returns true if object is animated - virtual qreal opacity( const QObject* object, const Qt::Orientation orientation ) + //* returns true if object is animated + qreal opacity( const QObject* object, const Qt::Orientation orientation ) { if( DataMap::Value data = _data.find( object ) ) { return data.data()->opacity( orientation ); } else return AnimationData::OpacityInvalid; } - //! enability - void setEnabled( bool value ) + //* enability + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! data map + //* data map DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygenenabledata.h b/kstyle/animations/oxygenenabledata.h index 23ce0d19..1d60dc6b 100644 --- a/kstyle/animations/oxygenenabledata.h +++ b/kstyle/animations/oxygenenabledata.h @@ -1,59 +1,55 @@ #ifndef oxygenenable_data_h #define oxygenenable_data_h ////////////////////////////////////////////////////////////////////////////// // oxygenenabledata.h // generic data container for widget enable/disable animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenwidgetstatedata.h" namespace Oxygen { - //! Enable data + //* Enable data class EnableData: public WidgetStateData { Q_OBJECT public: - //! constructor + //* constructor EnableData( QObject* parent, QWidget* target, int duration, bool state = true ): WidgetStateData( parent, target, duration, state ) { target->installEventFilter( this ); } - //! destructor - virtual ~EnableData( void ) - {} - - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; }; } #endif diff --git a/kstyle/animations/oxygengenericdata.cpp b/kstyle/animations/oxygengenericdata.cpp index f7677ad3..bbac80d8 100644 --- a/kstyle/animations/oxygengenericdata.cpp +++ b/kstyle/animations/oxygengenericdata.cpp @@ -1,41 +1,40 @@ ////////////////////////////////////////////////////////////////////////////// // oxygengenericdata.cpp // generic data container for widget animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygengenericdata.h" #include namespace Oxygen { //______________________________________________ GenericData::GenericData( QObject* parent, QWidget* target, int duration ): AnimationData( parent, target ), - _animation( new Animation( duration, this ) ), - _opacity(0) + _animation( new Animation( duration, this ) ) { setupAnimation( _animation, "opacity" ); } } diff --git a/kstyle/animations/oxygengenericdata.h b/kstyle/animations/oxygengenericdata.h index 5cd65373..9368dd26 100644 --- a/kstyle/animations/oxygengenericdata.h +++ b/kstyle/animations/oxygengenericdata.h @@ -1,93 +1,89 @@ #ifndef oxygengeneric_data_h #define oxygengeneric_data_h ////////////////////////////////////////////////////////////////////////////// // oxygengenericdata.h // generic data container for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimationdata.h" #include "oxygenanimation.h" #include #include namespace Oxygen { - //! generic data + //* generic data class GenericData: public AnimationData { Q_OBJECT - //! declare opacity property + //* declare opacity property Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) public: - //! constructor + //* constructor GenericData( QObject* parent, QWidget* widget, int duration ); - //! destructor - virtual ~GenericData( void ) - {} - - //! return animation object + //* return animation object virtual const Animation::Pointer& animation() const { return _animation; } - //! duration - void setDuration( int duration ) - { _animation.data()->setDuration( duration ); } - - //! opacity + //* opacity virtual qreal opacity( void ) const { return _opacity; } - //! opacity + //* duration + void setDuration( int duration ) override + { _animation.data()->setDuration( duration ); } + + //* opacity virtual void setOpacity( qreal value ) { value = digitize( value ); if( _opacity == value ) return; _opacity = value; setDirty(); } private: - //! animation handling + //* animation handling Animation::Pointer _animation; - //! opacity variable - qreal _opacity; + //* opacity variable + qreal _opacity = 0; }; } #endif diff --git a/kstyle/animations/oxygenheaderviewdata.h b/kstyle/animations/oxygenheaderviewdata.h index 6bed473f..e27c00ba 100644 --- a/kstyle/animations/oxygenheaderviewdata.h +++ b/kstyle/animations/oxygenheaderviewdata.h @@ -1,164 +1,157 @@ #ifndef oxygenheaderview_data_h #define oxygenheaderview_data_h ////////////////////////////////////////////////////////////////////////////// // oxygenheaderviewdata.h // data container for QHeaderView animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimationdata.h" #include namespace Oxygen { - //! headerviews + //* headerviews class HeaderViewData: public AnimationData { Q_OBJECT - //! declare opacity property + //* declare opacity property Q_PROPERTY( qreal currentOpacity READ currentOpacity WRITE setCurrentOpacity ) Q_PROPERTY( qreal previousOpacity READ previousOpacity WRITE setPreviousOpacity ) public: - //! constructor + //* constructor HeaderViewData( QObject* parent, QWidget* target, int duration ); - //! destructor - virtual ~HeaderViewData( void ) - {} - - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { currentIndexAnimation().data()->setDuration( duration ); previousIndexAnimation().data()->setDuration( duration ); } - //! update state + //* update state bool updateState( const QPoint&, bool ); - //!@name current index handling + //*@name current index handling //@{ - //! current opacity - virtual qreal currentOpacity( void ) const + //* current opacity + qreal currentOpacity( void ) const { return _current._opacity; } - //! current opacity - virtual void setCurrentOpacity( qreal value ) + //* current opacity + void setCurrentOpacity( qreal value ) { value = digitize( value ); if( _current._opacity == value ) return; _current._opacity = value; setDirty(); } - //! current index - virtual int currentIndex( void ) const + //* current index + int currentIndex( void ) const { return _current._index; } - //! current index - virtual void setCurrentIndex( int index ) + //* current index + void setCurrentIndex( int index ) { _current._index = index; } - //! current index animation - virtual const Animation::Pointer& currentIndexAnimation( void ) const + //* current index animation + const Animation::Pointer& currentIndexAnimation( void ) const { return _current._animation; } //@} - //!@name previous index handling + //*@name previous index handling //@{ - //! previous opacity - virtual qreal previousOpacity( void ) const + //* previous opacity + qreal previousOpacity( void ) const { return _previous._opacity; } - //! previous opacity - virtual void setPreviousOpacity( qreal value ) + //* previous opacity + void setPreviousOpacity( qreal value ) { value = digitize( value ); if( _previous._opacity == value ) return; _previous._opacity = value; setDirty(); } - //! previous index - virtual int previousIndex( void ) const + //* previous index + int previousIndex( void ) const { return _previous._index; } - //! previous index - virtual void setPreviousIndex( int index ) + //* previous index + void setPreviousIndex( int index ) { _previous._index = index; } - //! previous index Animation - virtual const Animation::Pointer& previousIndexAnimation( void ) const + //* previous index Animation + const Animation::Pointer& previousIndexAnimation( void ) const { return _previous._animation; } //@} - //! return Animation associated to action at given position, if any - virtual Animation::Pointer animation( const QPoint& position ) const; + //* return Animation associated to action at given position, if any + Animation::Pointer animation( const QPoint& position ) const; - //! return opacity associated to action at given position, if any - virtual qreal opacity( const QPoint& position ) const; + //* return opacity associated to action at given position, if any + qreal opacity( const QPoint& position ) const; protected: - //! dirty - void setDirty( void ) const ; + //* dirty + void setDirty( void ) const override; private: - //! container for needed animation data + //* container for needed animation data class Data { public: - //! default constructor - Data( void ): - _opacity(0), - _index(-1) - {} + //* default constructor + Data( void ) = default; Animation::Pointer _animation; - qreal _opacity; - int _index; + qreal _opacity = 0; + int _index = -1; }; - //! current tab animation data (for hover enter animations) + //* current tab animation data (for hover enter animations) Data _current; - //! previous tab animations data (for hover leave animations) + //* previous tab animations data (for hover leave animations) Data _previous; }; } #endif diff --git a/kstyle/animations/oxygenheaderviewengine.h b/kstyle/animations/oxygenheaderviewengine.h index 4ba958e6..808df29a 100644 --- a/kstyle/animations/oxygenheaderviewengine.h +++ b/kstyle/animations/oxygenheaderviewengine.h @@ -1,101 +1,97 @@ #ifndef oxygenheaderviewengine_h #define oxygenheaderviewengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenheaderviewengine.h // stores event filters and maps widgets to timelines for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenheaderviewdata.h" namespace Oxygen { - //! stores headerview hovered action and timeLine + //* stores headerview hovered action and timeLine class HeaderViewEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit HeaderViewEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~HeaderViewEngine( void ) - {} - - //! register headerview - virtual bool registerWidget( QWidget* ); + //* register headerview + bool registerWidget( QWidget* ); - //! true if widget hover state is changed - virtual bool updateState( const QObject*, const QPoint&, bool ); + //* true if widget hover state is changed + bool updateState( const QObject*, const QPoint&, bool ); - //! true if widget is animated - virtual bool isAnimated( const QObject* object, const QPoint& point ) + //* true if widget is animated + bool isAnimated( const QObject* object, const QPoint& point ) { if( DataMap::Value data = _data.find( object ) ) { if( Animation::Pointer animation = data.data()->animation( point ) ) return animation.data()->isRunning(); } return false; } - //! animation opacity - virtual qreal opacity( const QObject* object, const QPoint& point ) + //* animation opacity + qreal opacity( const QObject* object, const QPoint& point ) { return isAnimated( object, point ) ? _data.find( object ).data()->opacity( point ) : AnimationData::OpacityInvalid; } - //! enability - void setEnabled( bool value ) + //* enability + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! data map + //* data map DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygenmdiwindowdata.h b/kstyle/animations/oxygenmdiwindowdata.h index 80cfe2dd..984cd7b4 100644 --- a/kstyle/animations/oxygenmdiwindowdata.h +++ b/kstyle/animations/oxygenmdiwindowdata.h @@ -1,164 +1,157 @@ #ifndef oxygenmdiwindow_data_h #define oxygenmdiwindow_data_h ////////////////////////////////////////////////////////////////////////////// // oxygenmdiwindowdata.h // mdi window data container for window titlebar buttons // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimationdata.h" #include namespace Oxygen { - //! handles mdiwindow arrows hover + //* handles mdiwindow arrows hover class MdiWindowData: public AnimationData { Q_OBJECT - //! declare opacity property + //* declare opacity property Q_PROPERTY( qreal currentOpacity READ currentOpacity WRITE setCurrentOpacity ) Q_PROPERTY( qreal previousOpacity READ previousOpacity WRITE setPreviousOpacity ) public: - //! constructor + //* constructor MdiWindowData( QObject*, QWidget*, int ); - //! destructor - virtual ~MdiWindowData( void ) - {} + //* animation state + bool updateState( int primitive, bool value ); - //! animation state - virtual bool updateState( int primitive, bool value ); - - //! animation state - virtual bool isAnimated( int primitive ) const + //* animation state + bool isAnimated( int primitive ) const { return( ( primitive == _currentData._primitive && currentAnimation().data()->isRunning() ) || ( primitive == _previousData._primitive && previousAnimation().data()->isRunning() ) ); } - //! opacity - virtual qreal opacity( int primitive ) const + //* opacity + qreal opacity( int primitive ) const { if( primitive == _currentData._primitive ) return currentOpacity(); else if( primitive == _previousData._primitive ) return previousOpacity(); else return OpacityInvalid; } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { currentAnimation().data()->setDuration( duration ); previousAnimation().data()->setDuration( duration ); } - //!@name current animation + //*@name current animation //@{ - //! opacity + //* opacity qreal currentOpacity( void ) const { return _currentData._opacity; } - //! opacity + //* opacity void setCurrentOpacity( qreal value ) { value = digitize( value ); if( _currentData._opacity == value ) return; _currentData._opacity = value; setDirty(); } - //! animation + //* animation Animation::Pointer currentAnimation( void ) const { return _currentData._animation; } //@} - //!@name previous animation + //*@name previous animation //@{ - //! opacity + //* opacity qreal previousOpacity( void ) const { return _previousData._opacity; } - //! opacity + //* opacity void setPreviousOpacity( qreal value ) { value = digitize( value ); if( _previousData._opacity == value ) return; _previousData._opacity = value; setDirty(); } - //! animation + //* animation Animation::Pointer previousAnimation( void ) const { return _previousData._animation; } //@} private: - //! container for needed animation data + //* container for needed animation data class Data { public: - //! default constructor - Data( void ): - _primitive( 0 ), - _opacity(0) - {} + //* default constructor + Data() = default; - //! subcontrol + //* subcontrol bool updateSubControl( int ); - //! subcontrol - int _primitive; + //* subcontrol + int _primitive = 0; - //! animation + //* animation Animation::Pointer _animation; - //! opacity - qreal _opacity; + //* opacity + qreal _opacity = 0; }; - //! current data + //* current data Data _currentData; - //! previous data + //* previous data Data _previousData; }; } #endif diff --git a/kstyle/animations/oxygenmdiwindowengine.h b/kstyle/animations/oxygenmdiwindowengine.h index 9c723a0f..045fe106 100644 --- a/kstyle/animations/oxygenmdiwindowengine.h +++ b/kstyle/animations/oxygenmdiwindowengine.h @@ -1,115 +1,111 @@ #ifndef oxygenmdiwindowengine_h #define oxygenmdiwindowengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenmdiwindowengine.h // stores event filters and maps widgets to animations // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenmdiwindowdata.h" namespace Oxygen { - //! handle mdiwindow arrows hover effect + //* handle mdiwindow arrows hover effect class MdiWindowEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit MdiWindowEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~MdiWindowEngine( void ) - {} - - //! register widget - virtual bool registerWidget( QWidget* ); + //* register widget + bool registerWidget( QWidget* ); - //! state - virtual bool updateState( const QObject* object, int primitive, bool value ) + //* state + bool updateState( const QObject* object, int primitive, bool value ) { if( DataMap::Value data = _data.find( object ) ) { return data.data()->updateState( primitive, value ); } else return false; } - //! true if widget is animated - virtual bool isAnimated( const QObject* object, int primitive ) + //* true if widget is animated + bool isAnimated( const QObject* object, int primitive ) { if( DataMap::Value data = _data.find( object ) ) { return data.data()->isAnimated( primitive ); } else return false; } - //! animation opacity - virtual qreal opacity( const QObject* object, int primitive ) + //* animation opacity + qreal opacity( const QObject* object, int primitive ) { if( DataMap::Value data = _data.find( object ) ) { return data.data()->opacity( primitive ); } else return AnimationData::OpacityInvalid; } - //! enability - void setEnabled( bool value ) + //* enability + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! data map + //* data map DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygenmenubardata.h b/kstyle/animations/oxygenmenubardata.h index 09ef32fd..400773e0 100644 --- a/kstyle/animations/oxygenmenubardata.h +++ b/kstyle/animations/oxygenmenubardata.h @@ -1,467 +1,455 @@ #ifndef oxygenmenubar_data_h #define oxygenmenubar_data_h ////////////////////////////////////////////////////////////////////////////// // oxygenmenubardata.h // data container for QMenuBar animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimationdata.h" #include "oxygen.h" #include #include namespace Oxygen { - //! widget index + //* widget index enum WidgetIndex { Current, Previous }; - //! menubar data + //* menubar data class MenuBarData: public AnimationData { Q_OBJECT public: - //! constructor + //* constructor MenuBarData( QObject* parent, QWidget* target ); - //! destructor - virtual ~MenuBarData( void ) - {} - protected: - bool _isMenu; - int _motions; + bool _isMenu = false; + int _motions = -1; }; - //! menubar data + //* menubar data class MenuBarDataV1: public MenuBarData { Q_OBJECT - //! declare opacity property + //* declare opacity property Q_PROPERTY( qreal currentOpacity READ currentOpacity WRITE setCurrentOpacity ) Q_PROPERTY( qreal previousOpacity READ previousOpacity WRITE setPreviousOpacity ) public: - //! constructor + //* constructor MenuBarDataV1( QObject* parent, QWidget* target, int duration ); - //! destructor - virtual ~MenuBarDataV1( void ) - {} - - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! animations - virtual const Animation::Pointer& currentAnimation( void ) const + //* animations + const Animation::Pointer& currentAnimation( void ) const { return _current._animation; } - //! animations - virtual const Animation::Pointer& previousAnimation( void ) const + //* animations + const Animation::Pointer& previousAnimation( void ) const { return _previous._animation; } - //! return animation matching given point - virtual Animation::Pointer animation( const QPoint& point ) const + //* return animation matching given point + Animation::Pointer animation( const QPoint& point ) const { if( currentRect().contains( point ) ) return currentAnimation(); else if( previousRect().contains( point ) ) return previousAnimation(); else return Animation::Pointer(); } - //! return animation matching given point - virtual qreal opacity( const QPoint& point ) const + //* return animation matching given point + qreal opacity( const QPoint& point ) const { if( currentRect().contains( point ) ) return currentOpacity(); else if( previousRect().contains( point ) ) return previousOpacity(); else return OpacityInvalid; } // return rect matching QPoint - virtual QRect currentRect( const QPoint& point ) const + QRect currentRect( const QPoint& point ) const { if( currentRect().contains( point ) ) return currentRect(); else if( previousRect().contains( point ) ) return previousRect(); else return QRect(); } - //! animation associated to given Widget index - virtual const Animation::Pointer& animation( WidgetIndex index ) const + //* animation associated to given Widget index + const Animation::Pointer& animation( WidgetIndex index ) const { return index == Current ? currentAnimation():previousAnimation(); } - //! opacity associated to given Widget index - virtual qreal opacity( WidgetIndex index ) const + //* opacity associated to given Widget index + qreal opacity( WidgetIndex index ) const { return index == Current ? currentOpacity():previousOpacity(); } - //! opacity associated to given Widget index - virtual const QRect& currentRect( WidgetIndex index ) const + //* opacity associated to given Widget index + const QRect& currentRect( WidgetIndex index ) const { return index == Current ? currentRect():previousRect(); } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { currentAnimation().data()->setDuration( duration ); previousAnimation().data()->setDuration( duration ); } - //! current opacity - virtual qreal currentOpacity( void ) const + //* current opacity + qreal currentOpacity( void ) const { return _current._opacity; } - //! current opacity - virtual void setCurrentOpacity( qreal value ) + //* current opacity + void setCurrentOpacity( qreal value ) { value = digitize( value ); if( _current._opacity == value ) return; _current._opacity = value; setDirty(); } - //! current rect - virtual const QRect& currentRect( void ) const + //* current rect + const QRect& currentRect( void ) const { return _current._rect; } - //! previous opacity - virtual qreal previousOpacity( void ) const + //* previous opacity + qreal previousOpacity( void ) const { return _previous._opacity; } - //! previous opacity - virtual void setPreviousOpacity( qreal value ) + //* previous opacity + void setPreviousOpacity( qreal value ) { value = digitize( value ); if( _previous._opacity == value ) return; _previous._opacity = value; setDirty(); } - //! previous rect - virtual const QRect& previousRect( void ) const + //* previous rect + const QRect& previousRect( void ) const { return _previous._rect; } protected: - //!@name current action handling + //*@name current action handling //@{ - //! guarded action pointer + //* guarded action pointer using ActionPointer = WeakPointer; - //! current action + //* current action virtual const ActionPointer& currentAction( void ) const { return _currentAction; } - //! current action + //* current action virtual void setCurrentAction( QAction* action ) { _currentAction = ActionPointer( action ); } - //! current action + //* current action virtual void clearCurrentAction( void ) { _currentAction = ActionPointer(); } //@} - //!@name rect handling + //*@name rect handling //@{ - //! current rect + //* current rect virtual void setCurrentRect( const QRect& rect ) { _current._rect = rect; } - //! current rect + //* current rect virtual void clearCurrentRect( void ) { _current._rect = QRect(); } - //! previous rect + //* previous rect virtual void setPreviousRect( const QRect& rect ) { _previous._rect = rect; } - //! previous rect + //* previous rect virtual void clearPreviousRect( void ) { _previous._rect = QRect(); } //@} // leave event template< typename T > inline void enterEvent( const QObject* object ); // leave event template< typename T > inline void leaveEvent( const QObject* object ); - //! mouse move event + //* mouse move event template< typename T > inline void mouseMoveEvent( const QObject* object ); - //! mouse move event + //* mouse move event template< typename T > inline void mousePressEvent( const QObject* object ); - //! menubar enterEvent + //* menubar enterEvent virtual void enterEvent( const QObject* object ) { enterEvent( object ); } - //! menubar enterEvent + //* menubar enterEvent virtual void leaveEvent( const QObject* object ) { leaveEvent( object ); } - //! menubar mouseMoveEvent + //* menubar mouseMoveEvent virtual void mouseMoveEvent( const QObject* object ) { mouseMoveEvent( object ); } - //! menubar mousePressEvent + //* menubar mousePressEvent virtual void mousePressEvent( const QObject* object ) { mousePressEvent( object ); } private: - //! container for needed animation data + //* container for needed animation data class Data { public: - //! default constructor + //* default constructor Data( void ): _opacity(0) {} Animation::Pointer _animation; qreal _opacity; QRect _rect; }; - //! current tab animation data (for hover enter animations) + //* current tab animation data (for hover enter animations) Data _current; - //! previous tab animations data (for hover leave animations) + //* previous tab animations data (for hover leave animations) Data _previous; - //! current action + //* current action ActionPointer _currentAction; }; - //! menubar data + //* menubar data class MenuBarDataV2: public MenuBarData { Q_OBJECT Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) Q_PROPERTY( qreal progress READ progress WRITE setProgress ) public: - //! constructor + //* constructor MenuBarDataV2( QObject* parent, QWidget* target, int duration ); - //! destructor - virtual ~MenuBarDataV2( void ) - {} - - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! return animation associated to action at given position, if any + //* return animation associated to action at given position, if any virtual const Animation::Pointer& animation( void ) const { return _animation; } - //! return animation associated to action at given position, if any + //* return animation associated to action at given position, if any virtual const Animation::Pointer& progressAnimation( void ) const { return _progressAnimation; } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { animation().data()->setDuration( duration ); } - //! duration + //* duration virtual void setFollowMouseDuration( int duration ) { progressAnimation().data()->setDuration( duration ); } - //! return 'hover' rect position when widget is animated + //* return 'hover' rect position when widget is animated virtual const QRect& animatedRect( void ) const { return _animatedRect; } - //! current rect + //* current rect virtual const QRect& currentRect( void ) const { return _currentRect; } - //! timer + //* timer const QBasicTimer& timer( void ) const { return _timer; } - //! animation opacity + //* animation opacity virtual qreal opacity( void ) const { return _opacity; } - //! animation opacity + //* animation opacity virtual void setOpacity( qreal value ) { value = digitize( value ); if( _opacity == value ) return; _opacity = value; setDirty(); } - //! animation progress + //* animation progress virtual qreal progress( void ) const { return _progress; } - //! animation progress + //* animation progress virtual void setProgress( qreal value ) { value = digitize( value ); if( _progress == value ) return; _progress = value; updateAnimatedRect(); } protected: virtual void setEntered( bool value ) { _entered = value; } - //! animated rect + //* animated rect virtual void clearAnimatedRect( void ) { _animatedRect = QRect(); } - //! updated animated rect + //* updated animated rect virtual void updateAnimatedRect( void ); - //! timer event - void timerEvent( QTimerEvent* ) ; + //* timer event + void timerEvent( QTimerEvent* ) override; - //!@name current action handling + //*@name current action handling //@{ - //! guarded action pointer + //* guarded action pointer using ActionPointer = WeakPointer; - //! current action + //* current action virtual const ActionPointer& currentAction( void ) const { return _currentAction; } - //! current action + //* current action virtual void setCurrentAction( QAction* action ) { _currentAction = ActionPointer( action ); } - //! current action + //* current action virtual void clearCurrentAction( void ) { _currentAction = ActionPointer(); } //@} - //!@name rect handling + //*@name rect handling //@{ - //! current rect + //* current rect virtual void setCurrentRect( const QRect& rect ) { _currentRect = rect; } - //! current rect + //* current rect virtual void clearCurrentRect( void ) { _currentRect = QRect(); } - //! previous rect + //* previous rect virtual const QRect& previousRect( void ) const { return _previousRect; } - //! previous rect + //* previous rect virtual void setPreviousRect( const QRect& rect ) { _previousRect = rect; } - //! previous rect + //* previous rect virtual void clearPreviousRect( void ) { _previousRect = QRect(); } //@} // leave event template< typename T > inline void enterEvent( const QObject* object ); // leave event template< typename T > inline void leaveEvent( const QObject* object ); - //! mouse move event + //* mouse move event template< typename T > inline void mouseMoveEvent( const QObject* object ); - //! menubar enterEvent + //* menubar enterEvent virtual void enterEvent( const QObject* object ) { enterEvent( object ); } - //! menubar enterEvent + //* menubar enterEvent virtual void leaveEvent( const QObject* object ) { leaveEvent( object ); } - //! menubar mouseMoveEvent + //* menubar mouseMoveEvent virtual void mouseMoveEvent( const QObject* object ) { mouseMoveEvent( object ); } private: - //! fade animation + //* fade animation Animation::Pointer _animation; - //! progress animation + //* progress animation Animation::Pointer _progressAnimation; - //! opacity - qreal _opacity; + //* opacity + qreal _opacity = 0; - //! opacity - qreal _progress; + //* opacity + qreal _progress = 0; - //! timer - /*! this allows to add some delay before starting leaveEvent animation */ + //* timer + /** this allows to add some delay before starting leaveEvent animation */ QBasicTimer _timer; - //! current action + //* current action ActionPointer _currentAction; // current rect QRect _currentRect; // previous rect QRect _previousRect; // animated rect QRect _animatedRect; - //! true if toolbar was entered at least once (this prevents some initialization glitches) - bool _entered; + //* true if toolbar was entered at least once (this prevents some initialization glitches) + bool _entered = false; }; } #include "oxygenmenubardata_imp.h" #endif diff --git a/kstyle/animations/oxygenmenubarengine.h b/kstyle/animations/oxygenmenubarengine.h index d2c5f565..33d542a9 100644 --- a/kstyle/animations/oxygenmenubarengine.h +++ b/kstyle/animations/oxygenmenubarengine.h @@ -1,240 +1,227 @@ #ifndef oxygenmenubarengine_h #define oxygenmenubarengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenmenubarengine.h // stores event filters and maps widgets to timelines for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenmenubardata.h" namespace Oxygen { - //! stores menubar hovered action and timeLine + //* stores menubar hovered action and timeLine class MenuBarBaseEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit MenuBarBaseEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~MenuBarBaseEngine( void ) - {} - - //! register menubar + //* register menubar virtual bool registerWidget( QWidget* ) = 0; - //! true if widget is animated + //* true if widget is animated virtual bool isAnimated( const QObject*, const QPoint& ) { return false; } - //! animation opacity + //* animation opacity virtual qreal opacity( const QObject*, const QPoint& ) { return -1; } - //! return 'hover' rect position when widget is animated + //* return 'hover' rect position when widget is animated virtual QRect currentRect( const QObject*, const QPoint& ) { return QRect(); } - //! animated rect + //* animated rect virtual QRect animatedRect( const QObject* ) { return QRect(); } - //! timer + //* timer virtual bool isTimerActive( const QObject* ) { return false; } - //! enability - void setEnabled( bool ) = 0; + //* enable state + void setEnabled( bool ) override = 0; - //! duration - void setDuration( int ) = 0; + //* duration + void setDuration( int ) override = 0; - //! duration + //* duration virtual void setFollowMouseDuration( int ) {} }; - //! fading menubar animation + //* fading menubar animation class MenuBarEngineV1: public MenuBarBaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit MenuBarEngineV1( QObject* parent ): MenuBarBaseEngine( parent ) {} - //! constructor + //* constructor MenuBarEngineV1( QObject* parent, MenuBarBaseEngine* other ); - //! destructor - virtual ~MenuBarEngineV1( void ) - {} - - //! register menubar - bool registerWidget( QWidget* ) ; + //* register menubar + bool registerWidget( QWidget* ) override; - //! true if widget is animated - bool isAnimated( const QObject* object, const QPoint& point ) ; + //* true if widget is animated + bool isAnimated( const QObject* object, const QPoint& point ) override; - //! animation opacity - qreal opacity( const QObject* object, const QPoint& point ) + //* animation opacity + qreal opacity( const QObject* object, const QPoint& point ) override { return isAnimated( object, point ) ? _data.find( object ).data()->opacity( point ): AnimationData::OpacityInvalid; } - //! return 'hover' rect position when widget is animated - QRect currentRect( const QObject* object, const QPoint& point) + //* return 'hover' rect position when widget is animated + QRect currentRect( const QObject* object, const QPoint& point) override { return isAnimated( object, point ) ? _data.find( object ).data()->currentRect( point ): QRect(); } - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { BaseEngine::setDuration( duration ); _data.setDuration( duration ); } - //! return list of registered widgets - WidgetList registeredWidgets( void ) const ; + //* return list of registered widgets + WidgetList registeredWidgets( void ) const override; - public Q_SLOTS: + protected Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! data map + //* data map DataMap _data; }; - //! follow-mouse menubar animation + //* follow-mouse menubar animation class MenuBarEngineV2: public MenuBarBaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit MenuBarEngineV2( QObject* parent ): MenuBarBaseEngine( parent ) {} - //! constructor + //* constructor MenuBarEngineV2( QObject* parent, MenuBarBaseEngine* other ); - //! destructor - virtual ~MenuBarEngineV2( void ) - {} - - //! register menubar - bool registerWidget( QWidget* ) ; - + //* register menubar + bool registerWidget( QWidget* ) override; - //! true if widget is animated - bool isAnimated( const QObject* object, const QPoint& point ) ; + //* true if widget is animated + bool isAnimated( const QObject* object, const QPoint& point ) override; - //! animation opacity - qreal opacity( const QObject* object, const QPoint& point ) + //* animation opacity + qreal opacity( const QObject* object, const QPoint& point ) override { return isAnimated( object, point ) ? _data.find( object ).data()->opacity(): AnimationData::OpacityInvalid; } - //! return 'hover' rect position when widget is animated - QRect currentRect( const QObject*, const QPoint& ) ; + //* return 'hover' rect position when widget is animated + QRect currentRect( const QObject*, const QPoint& ) override; - //! return 'hover' rect position when widget is animated - QRect animatedRect( const QObject* ) ; + //* return 'hover' rect position when widget is animated + QRect animatedRect( const QObject* ) override; - //! timer associated to the data - bool isTimerActive( const QObject* ) ; + //* timer associated to the data + bool isTimerActive( const QObject* ) override; - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } - //! duration - virtual int followMouseDuration( void ) const + //* duration + int followMouseDuration( void ) const { return _followMouseDuration; } - //! duration - void setFollowMouseDuration( int duration ) + //* duration + void setFollowMouseDuration( int duration ) override { _followMouseDuration = duration; foreach( const DataMap::Value& value, _data ) { if( value ) value.data()->setFollowMouseDuration( duration ); } } - //! return list of registered widgets - WidgetList registeredWidgets( void ) const ; + //* return list of registered widgets + WidgetList registeredWidgets( void ) const override; protected Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! follow mouse animation duration + //* follow mouse animation duration int _followMouseDuration; - //! data map + //* data map DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygenmenudata.h b/kstyle/animations/oxygenmenudata.h index 464c1836..291043fa 100644 --- a/kstyle/animations/oxygenmenudata.h +++ b/kstyle/animations/oxygenmenudata.h @@ -1,115 +1,107 @@ #ifndef oxygenmenu_data_h #define oxygenmenu_data_h ////////////////////////////////////////////////////////////////////////////// // oxygenmenudata.h // data container for QMenu animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenmenubardata.h" #include namespace Oxygen { - //! menubar data + //* menubar data /*! most members are identical to menubar data. The one that are not are using templatized versions, because QMenuBar and QMenu API are very similar */ class MenuDataV1: public MenuBarDataV1 { Q_OBJECT public: - //! constructor + //* constructor MenuDataV1( QObject* parent, QWidget* target, int duration ): MenuBarDataV1( parent, target, duration ) {} - //! destructor - virtual ~MenuDataV1( void ) - {} - protected: - //! menubar enterEvent - void enterEvent( const QObject* object ) + //* menubar enterEvent + void enterEvent( const QObject* object ) override { MenuBarDataV1::enterEvent( object ); } - //! menubar enterEvent - void leaveEvent( const QObject* object ) + //* menubar enterEvent + void leaveEvent( const QObject* object ) override { MenuBarDataV1::leaveEvent( object ); } - //! menubar mouseMoveEvent - void mouseMoveEvent( const QObject* object ) + //* menubar mouseMoveEvent + void mouseMoveEvent( const QObject* object ) override { MenuBarDataV1::mouseMoveEvent( object ); } - //! menubar mousePressEvent - void mousePressEvent( const QObject* object ) + //* menubar mousePressEvent + void mousePressEvent( const QObject* object ) override { MenuBarDataV1::mousePressEvent( object ); } }; - //! menubar data + //* menubar data /*! most members are identical to menubar data. The one that are not are using templatized versions, because QMenuBar and QMenu API are very similar */ class MenuDataV2: public MenuBarDataV2 { Q_OBJECT public: - //! constructor + //* constructor MenuDataV2( QObject* parent, QWidget* target, int duration ): MenuBarDataV2( parent, target, duration ) { setEntered( false ); } - //! destructor - virtual ~MenuDataV2( void ) - {} - protected: - //! menubar enterEvent - void enterEvent( const QObject* object ) + //* menubar enterEvent + void enterEvent( const QObject* object ) override { MenuBarDataV2::enterEvent( object ); } - //! menubar enterEvent - void leaveEvent( const QObject* object ) + //* menubar enterEvent + void leaveEvent( const QObject* object ) override { MenuBarDataV2::leaveEvent( object ); } - //! menubar mouseMoveEvent - void mouseMoveEvent( const QObject* object ) + //* menubar mouseMoveEvent + void mouseMoveEvent( const QObject* object ) override { MenuBarDataV2::mouseMoveEvent( object ); } }; } #endif diff --git a/kstyle/animations/oxygenmenuengine.h b/kstyle/animations/oxygenmenuengine.h index 7967749a..160ebe0e 100644 --- a/kstyle/animations/oxygenmenuengine.h +++ b/kstyle/animations/oxygenmenuengine.h @@ -1,246 +1,234 @@ #ifndef oxygenmenuengine_h #define oxygenmenuengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenmenuengine.h // stores event filters and maps widgets to timelines for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenmenudata.h" namespace Oxygen { - //! stores menu hovered action and timeLine + //* stores menu hovered action and timeLine class MenuBaseEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit MenuBaseEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~MenuBaseEngine( void ) - {} - - //! register menubar + //* register menubar virtual bool registerWidget( QWidget* ) = 0; - //! true if widget is animated + //* true if widget is animated virtual bool isAnimated( const QObject*, WidgetIndex ) { return false; } - //! opacity + //* opacity virtual qreal opacity( const QObject*, WidgetIndex ) { return -1; } - //! return 'hover' rect position when widget is animated + //* return 'hover' rect position when widget is animated virtual QRect currentRect( const QObject*, WidgetIndex ) { return QRect(); } - //! return 'hover' rect position when widget is animated + //* return 'hover' rect position when widget is animated virtual QRect animatedRect( const QObject* ) { return QRect(); } - //! timer associated to the data + //* timer associated to the data virtual bool isTimerActive( const QObject* ) { return false; } - //! enability - void setEnabled( bool value ) = 0; + //* enable state + void setEnabled( bool value ) override = 0; - //! duration - void setDuration( int ) = 0; + //* duration + void setDuration( int ) override = 0; - //! duration + //* duration virtual void setFollowMouseDuration( int ) {} }; - //! stores menu hovered action and timeLine + //* stores menu hovered action and timeLine class MenuEngineV1: public MenuBaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit MenuEngineV1( QObject* parent ): MenuBaseEngine( parent ) {} - //! constructor + //* constructor MenuEngineV1( QObject* parent, MenuBaseEngine* other ); - //! destructor - virtual ~MenuEngineV1( void ) - {} - - //! register menubar - bool registerWidget( QWidget* ) ; + //* register menubar + bool registerWidget( QWidget* ) override; - //! true if widget is animated - bool isAnimated( const QObject* object, WidgetIndex index ) ; + //* true if widget is animated + bool isAnimated( const QObject* object, WidgetIndex index ) override; - //! animation opacity - qreal opacity( const QObject* object, WidgetIndex index ) + //* animation opacity + qreal opacity( const QObject* object, WidgetIndex index ) override { if( !isAnimated( object, index ) ) return AnimationData::OpacityInvalid; else return _data.find(object).data()->opacity( index ); } - //! return 'hover' rect position when widget is animated - QRect currentRect( const QObject* object, WidgetIndex index ) + //* return 'hover' rect position when widget is animated + QRect currentRect( const QObject* object, WidgetIndex index ) override { if( !isAnimated( object, index ) ) return QRect(); else return _data.find(object).data()->currentRect( index ); } - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { BaseEngine::setDuration( duration ); _data.setDuration( duration ); } - //! return list of registered widgets - WidgetList registeredWidgets( void ) const ; + //* return list of registered widgets + WidgetList registeredWidgets( void ) const override; public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! data map + //* data map DataMap _data; }; - //! stores menu hovered action and timeLine + //* stores menu hovered action and timeLine class MenuEngineV2: public MenuBaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit MenuEngineV2( QObject* parent ): MenuBaseEngine( parent ) {} - //! destructor - virtual ~MenuEngineV2( void ) - {} - - //! constructor + //* constructor MenuEngineV2( QObject* parent, MenuBaseEngine* other ); - //! register menu - bool registerWidget( QWidget* ) ; + //* register menu + bool registerWidget( QWidget* ) override; - //! return timeLine associated to action at given position, if any - bool isAnimated( const QObject*, WidgetIndex ) ; + //* return timeLine associated to action at given position, if any + bool isAnimated( const QObject*, WidgetIndex ) override; - //! animation opacity - qreal opacity( const QObject* object, WidgetIndex index ) + //* animation opacity + qreal opacity( const QObject* object, WidgetIndex index ) override { if( !isAnimated( object, index ) ) return AnimationData::OpacityInvalid; else return _data.find(object).data()->opacity(); } - //! return 'hover' rect position when widget is animated - QRect currentRect( const QObject* object, WidgetIndex index ) ; + //* return 'hover' rect position when widget is animated + QRect currentRect( const QObject* object, WidgetIndex index ) override; - //! return 'hover' rect position when widget is animated - QRect animatedRect( const QObject* ) ; + //* return 'hover' rect position when widget is animated + QRect animatedRect( const QObject* ) override; - //! timer associated to the data - bool isTimerActive( const QObject* ) ; + //* timer associated to the data + bool isTimerActive( const QObject* ) override; - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } - //! duration + //* duration virtual int followMouseDuration( void ) const { return _followMouseDuration; } - //! duration - void setFollowMouseDuration( int duration ) + //* duration + void setFollowMouseDuration( int duration ) override { _followMouseDuration = duration; foreach( const DataMap::Value& value, _data ) { if( value ) value.data()->setFollowMouseDuration( duration ); } } - //! return list of registered widgets - WidgetList registeredWidgets( void ) const ; + //* return list of registered widgets + WidgetList registeredWidgets( void ) const override; protected Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! follow mouse animation duration + //* follow mouse animation duration int _followMouseDuration; - //! data map + //* data map DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygenprogressbardata.h b/kstyle/animations/oxygenprogressbardata.h index 8e771da6..72077698 100644 --- a/kstyle/animations/oxygenprogressbardata.h +++ b/kstyle/animations/oxygenprogressbardata.h @@ -1,77 +1,73 @@ #ifndef oxygenprogressbardata_h #define oxygenprogressbardata_h ////////////////////////////////////////////////////////////////////////////// // oxygenprogressbardata.h // data container for progressbar animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygengenericdata.h" #include #include namespace Oxygen { - //! generic data + //* generic data class ProgressBarData: public GenericData { Q_OBJECT public: - //! constructor + //* constructor ProgressBarData( QObject* parent, QWidget* widget, int duration ); - //! destructor - virtual ~ProgressBarData( void ) - {} + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! event filter - bool eventFilter( QObject*, QEvent* ) ; - - //! progressbar value (during animation) - virtual int value( void ) const + //* progressbar value (during animation) + int value( void ) const { return _startValue + opacity()*( _endValue - _startValue ); } - protected Q_SLOTS: + private Q_SLOTS: - //! triggered by progressBar::valueChanged + //* triggered by progressBar::valueChanged void valueChanged( int ); private: - //! animation starting value - int _startValue; + //* animation starting value + int _startValue = 0; - //! animation ending value - int _endValue; + //* animation ending value + int _endValue = 0; }; } #endif diff --git a/kstyle/animations/oxygenprogressbarengine.h b/kstyle/animations/oxygenprogressbarengine.h index 9098b41b..ad662aa6 100644 --- a/kstyle/animations/oxygenprogressbarengine.h +++ b/kstyle/animations/oxygenprogressbarengine.h @@ -1,100 +1,96 @@ #ifndef oxygenprogressbarengine_h #define oxygenprogressbarengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenprogressbarengine.h // handle progress bar animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygenprogressbardata.h" #include "oxygendatamap.h" #include namespace Oxygen { - //! handles progress bar animations + //* handles progress bar animations class ProgressBarEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit ProgressBarEngine( QObject* object ): BaseEngine( object ) {} - //! destructor - virtual ~ProgressBarEngine( void ) - {} - - //! register progressbar - virtual bool registerWidget( QWidget* ); + //* register progressbar + bool registerWidget( QWidget* ); - //! true if widget is animated - virtual bool isAnimated( const QObject* ); + //* true if widget is animated + bool isAnimated( const QObject* ); - //! animation opacity - virtual int value( const QObject* object ) + //* animation opacity + int value( const QObject* object ) { return isAnimated( object ) ? data( object ).data()->value():0 ; } - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } protected: - //! returns data associated to widget + //* returns data associated to widget DataMap::Value data( const QObject* ); private: - //! map widgets to progressbar data + //* map widgets to progressbar data DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygenscrollbardata.h b/kstyle/animations/oxygenscrollbardata.h index e44d8614..10a77cef 100644 --- a/kstyle/animations/oxygenscrollbardata.h +++ b/kstyle/animations/oxygenscrollbardata.h @@ -1,245 +1,238 @@ #ifndef oxygenscrollbar_data_h #define oxygenscrollbar_data_h ////////////////////////////////////////////////////////////////////////////// // oxygenscrollbardata.h // data container for QScrollBar animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenwidgetstatedata.h" #include namespace Oxygen { - //! scrollbar data + //* scrollbar data class ScrollBarData: public WidgetStateData { Q_OBJECT Q_PROPERTY( qreal addLineOpacity READ addLineOpacity WRITE setAddLineOpacity ) Q_PROPERTY( qreal subLineOpacity READ subLineOpacity WRITE setSubLineOpacity ) public: - //! constructor + //* constructor ScrollBarData( QObject* parent, QWidget* target, int ); - //! destructor - virtual ~ScrollBarData( void ) - {} + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! event filter - bool eventFilter( QObject*, QEvent* ) ; - - //! needed to avoid warning about virtual function being hidden using WidgetStateData::animation; using WidgetStateData::opacity; - //! return animation for a given subcontrol - virtual const Animation::Pointer& animation( QStyle::SubControl ) const; + //* return animation for a given subcontrol + const Animation::Pointer& animation( QStyle::SubControl ) const; - //! return default opacity for a given subcontrol - virtual qreal opacity( QStyle::SubControl ) const; + //* return default opacity for a given subcontrol + qreal opacity( QStyle::SubControl ) const; - //! return default opacity for a given subcontrol - virtual bool isHovered( QStyle::SubControl control ) const + //* return default opacity for a given subcontrol + bool isHovered( QStyle::SubControl control ) const { switch( control ) { case QStyle::SC_ScrollBarAddLine: return addLineArrowHovered(); case QStyle::SC_ScrollBarSubLine: return subLineArrowHovered(); default: return false; } } - //! subControlRect - virtual QRect subControlRect( QStyle::SubControl control ) const + //* subControlRect + QRect subControlRect( QStyle::SubControl control ) const { switch( control ) { case QStyle::SC_ScrollBarAddLine: return _addLineData._rect; case QStyle::SC_ScrollBarSubLine: return _subLineData._rect; default: return QRect(); } } - //! subcontrol rect - virtual void setSubControlRect( QStyle::SubControl control, const QRect& rect ) + //* subcontrol rect + void setSubControlRect( QStyle::SubControl control, const QRect& rect ) { switch( control ) { case QStyle::SC_ScrollBarAddLine: _addLineData._rect = rect; break; case QStyle::SC_ScrollBarSubLine: _subLineData._rect = rect; break; default: break; } } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { WidgetStateData::setDuration( duration ); addLineAnimation().data()->setDuration( duration ); subLineAnimation().data()->setDuration( duration ); } - //! addLine opacity - virtual void setAddLineOpacity( qreal value ) + //* addLine opacity + void setAddLineOpacity( qreal value ) { value = digitize( value ); if( _addLineData._opacity == value ) return; _addLineData._opacity = value; setDirty(); } - //! addLine opacity - virtual qreal addLineOpacity( void ) const + //* addLine opacity + qreal addLineOpacity( void ) const { return _addLineData._opacity; } - //! subLine opacity - virtual void setSubLineOpacity( qreal value ) + //* subLine opacity + void setSubLineOpacity( qreal value ) { value = digitize( value ); if( _subLineData._opacity == value ) return; _subLineData._opacity = value; setDirty(); } - //! subLine opacity - virtual qreal subLineOpacity( void ) const + //* subLine opacity + qreal subLineOpacity( void ) const { return _subLineData._opacity; } - //! mouse position + //* mouse position QPoint position( void ) const { return _position; } protected Q_SLOTS: - //! clear addLineRect + //* clear addLineRect void clearAddLineRect( void ) { if( addLineAnimation().data()->direction() == Animation::Backward ) { _addLineData._rect = QRect(); } } - //! clear subLineRect + //* clear subLineRect void clearSubLineRect( void ) { if( subLineAnimation().data()->direction() == Animation::Backward ) { _subLineData._rect = QRect(); } } - protected: + private: - //! hoverMoveEvent - virtual void hoverMoveEvent( QObject*, QEvent* ); + //* hoverMoveEvent + void hoverMoveEvent( QObject*, QEvent* ); - //! hoverMoveEvent - virtual void hoverLeaveEvent( QObject*, QEvent* ); + //* hoverMoveEvent + void hoverLeaveEvent( QObject*, QEvent* ); - //!@name hover flags + //*@name hover flags //@{ - virtual bool addLineArrowHovered( void ) const + bool addLineArrowHovered( void ) const { return _addLineData._hovered; } - virtual void setAddLineArrowHovered( bool value ) + void setAddLineArrowHovered( bool value ) { _addLineData._hovered = value; } - virtual bool subLineArrowHovered( void ) const + bool subLineArrowHovered( void ) const { return _subLineData._hovered; } - virtual void setSubLineArrowHovered( bool value ) + void setSubLineArrowHovered( bool value ) { _subLineData._hovered = value; } //@} - //! update add line arrow - virtual void updateAddLineArrow( QStyle::SubControl ); + //* update add line arrow + void updateAddLineArrow( QStyle::SubControl ); - //! update sub line arrow - virtual void updateSubLineArrow( QStyle::SubControl ); + //* update sub line arrow + void updateSubLineArrow( QStyle::SubControl ); - //!@name timelines + //*@name timelines //@{ - virtual const Animation::Pointer& addLineAnimation( void ) const + const Animation::Pointer& addLineAnimation( void ) const { return _addLineData._animation; } - virtual const Animation::Pointer& subLineAnimation( void ) const + const Animation::Pointer& subLineAnimation( void ) const { return _subLineData._animation; } - private: - - //! stores arrow data + //* stores arrow data class Data { public: - //! constructor + //* constructor Data( void ): _hovered( false ), _opacity( AnimationData::OpacityInvalid ) {} - //! true if hovered + //* true if hovered bool _hovered; - //! animation + //* animation Animation::Pointer _animation; - //! opacity + //* opacity qreal _opacity; - //! rect + //* rect QRect _rect; }; - //! add line data (down arrow) + //* add line data (down arrow) Data _addLineData; - //! subtract line data (up arrow) + //* subtract line data (up arrow) Data _subLineData; - //! mouse position + //* mouse position QPoint _position; }; } #endif diff --git a/kstyle/animations/oxygenscrollbarengine.h b/kstyle/animations/oxygenscrollbarengine.h index 1d49ede7..3ba4716d 100644 --- a/kstyle/animations/oxygenscrollbarengine.h +++ b/kstyle/animations/oxygenscrollbarengine.h @@ -1,135 +1,131 @@ #ifndef oxygenscrollbarengine_h #define oxygenscrollbarengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenscrollbarengine.h // stores event filters and maps widgets to timelines for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenscrollbardata.h" namespace Oxygen { - //! stores scrollbar hovered action and timeLine + //* stores scrollbar hovered action and timeLine class ScrollBarEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit ScrollBarEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~ScrollBarEngine( void ) - {} - - //! register scrollbar - virtual bool registerWidget( QWidget* ); + //* register scrollbar + bool registerWidget( QWidget* ); - //! true if widget is animated - virtual bool isAnimated( const QObject* object, QStyle::SubControl control ); + //* true if widget is animated + bool isAnimated( const QObject* object, QStyle::SubControl control ); - //! animation opacity - virtual qreal opacity( const QObject* object, QStyle::SubControl control ) + //* animation opacity + qreal opacity( const QObject* object, QStyle::SubControl control ) { return isAnimated( object, control ) ? _data.find( object ).data()->opacity( control ):AnimationData::OpacityInvalid; } - //! return true if given subcontrol is hovered - virtual bool isHovered( const QObject* object, QStyle::SubControl control ) + //* return true if given subcontrol is hovered + bool isHovered( const QObject* object, QStyle::SubControl control ) { if( DataMap::Value data = _data.find( object ) ) return data.data()->isHovered( control ); else return false; } - //! control rect associated to object - virtual QRect subControlRect( const QObject* object, QStyle::SubControl control ) + //* control rect associated to object + QRect subControlRect( const QObject* object, QStyle::SubControl control ) { if( DataMap::Value data = _data.find( object ) ) return data.data()->subControlRect( control ); else return QRect(); } - //! control rect - virtual void setSubControlRect( const QObject* object, QStyle::SubControl control, const QRect& rect ) + //* control rect + void setSubControlRect( const QObject* object, QStyle::SubControl control, const QRect& rect ) { if( DataMap::Value data = _data.find( object ) ) { data.data()->setSubControlRect( control, rect ); } } - //! control rect - virtual void updateState( const QObject* object, bool state ) + //* control rect + void updateState( const QObject* object, bool state ) { if( DataMap::Value data = _data.find( object ) ) { data.data()->updateState( state ); } } - //! mouse position - virtual QPoint position( const QObject* object ) + //* mouse position + QPoint position( const QObject* object ) { if( DataMap::Value data = _data.find( object ) ) return data.data()->position(); else return QPoint( -1, -1 ); } - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); /* do not disable the map directly, because the contained OxygenScrollbarData are also used in non animated mode to store scrollbar arrows rect. However do disable all contains DATA object, in order to prevent actual animations */ foreach( const DataMap::Value data, _data ) { if( data ) data.data()->setEnabled( value ); } } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! data map + //* data map DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygenspinboxdata.h b/kstyle/animations/oxygenspinboxdata.h index b8ced0a1..43e143e6 100644 --- a/kstyle/animations/oxygenspinboxdata.h +++ b/kstyle/animations/oxygenspinboxdata.h @@ -1,170 +1,166 @@ #ifndef oxygenspinbox_data_h #define oxygenspinbox_data_h ////////////////////////////////////////////////////////////////////////////// // oxygenspinboxdata.h // spinbox data container for up/down arrow hover (mouse-over) animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimationdata.h" #include namespace Oxygen { - //! handles spinbox arrows hover + //* handles spinbox arrows hover class SpinBoxData: public AnimationData { Q_OBJECT - //! declare opacity property + //* declare opacity property Q_PROPERTY( qreal upArrowOpacity READ upArrowOpacity WRITE setUpArrowOpacity ) Q_PROPERTY( qreal downArrowOpacity READ downArrowOpacity WRITE setDownArrowOpacity ) public: - //! constructor + //* constructor SpinBoxData( QObject*, QWidget*, int ); - //! destructor - virtual ~SpinBoxData( void ) - {} - - //! animation state - virtual bool updateState( QStyle::SubControl subControl, bool value ) + //* animation state + bool updateState( QStyle::SubControl subControl, bool value ) { if( subControl == QStyle::SC_SpinBoxUp ) return _upArrowData.updateState( value ); else if( subControl == QStyle::SC_SpinBoxDown ) return _downArrowData.updateState( value ); else return false; } - //! animation state - virtual bool isAnimated( QStyle::SubControl subControl ) const + //* animation state + bool isAnimated( QStyle::SubControl subControl ) const { return( ( subControl == QStyle::SC_SpinBoxUp && upArrowAnimation().data()->isRunning() ) || ( subControl == QStyle::SC_SpinBoxDown && downArrowAnimation().data()->isRunning() ) ); } - //! opacity - virtual qreal opacity( QStyle::SubControl subControl ) const + //* opacity + qreal opacity( QStyle::SubControl subControl ) const { if( subControl == QStyle::SC_SpinBoxUp ) return upArrowOpacity(); else if( subControl == QStyle::SC_SpinBoxDown ) return downArrowOpacity(); else return OpacityInvalid; } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { upArrowAnimation().data()->setDuration( duration ); downArrowAnimation().data()->setDuration( duration ); } - //!@name up arrow animation + //*@name up arrow animation //@{ - //! opacity + //* opacity qreal upArrowOpacity( void ) const { return _upArrowData._opacity; } - //! opacity + //* opacity void setUpArrowOpacity( qreal value ) { value = digitize( value ); if( _upArrowData._opacity == value ) return; _upArrowData._opacity = value; setDirty(); } - //! animation + //* animation Animation::Pointer upArrowAnimation( void ) const { return _upArrowData._animation; } //@} - //!@name down arrow animation + //*@name down arrow animation //@{ - //! opacity + //* opacity qreal downArrowOpacity( void ) const { return _downArrowData._opacity; } - //! opacity + //* opacity void setDownArrowOpacity( qreal value ) { value = digitize( value ); if( _downArrowData._opacity == value ) return; _downArrowData._opacity = value; setDirty(); } - //! animation + //* animation Animation::Pointer downArrowAnimation( void ) const { return _downArrowData._animation; } //@} private: - //! container for needed animation data + //* container for needed animation data class Data { public: - //! default constructor + //* default constructor Data( void ): _state( false ), _opacity(0) {} - //! state + //* state bool updateState( bool ); - //! arrow state + //* arrow state bool _state; - //! animation + //* animation Animation::Pointer _animation; - //! opacity + //* opacity qreal _opacity; }; - //! up arrow data + //* up arrow data Data _upArrowData; - //! down arrow data + //* down arrow data Data _downArrowData; }; } #endif diff --git a/kstyle/animations/oxygenspinboxengine.h b/kstyle/animations/oxygenspinboxengine.h index 37dc50f8..f46d9831 100644 --- a/kstyle/animations/oxygenspinboxengine.h +++ b/kstyle/animations/oxygenspinboxengine.h @@ -1,115 +1,111 @@ #ifndef oxygenspinboxengine_h #define oxygenspinboxengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenspinboxengine.h // stores event filters and maps widgets to animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenspinboxdata.h" namespace Oxygen { - //! handle spinbox arrows hover effect + //* handle spinbox arrows hover effect class SpinBoxEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit SpinBoxEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~SpinBoxEngine( void ) - {} - - //! register widget - virtual bool registerWidget( QWidget* ); + //* register widget + bool registerWidget( QWidget* ); - //! state - virtual bool updateState( const QObject* object, QStyle::SubControl subControl, bool value ) + //* state + bool updateState( const QObject* object, QStyle::SubControl subControl, bool value ) { if( DataMap::Value data = _data.find( object ) ) { return data.data()->updateState( subControl, value ); } else return false; } - //! true if widget is animated - virtual bool isAnimated( const QObject* object, QStyle::SubControl subControl ) + //* true if widget is animated + bool isAnimated( const QObject* object, QStyle::SubControl subControl ) { if( DataMap::Value data = _data.find( object ) ) { return data.data()->isAnimated( subControl ); } else return false; } - //! animation opacity - virtual qreal opacity( const QObject* object, QStyle::SubControl subControl ) + //* animation opacity + qreal opacity( const QObject* object, QStyle::SubControl subControl ) { if( DataMap::Value data = _data.find( object ) ) { return data.data()->opacity( subControl ); } else return AnimationData::OpacityInvalid; } - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! data map + //* data map DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygensplitterengine.h b/kstyle/animations/oxygensplitterengine.h index 929972e0..38d5ea7e 100644 --- a/kstyle/animations/oxygensplitterengine.h +++ b/kstyle/animations/oxygensplitterengine.h @@ -1,116 +1,110 @@ #ifndef oxygensplitterengine_h #define oxygensplitterengine_h ////////////////////////////////////////////////////////////////////////////// // oxygensplitterengine.h // QSplitter engine // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenwidgetstatedata.h" namespace Oxygen { - //! QSplitter animation engine + //* QSplitter animation engine class SplitterEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit SplitterEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~SplitterEngine( void ) - {} - - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } - //! register widget - virtual bool registerWidget( QWidget* ); + //* register widget + bool registerWidget( QWidget* ); - //! true if widget hover state is changed - virtual bool updateState( const QPaintDevice*, bool ); + //* true if widget hover state is changed + bool updateState( const QPaintDevice*, bool ); - //! true if widget is animated - virtual bool isAnimated( const QPaintDevice* ); + //* true if widget is animated + bool isAnimated( const QPaintDevice* ); - //! animation opacity - virtual qreal opacity( const QPaintDevice* object ) + //* animation opacity + qreal opacity( const QPaintDevice* object ) { return isAnimated( object ) ? data( object ).data()->opacity(): AnimationData::OpacityInvalid; } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* data ) + //* remove widget from map + bool unregisterWidget( QObject* data ) override { if( !data ) return false; // reinterpret_cast is safe here since only the address is used to find // data in the map return _data.unregisterWidget( reinterpret_cast(data) ); } - protected: + private: - //! returns data associated to widget + //* returns data associated to widget PaintDeviceDataMap::Value data( const QPaintDevice* object ) { return _data.find( object ).data(); } - private: - - //! engine enability + //* engine enable state bool _enabled; - //! animation duration + //* animation duration int _duration; - //! map + //* map PaintDeviceDataMap _data; }; } #endif diff --git a/kstyle/animations/oxygentabbardata.h b/kstyle/animations/oxygentabbardata.h index d4c90a09..1b113dc8 100644 --- a/kstyle/animations/oxygentabbardata.h +++ b/kstyle/animations/oxygentabbardata.h @@ -1,151 +1,147 @@ #ifndef oxygentabbar_data_h #define oxygentabbar_data_h /************************************************************************* * Copyright (C) 2014 by Hugo Pereira Da Costa * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ #include "oxygenanimationdata.h" #include namespace Oxygen { //* tabbars class TabBarData: public AnimationData { Q_OBJECT //* declare opacity property Q_PROPERTY( qreal currentOpacity READ currentOpacity WRITE setCurrentOpacity ) Q_PROPERTY( qreal previousOpacity READ previousOpacity WRITE setPreviousOpacity ) public: //* constructor TabBarData( QObject* parent, QWidget* target, int duration ); - //* destructor - virtual ~TabBarData( void ) - {} - //* duration - void setDuration( int duration ) + void setDuration( int duration ) override { currentIndexAnimation().data()->setDuration( duration ); previousIndexAnimation().data()->setDuration( duration ); } //* update state bool updateState( const QPoint&, bool ); //*@name current index handling //@{ //* current opacity - virtual qreal currentOpacity( void ) const + qreal currentOpacity( void ) const { return _current._opacity; } //* current opacity - virtual void setCurrentOpacity( qreal value ) + void setCurrentOpacity( qreal value ) { if( _current._opacity == value ) return; _current._opacity = value; setDirty(); } //* current index - virtual int currentIndex( void ) const + int currentIndex( void ) const { return _current._index; } //* current index - virtual void setCurrentIndex( int index ) + void setCurrentIndex( int index ) { _current._index = index; } //* current index animation - virtual const Animation::Pointer& currentIndexAnimation( void ) const + const Animation::Pointer& currentIndexAnimation( void ) const { return _current._animation; } //@} //*@name previous index handling //@{ //* previous opacity - virtual qreal previousOpacity( void ) const + qreal previousOpacity( void ) const { return _previous._opacity; } //* previous opacity - virtual void setPreviousOpacity( qreal value ) + void setPreviousOpacity( qreal value ) { if( _previous._opacity == value ) return; _previous._opacity = value; setDirty(); } //* previous index - virtual int previousIndex( void ) const + int previousIndex( void ) const { return _previous._index; } //* previous index - virtual void setPreviousIndex( int index ) + void setPreviousIndex( int index ) { _previous._index = index; } //* previous index Animation - virtual const Animation::Pointer& previousIndexAnimation( void ) const + const Animation::Pointer& previousIndexAnimation( void ) const { return _previous._animation; } //@} //* return Animation associated to action at given position, if any - virtual Animation::Pointer animation( const QPoint& position ) const; + Animation::Pointer animation( const QPoint& position ) const; //* return opacity associated to action at given position, if any - virtual qreal opacity( const QPoint& position ) const; + qreal opacity( const QPoint& position ) const; private: //* container for needed animation data class Data { public: //* default constructor Data( void ): _opacity(0), _index(-1) {} Animation::Pointer _animation; qreal _opacity; int _index; }; //* current tab animation data (for hover enter animations) Data _current; //* previous tab animations data (for hover leave animations) Data _previous; }; } #endif diff --git a/kstyle/animations/oxygentabbarengine.h b/kstyle/animations/oxygentabbarengine.h index bcca7ddf..940145a6 100644 --- a/kstyle/animations/oxygentabbarengine.h +++ b/kstyle/animations/oxygentabbarengine.h @@ -1,102 +1,98 @@ #ifndef oxygentabbarengine_h #define oxygentabbarengine_h /************************************************************************* * Copyright (C) 2014 by Hugo Pereira Da Costa * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ #include "oxygen.h" #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygentabbardata.h" namespace Oxygen { //* stores tabbar hovered action and timeLine class TabBarEngine: public BaseEngine { Q_OBJECT public: //* constructor explicit TabBarEngine( QObject* parent ): BaseEngine( parent ) {} - //* destructor - virtual ~TabBarEngine( void ) - {} - //* register tabbar - virtual bool registerWidget( QWidget* ); + bool registerWidget( QWidget* ); //* true if widget hover state is changed - virtual bool updateState( const QObject*, const QPoint&, AnimationMode, bool ); + bool updateState( const QObject*, const QPoint&, AnimationMode, bool ); //* true if widget is animated - virtual bool isAnimated( const QObject* object, const QPoint& point, AnimationMode ); + bool isAnimated( const QObject* object, const QPoint& point, AnimationMode ); //* animation opacity - virtual qreal opacity( const QObject* object, const QPoint& point, AnimationMode mode ) + qreal opacity( const QObject* object, const QPoint& point, AnimationMode mode ) { return isAnimated( object, point, mode ) ? data( object, mode ).data()->opacity( point ) : AnimationData::OpacityInvalid; } - //* enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _hoverData.setEnabled( value ); _focusData.setEnabled( value ); } //* duration - void setDuration( int value ) + void setDuration( int value ) override { BaseEngine::setDuration( value ); _hoverData.setDuration( value ); _focusData.setDuration( value ); } public Q_SLOTS: //* remove widget from map - bool unregisterWidget( QObject* object ) + bool unregisterWidget( QObject* object ) override { if( !object ) return false; bool found = false; if( _hoverData.unregisterWidget( object ) ) found = true; if( _focusData.unregisterWidget( object ) ) found = true; return found; } private: //* returns data associated to widget DataMap::Value data( const QObject*, AnimationMode ); //* data map DataMap _hoverData; DataMap _focusData; }; } #endif diff --git a/kstyle/animations/oxygentoolbardata.h b/kstyle/animations/oxygentoolbardata.h index 7de4c932..ab8ef94b 100644 --- a/kstyle/animations/oxygentoolbardata.h +++ b/kstyle/animations/oxygentoolbardata.h @@ -1,219 +1,217 @@ #ifndef oxygentoolbar_data_h #define oxygentoolbar_data_h ////////////////////////////////////////////////////////////////////////////// // oxygentoolbardata.h // stores event filters and maps widgets to timelines for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimationdata.h" #include namespace Oxygen { - //! toolbar data + //* toolbar data class ToolBarData: public AnimationData { Q_OBJECT Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) Q_PROPERTY( qreal progress READ progress WRITE setProgress ) public: - //! constructor + //* constructor ToolBarData( QObject* parent, QWidget* target, int duration ); - //! destructor - virtual ~ToolBarData( void ) - {} + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! event filter - bool eventFilter( QObject*, QEvent* ) ; - - //! return animation associated to action at given position, if any - virtual const Animation::Pointer& animation( void ) const + //* return animation associated to action at given position, if any + const Animation::Pointer& animation( void ) const { return _animation; } - //! return animation associated to action at given position, if any - virtual const Animation::Pointer& progressAnimation( void ) const + //* return animation associated to action at given position, if any + const Animation::Pointer& progressAnimation( void ) const { return _progressAnimation; } - //! duration - void setDuration( int duration ) + //* duration + void setDuration( int duration ) override { animation().data()->setDuration( duration ); } - //! duration - virtual void setFollowMouseDuration( int duration ) + //* duration + void setFollowMouseDuration( int duration ) { progressAnimation().data()->setDuration( duration ); } - //! return 'hover' rect position when widget is animated - virtual const QRect& animatedRect( void ) const + //* return 'hover' rect position when widget is animated + const QRect& animatedRect( void ) const { return _animatedRect; } - //! current rect - virtual const QRect& currentRect( void ) const + //* current rect + const QRect& currentRect( void ) const { return _currentRect; } - //! timer + //* timer const QBasicTimer& timer( void ) const { return _timer; } - //! animation opacity - virtual qreal opacity( void ) const + //* animation opacity + qreal opacity( void ) const { return _opacity; } - //! animation opacity - virtual void setOpacity( qreal value ) + //* animation opacity + void setOpacity( qreal value ) { value = digitize( value ); if( _opacity == value ) return; _opacity = value; setDirty(); } - //! animation progress - virtual qreal progress( void ) const + //* animation progress + qreal progress( void ) const { return _progress; } - //! animation progress - virtual void setProgress( qreal value ) + //* animation progress + void setProgress( qreal value ) { value = digitize( value ); if( _progress == value ) return; _progress = value; updateAnimatedRect(); } protected Q_SLOTS: - //! updated animated rect - virtual void updateAnimatedRect( void ); + //* updated animated rect + void updateAnimatedRect( void ); protected: - //! timer event - void timerEvent( QTimerEvent *) ; + //* timer event + void timerEvent( QTimerEvent *) override; + + private: - //!@name current object handling + //*@name current object handling //@{ - //! object pointer + //* object pointer /*! there is no need to guard it because the object contents is never accessed */ using ObjectPointer = const QObject*; - //! current object - virtual const ObjectPointer& currentObject( void ) const + //* current object + const ObjectPointer& currentObject( void ) const { return _currentObject; } - //! current object - virtual void setCurrentObject( const QObject* object ) + //* current object + void setCurrentObject( const QObject* object ) { _currentObject = ObjectPointer( object ); } - //! current object - virtual void clearCurrentObject( void ) + //* current object + void clearCurrentObject( void ) { _currentObject = NULL; } //@} - //!@name rect handling + //*@name rect handling //@{ - //! current rect - virtual void setCurrentRect( const QRect& rect ) + //* current rect + void setCurrentRect( const QRect& rect ) { _currentRect = rect; } - //! current rect - virtual void clearCurrentRect( void ) + //* current rect + void clearCurrentRect( void ) { _currentRect = QRect(); } - //! previous rect - virtual const QRect& previousRect( void ) const + //* previous rect + const QRect& previousRect( void ) const { return _previousRect; } - //! previous rect - virtual void setPreviousRect( const QRect& rect ) + //* previous rect + void setPreviousRect( const QRect& rect ) { _previousRect = rect; } - //! previous rect - virtual void clearPreviousRect( void ) + //* previous rect + void clearPreviousRect( void ) { _previousRect = QRect(); } - //! animated rect - virtual void clearAnimatedRect( void ) + //* animated rect + void clearAnimatedRect( void ) { _animatedRect = QRect(); } //@} - //! toolbar enterEvent - virtual void enterEvent( const QObject* ); + //* toolbar enterEvent + void enterEvent( const QObject* ); - //! toolbar enterEvent - virtual void leaveEvent( const QObject* ); + //* toolbar enterEvent + void leaveEvent( const QObject* ); - //! toolbutton added - virtual void childAddedEvent( QObject* ); + //* toolbutton added + void childAddedEvent( QObject* ); - //! toolbutton enter event - virtual void childEnterEvent( const QObject* ); + //* toolbutton enter event + void childEnterEvent( const QObject* ); private: - //! fade animation + //* fade animation Animation::Pointer _animation; - //! progress animation + //* progress animation Animation::Pointer _progressAnimation; - //! opacity + //* opacity qreal _opacity; - //! opacity + //* opacity qreal _progress; - //! timer + //* timer /*! this allows to add some delay before starting leaveEvent animation */ QBasicTimer _timer; - //! current object + //* current object ObjectPointer _currentObject; - //! current rect + //* current rect QRect _currentRect; - //! previous rect + //* previous rect QRect _previousRect; - //! animated rect + //* animated rect QRect _animatedRect; - //! true if toolbar was entered at least once (this prevents some initialization glitches) + //* true if toolbar was entered at least once (this prevents some initialization glitches) bool _entered; }; } #endif diff --git a/kstyle/animations/oxygentoolbarengine.h b/kstyle/animations/oxygentoolbarengine.h index a3dfe308..06402d9f 100644 --- a/kstyle/animations/oxygentoolbarengine.h +++ b/kstyle/animations/oxygentoolbarengine.h @@ -1,124 +1,120 @@ #ifndef oxygentoolbarengine_h #define oxygentoolbarengine_h ////////////////////////////////////////////////////////////////////////////// // oxygentoolbarengine.h // stores event filters and maps widgets to timelines for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygentoolbardata.h" namespace Oxygen { - //! follow-mouse toolbar animation + //* follow-mouse toolbar animation class ToolBarEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit ToolBarEngine( QObject* parent ): BaseEngine( parent ), _followMouseDuration( 150 ) {} - //! destructor - virtual ~ToolBarEngine( void ) - {} - - //! register toolbar - virtual void registerWidget( QWidget* ); + //* register toolbar + void registerWidget( QWidget* ); - //! returns registered widgets - WidgetList registeredWidgets( void ) const ; + //* returns registered widgets + WidgetList registeredWidgets( void ) const override; - //! return true if object is animated - virtual bool isAnimated( const QObject* ); + //* return true if object is animated + bool isAnimated( const QObject* ); - //! return true if object is animated - virtual bool isFollowMouseAnimated( const QObject* ); + //* return true if object is animated + bool isFollowMouseAnimated( const QObject* ); - //! animation opacity - virtual qreal opacity( const QObject* object ) + //* animation opacity + qreal opacity( const QObject* object ) { return isAnimated( object ) ? _data.find( object ).data()->opacity(): AnimationData::OpacityInvalid; } - //! return 'hover' rect position when widget is animated - virtual QRect currentRect( const QObject* ); + //* return 'hover' rect position when widget is animated + QRect currentRect( const QObject* ); - //! return 'hover' rect position when widget is animated - virtual QRect animatedRect( const QObject* ); + //* return 'hover' rect position when widget is animated + QRect animatedRect( const QObject* ); - //! timer - virtual bool isTimerActive( const QObject* ); + //* timer + bool isTimerActive( const QObject* ); - //! enability - void setEnabled( bool value ) + //* enable state + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } - //! duration - virtual int followMouseDuration( void ) const + //* duration + int followMouseDuration( void ) const { return _followMouseDuration; } - //! duration - virtual void setFollowMouseDuration( int duration ) + //* duration + void setFollowMouseDuration( int duration ) { _followMouseDuration = duration; foreach( const DataMap::Value& value, _data ) { if( value ) value.data()->setFollowMouseDuration( duration ); } } protected Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! follow mouse animation duration - int _followMouseDuration; + //* follow mouse animation duration + int _followMouseDuration = -1; - //! data map + //* data map DataMap _data; }; } #endif diff --git a/kstyle/animations/oxygentoolboxengine.h b/kstyle/animations/oxygentoolboxengine.h index a82ead14..42dd79a1 100644 --- a/kstyle/animations/oxygentoolboxengine.h +++ b/kstyle/animations/oxygentoolboxengine.h @@ -1,110 +1,106 @@ #ifndef oxygentoolboxengine_h #define oxygentoolboxengine_h ////////////////////////////////////////////////////////////////////////////// // oxygentoolboxengine.h // QToolBox engine // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenwidgetstatedata.h" namespace Oxygen { //* QToolBox animation engine class ToolBoxEngine: public BaseEngine { Q_OBJECT public: //* constructor explicit ToolBoxEngine( QObject* parent ): BaseEngine( parent ) {} - //* destructor - virtual ~ToolBoxEngine( void ) - {} - //* enability - void setEnabled( bool value ) + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } //* duration - void setDuration( int value ) + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } //* register widget - virtual bool registerWidget( QWidget* ); + bool registerWidget( QWidget* ); //* true if widget hover state is changed - virtual bool updateState( const QPaintDevice*, bool ); + bool updateState( const QPaintDevice*, bool ); //* true if widget is animated - virtual bool isAnimated( const QPaintDevice* ); + bool isAnimated( const QPaintDevice* ); //* animation opacity - virtual qreal opacity( const QPaintDevice* object ) + qreal opacity( const QPaintDevice* object ) { return isAnimated( object ) ? data( object ).data()->opacity(): AnimationData::OpacityInvalid; } public Q_SLOTS: //* remove widget from map - bool unregisterWidget( QObject* data ) + bool unregisterWidget( QObject* data ) override { if( !data ) return false; // reinterpret_cast is safe here since only the address is used to find // data in the map return _data.unregisterWidget( reinterpret_cast(data) ); } protected: //* returns data associated to widget PaintDeviceDataMap::Value data( const QPaintDevice* object ) { return _data.find( object ).data(); } private: //* map PaintDeviceDataMap _data; }; } #endif diff --git a/kstyle/animations/oxygenwidgetstatedata.h b/kstyle/animations/oxygenwidgetstatedata.h index 6090f1df..193cfa9a 100644 --- a/kstyle/animations/oxygenwidgetstatedata.h +++ b/kstyle/animations/oxygenwidgetstatedata.h @@ -1,67 +1,63 @@ #ifndef oxygenwidgetstatedata_h #define oxygenwidgetstatedata_h ////////////////////////////////////////////////////////////////////////////// // oxygenwidgetstatedata.h // generic data container for widgetstate hover (mouse-over) animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygengenericdata.h" namespace Oxygen { - //! handle widget state (hover/focus/enable) changes + //* handle widget state (hover/focus/enable) changes class WidgetStateData: public GenericData { Q_OBJECT public: - //! constructor + //* constructor WidgetStateData( QObject* parent, QWidget* target, int duration, bool state = false ): GenericData( parent, target, duration ), _state( state ) {} - //! destructor - virtual ~WidgetStateData( void ) - {} - - /*! + /** returns true if hover has Changed and starts timer accordingly */ - virtual bool updateState( bool value ); + bool updateState( bool value ); private: - bool _state; + bool _state = false; }; } #endif diff --git a/kstyle/animations/oxygenwidgetstateengine.h b/kstyle/animations/oxygenwidgetstateengine.h index d39931b3..cdadf7e0 100644 --- a/kstyle/animations/oxygenwidgetstateengine.h +++ b/kstyle/animations/oxygenwidgetstateengine.h @@ -1,160 +1,154 @@ #ifndef oxygenwidgetstateengine_h #define oxygenwidgetstateengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenwidgetstateengine.h // stores event filters and maps widgets to animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenwidgetstatedata.h" #include "oxygen.h" namespace Oxygen { //* used for simple widgets class WidgetStateEngine: public BaseEngine { Q_OBJECT public: //* constructor explicit WidgetStateEngine( QObject* parent ): BaseEngine( parent ) {} - //* destructor - virtual ~WidgetStateEngine( void ) - {} - //* register widget - virtual bool registerWidget( QWidget*, AnimationModes ); + bool registerWidget( QWidget*, AnimationModes ); //* returns registered widgets - virtual WidgetList registeredWidgets( AnimationModes ) const; + WidgetList registeredWidgets( AnimationModes ) const; using BaseEngine::registeredWidgets; //* true if widget hover state is changed - virtual bool updateState( const QObject*, AnimationMode, bool ); + bool updateState( const QObject*, AnimationMode, bool ); //* true if widget is animated - virtual bool isAnimated( const QObject*, AnimationMode ); + bool isAnimated( const QObject*, AnimationMode ); //* animation opacity - virtual qreal opacity( const QObject* object, AnimationMode mode ) + qreal opacity( const QObject* object, AnimationMode mode ) { return isAnimated( object, mode ) ? data( object, mode ).data()->opacity(): AnimationData::OpacityInvalid; } //* animation mode /** precedence on focus */ - virtual AnimationMode frameAnimationMode( const QObject* object ) + AnimationMode frameAnimationMode( const QObject* object ) { if( isAnimated( object, AnimationEnable ) ) return AnimationEnable; else if( isAnimated( object, AnimationFocus ) ) return AnimationFocus; else if( isAnimated( object, AnimationHover ) ) return AnimationHover; else return AnimationNone; } //* animation opacity /** precedence on focus */ - virtual qreal frameOpacity( const QObject* object ) + qreal frameOpacity( const QObject* object ) { if( isAnimated( object, AnimationEnable ) ) return data( object, AnimationEnable ).data()->opacity(); else if( isAnimated( object, AnimationFocus ) ) return data( object, AnimationFocus ).data()->opacity(); else if( isAnimated( object, AnimationHover ) ) return data( object, AnimationHover ).data()->opacity(); else return AnimationData::OpacityInvalid; } //* animation mode /** precedence on mouseOver */ - virtual AnimationMode buttonAnimationMode( const QObject* object ) + AnimationMode buttonAnimationMode( const QObject* object ) { if( isAnimated( object, AnimationEnable ) ) return AnimationEnable; else if( isAnimated( object, AnimationHover ) ) return AnimationHover; else if( isAnimated( object, AnimationFocus ) ) return AnimationFocus; else return AnimationNone; } //* animation opacity /** precedence on mouseOver */ - virtual qreal buttonOpacity( const QObject* object ) + qreal buttonOpacity( const QObject* object ) { if( isAnimated( object, AnimationEnable ) ) return data( object, AnimationEnable ).data()->opacity(); else if( isAnimated( object, AnimationHover ) ) return data( object, AnimationHover ).data()->opacity(); else if( isAnimated( object, AnimationFocus ) ) return data( object, AnimationFocus ).data()->opacity(); else return AnimationData::OpacityInvalid; } //* duration - void setEnabled( bool value ) + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _hoverData.setEnabled( value ); _focusData.setEnabled( value ); _enableData.setEnabled( value ); } //* duration - void setDuration( int value ) + void setDuration( int value ) override { BaseEngine::setDuration( value ); _hoverData.setDuration( value ); _focusData.setDuration( value ); _enableData.setDuration( value ); } public Q_SLOTS: //* remove widget from map - bool unregisterWidget( QObject* object ) + bool unregisterWidget( QObject* object ) override { if( !object ) return false; bool found = false; if( _hoverData.unregisterWidget( object ) ) found = true; if( _focusData.unregisterWidget( object ) ) found = true; if( _enableData.unregisterWidget( object ) ) found = true; return found; } - protected: + private: //* returns data associated to widget DataMap::Value data( const QObject*, AnimationMode ); - private: - //* maps DataMap _hoverData; DataMap _focusData; DataMap _enableData; }; } #endif diff --git a/kstyle/config/oxygenanimationconfigwidget.cpp b/kstyle/config/oxygenanimationconfigwidget.cpp index abb79acc..cb46a629 100644 --- a/kstyle/config/oxygenanimationconfigwidget.cpp +++ b/kstyle/config/oxygenanimationconfigwidget.cpp @@ -1,283 +1,279 @@ ////////////////////////////////////////////////////////////////////////////// // oxygenanimationconfigwidget.cpp // animation configuration widget // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimationconfigwidget.h" #include "oxygenanimationconfigitem.h" #include "oxygenfollowmouseanimationconfigitem.h" #include "oxygengenericanimationconfigitem.h" #include "oxygenstyleconfigdata.h" #include #include #include #include namespace Oxygen { //_______________________________________________ AnimationConfigWidget::AnimationConfigWidget( QWidget* parent ): BaseAnimationConfigWidget( parent ) { QGridLayout* layout( qobject_cast( BaseAnimationConfigWidget::layout() ) ); setupItem( layout, _genericAnimations = new GenericAnimationConfigItem( this, i18n("Focus, mouseover and widget state transition"), i18n("Configure widgets' focus and mouseover highlight animation, as well as widget enabled/disabled state transition") ) ); setupItem( layout, _toolBarAnimations = new FollowMouseAnimationConfigItem( this, i18n("Toolbar highlight" ), i18n("Configure toolbars' mouseover highlight animation" ) ) ); _toolBarAnimations->hideDurationSpinBox(); setupItem( layout, _menuBarAnimations = new FollowMouseAnimationConfigItem( this, i18n("Menu bar highlight" ), i18n("Configure menu bars' mouseover highlight animation" ) ) ); setupItem( layout, _menuAnimations = new FollowMouseAnimationConfigItem( this, i18n("Menu highlight" ), i18n("Configure menus' mouseover highlight animation" ) ) ); setupItem( layout, _progressBarAnimations = new GenericAnimationConfigItem( this, i18n( "Progress bar animation" ), i18n( "Configure progress bars' steps animation" ) ) ); setupItem( layout, _stackedWidgetAnimations = new GenericAnimationConfigItem( this, i18n( "Tab transitions" ), i18n( "Configure fading transition between tabs" ) ) ); setupItem( layout, _labelAnimations = new GenericAnimationConfigItem( this, i18n( "Label transitions" ), i18n( "Configure fading transition when a label's text is changed" ) ) ); setupItem( layout, _lineEditAnimations = new GenericAnimationConfigItem( this, i18n( "Text editor transitions" ), i18n( "Configure fading transition when an editor's text is changed" ) ) ); setupItem( layout, _comboBoxAnimations = new GenericAnimationConfigItem( this, i18n( "Combo box transitions" ), i18n( "Configure fading transition when a combo box's selected choice is changed" ) ) ); // add a separator QFrame* frame = new QFrame( this ); frame->setFrameStyle( QFrame::HLine|QFrame::Sunken ); layout->addWidget( frame, _row, 0, 1, 2 ); ++_row; // progress bar busy animation setupItem( layout, _progressBarBusyAnimations = new GenericAnimationConfigItem( this, i18n( "Progress bar busy indicator" ), i18n( "Configure progress bars' busy indicator animation" ) ) ); // add spacers to the first column, previous row to finalize layout layout->addItem( new QSpacerItem( 25, 0 ), _row-1, 0, 1, 1 ); // add vertical spacer layout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding ), _row, 1, 1, 1 ); ++_row; connect( animationsEnabled(), SIGNAL(toggled(bool)), SLOT(updateChanged()) ); foreach( AnimationConfigItem* item, findChildren() ) { if( item != _progressBarBusyAnimations ) { item->QWidget::setEnabled( false ); connect( animationsEnabled(), SIGNAL(toggled(bool)), item, SLOT(setEnabled(bool)) ); } } } - //_______________________________________________ - AnimationConfigWidget::~AnimationConfigWidget( void ) - {} - //_______________________________________________ void AnimationConfigWidget::load( void ) { animationsEnabled()->setChecked( StyleConfigData::animationsEnabled() ); _genericAnimations->setEnabled( StyleConfigData::genericAnimationsEnabled() ); _genericAnimations->setDuration( StyleConfigData::genericAnimationsDuration() ); _toolBarAnimations->setEnabled( StyleConfigData::toolBarAnimationType() != StyleConfigData::TB_NONE ); _toolBarAnimations->setDuration( StyleConfigData::genericAnimationsDuration() ); _toolBarAnimations->setFollowMouseDuration( StyleConfigData::toolBarAnimationsDuration() ); switch( StyleConfigData::toolBarAnimationType() ) { case StyleConfigData::TB_FOLLOW_MOUSE: _toolBarAnimations->setType( 1 ); break; case StyleConfigData::TB_FADE: default: _toolBarAnimations->setType( 0 ); break; } _menuBarAnimations->setEnabled( StyleConfigData::menuBarAnimationType() != StyleConfigData::MB_NONE ); _menuBarAnimations->setDuration( StyleConfigData::menuBarAnimationsDuration() ); _menuBarAnimations->setFollowMouseDuration( StyleConfigData::menuBarFollowMouseAnimationsDuration() ); switch( StyleConfigData::menuBarAnimationType() ) { case StyleConfigData::MB_FOLLOW_MOUSE: _menuBarAnimations->setType( 1 ); break; case StyleConfigData::MB_FADE: default: _menuBarAnimations->setType( 0 ); break; } _menuAnimations->setEnabled( StyleConfigData::menuAnimationType() != StyleConfigData::ME_NONE ); _menuAnimations->setDuration( StyleConfigData::menuAnimationsDuration() ); _menuAnimations->setFollowMouseDuration( StyleConfigData::menuFollowMouseAnimationsDuration() ); switch( StyleConfigData::menuAnimationType() ) { case StyleConfigData::ME_FOLLOW_MOUSE: _menuAnimations->setType( 1 ); break; case StyleConfigData::ME_FADE: default: _menuAnimations->setType( 0 ); break; } _progressBarAnimations->setEnabled( StyleConfigData::progressBarAnimationsEnabled() ); _progressBarAnimations->setDuration( StyleConfigData::progressBarAnimationsDuration() ); _progressBarBusyAnimations->setEnabled( StyleConfigData::progressBarAnimated() ); _progressBarBusyAnimations->setDuration( StyleConfigData::progressBarBusyStepDuration() ); _stackedWidgetAnimations->setEnabled( StyleConfigData::stackedWidgetTransitionsEnabled() ); _stackedWidgetAnimations->setDuration( StyleConfigData::stackedWidgetTransitionsDuration() ); _labelAnimations->setEnabled( StyleConfigData::labelTransitionsEnabled() ); _labelAnimations->setDuration( StyleConfigData::labelTransitionsDuration() ); _lineEditAnimations->setEnabled( StyleConfigData::lineEditTransitionsEnabled() ); _lineEditAnimations->setDuration( StyleConfigData::lineEditTransitionsDuration() ); _comboBoxAnimations->setEnabled( StyleConfigData::comboBoxTransitionsEnabled() ); _comboBoxAnimations->setDuration( StyleConfigData::comboBoxTransitionsDuration() ); } //_______________________________________________ void AnimationConfigWidget::save( void ) { StyleConfigData::setAnimationsEnabled( animationsEnabled()->isChecked() ); StyleConfigData::setGenericAnimationsEnabled( _genericAnimations->enabled() ); StyleConfigData::setGenericAnimationsDuration( _genericAnimations->duration() ); StyleConfigData::setToolBarAnimationsDuration( _toolBarAnimations->followMouseDuration() ); if( !_toolBarAnimations->enabled() ) StyleConfigData::setToolBarAnimationType( StyleConfigData::TB_NONE ); else if( _toolBarAnimations->type() == 1 ) StyleConfigData::setToolBarAnimationType( StyleConfigData::TB_FOLLOW_MOUSE ); else StyleConfigData::setToolBarAnimationType( StyleConfigData::TB_FADE ); StyleConfigData::setMenuBarAnimationsDuration( _menuBarAnimations->duration() ); StyleConfigData::setMenuBarFollowMouseAnimationsDuration( _menuBarAnimations->followMouseDuration() ); if( !_menuBarAnimations->enabled() ) StyleConfigData::setMenuBarAnimationType( StyleConfigData::MB_NONE ); else if( _menuBarAnimations->type() == 1 ) StyleConfigData::setMenuBarAnimationType( StyleConfigData::MB_FOLLOW_MOUSE ); else StyleConfigData::setMenuBarAnimationType( StyleConfigData::MB_FADE ); StyleConfigData::setMenuAnimationsDuration( _menuAnimations->duration() ); StyleConfigData::setMenuFollowMouseAnimationsDuration( _menuAnimations->followMouseDuration() ); if( !_menuAnimations->enabled() ) StyleConfigData::setMenuAnimationType( StyleConfigData::ME_NONE ); else if( _menuAnimations->type() == 1 ) StyleConfigData::setMenuAnimationType( StyleConfigData::ME_FOLLOW_MOUSE ); else StyleConfigData::setMenuAnimationType( StyleConfigData::ME_FADE ); StyleConfigData::setProgressBarAnimationsEnabled( _progressBarAnimations->enabled() ); StyleConfigData::setProgressBarAnimationsDuration( _progressBarAnimations->duration() ); StyleConfigData::setProgressBarAnimated( _progressBarBusyAnimations->enabled() ); StyleConfigData::setProgressBarBusyStepDuration( _progressBarBusyAnimations->duration() ); StyleConfigData::setStackedWidgetTransitionsEnabled( _stackedWidgetAnimations->enabled() ); StyleConfigData::setStackedWidgetTransitionsDuration( _stackedWidgetAnimations->duration() ); StyleConfigData::setLabelTransitionsEnabled( _labelAnimations->enabled() ); StyleConfigData::setLabelTransitionsDuration( _labelAnimations->duration() ); StyleConfigData::setLineEditTransitionsEnabled( _lineEditAnimations->enabled() ); StyleConfigData::setLineEditTransitionsDuration( _lineEditAnimations->duration() ); StyleConfigData::setComboBoxTransitionsEnabled( _comboBoxAnimations->enabled() ); StyleConfigData::setComboBoxTransitionsDuration( _comboBoxAnimations->duration() ); setChanged( false ); } //_______________________________________________ void AnimationConfigWidget::updateChanged( void ) { bool modified( false ); if( animationsEnabled()->isChecked() != StyleConfigData::animationsEnabled() ) modified = true; else if( _genericAnimations->enabled() != StyleConfigData::genericAnimationsEnabled() ) modified = true; else if( _genericAnimations->duration() != StyleConfigData::genericAnimationsDuration() ) modified = true; else if( _toolBarAnimations->duration() != StyleConfigData::genericAnimationsDuration() ) modified = true; else if( _toolBarAnimations->followMouseDuration() != StyleConfigData::toolBarAnimationsDuration() ) modified = true; else if( StyleConfigData::toolBarAnimationType() == StyleConfigData::TB_NONE && _toolBarAnimations->enabled() ) modified = true; else if( StyleConfigData::toolBarAnimationType() == StyleConfigData::TB_FOLLOW_MOUSE && !( _toolBarAnimations->type() == 1 && _toolBarAnimations->enabled() ) ) modified = true; else if( StyleConfigData::toolBarAnimationType() == StyleConfigData::TB_FADE && !( _toolBarAnimations->type() == 0 && _toolBarAnimations->enabled() )) modified = true; else if( _menuBarAnimations->duration() != StyleConfigData::menuBarAnimationsDuration() ) modified = true; else if( _menuBarAnimations->followMouseDuration() != StyleConfigData::menuBarFollowMouseAnimationsDuration() ) modified = true; else if( StyleConfigData::menuBarAnimationType() == StyleConfigData::MB_NONE && _menuBarAnimations->enabled() ) modified = true; else if( StyleConfigData::menuBarAnimationType() == StyleConfigData::MB_FOLLOW_MOUSE && !( _menuBarAnimations->type() == 1 && _menuBarAnimations->enabled() ) ) modified = true; else if( StyleConfigData::menuBarAnimationType() == StyleConfigData::MB_FADE && !( _menuBarAnimations->type() == 0 && _menuBarAnimations->enabled() ) ) modified = true; else if( _menuAnimations->duration() != StyleConfigData::menuAnimationsDuration() ) modified = true; else if( _menuAnimations->followMouseDuration() != StyleConfigData::menuFollowMouseAnimationsDuration() ) modified = true; else if( StyleConfigData::menuAnimationType() == StyleConfigData::ME_NONE && _menuAnimations->enabled() ) modified = true; else if( StyleConfigData::menuAnimationType() == StyleConfigData::ME_FOLLOW_MOUSE && !( _menuAnimations->type() == 1 && _menuAnimations->enabled() ) ) modified = true; else if( StyleConfigData::menuAnimationType() == StyleConfigData::ME_FADE && !( _menuAnimations->type() == 0 && _menuAnimations->enabled() ) ) modified = true; else if( _progressBarAnimations->enabled() != StyleConfigData::progressBarAnimationsEnabled() ) modified = true; else if( _progressBarAnimations->duration() != StyleConfigData::progressBarAnimationsDuration() ) modified = true; else if( _progressBarBusyAnimations->enabled() != StyleConfigData::progressBarAnimated() ) modified = true; else if( _progressBarBusyAnimations->duration() != StyleConfigData::progressBarBusyStepDuration() ) modified = true; else if( _stackedWidgetAnimations->enabled() != StyleConfigData::stackedWidgetTransitionsEnabled() ) modified = true; else if( _stackedWidgetAnimations->duration() != StyleConfigData::stackedWidgetTransitionsDuration() ) modified = true; else if( _labelAnimations->enabled() != StyleConfigData::labelTransitionsEnabled() ) modified = true; else if( _labelAnimations->duration() != StyleConfigData::labelTransitionsDuration() ) modified = true; else if( _lineEditAnimations->enabled() != StyleConfigData::lineEditTransitionsEnabled() ) modified = true; else if( _lineEditAnimations->duration() != StyleConfigData::lineEditTransitionsDuration() ) modified = true; else if( _comboBoxAnimations->enabled() != StyleConfigData::comboBoxTransitionsEnabled() ) modified = true; else if( _comboBoxAnimations->duration() != StyleConfigData::comboBoxTransitionsDuration() ) modified = true; setChanged( modified ); } } diff --git a/kstyle/config/oxygenanimationconfigwidget.h b/kstyle/config/oxygenanimationconfigwidget.h index 791ac395..44367149 100644 --- a/kstyle/config/oxygenanimationconfigwidget.h +++ b/kstyle/config/oxygenanimationconfigwidget.h @@ -1,80 +1,77 @@ #ifndef oxygenanimationconfigwidget_h #define oxygenanimationconfigwidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenanimationconfigwidget.h // animation configuration item // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseanimationconfigwidget.h" namespace Oxygen { class GenericAnimationConfigItem; class FollowMouseAnimationConfigItem; class AnimationConfigWidget: public BaseAnimationConfigWidget { Q_OBJECT public: - //! constructor + //* constructor explicit AnimationConfigWidget( QWidget* = 0 ); - //! destructor - virtual ~AnimationConfigWidget( void ); - public Q_SLOTS: - //! read current configuration - void load( void ) ; + //* read current configuration + void load( void ) override; - //! save current configuration - void save( void ) ; + //* save current configuration + void save( void ) override; protected Q_SLOTS: - //! check whether configuration is changed and emit appropriate signal if yes - void updateChanged() ; + //* check whether configuration is changed and emit appropriate signal if yes + void updateChanged() override; private: GenericAnimationConfigItem* _genericAnimations; GenericAnimationConfigItem* _progressBarAnimations; GenericAnimationConfigItem* _progressBarBusyAnimations; GenericAnimationConfigItem* _stackedWidgetAnimations; GenericAnimationConfigItem* _labelAnimations; GenericAnimationConfigItem* _lineEditAnimations; GenericAnimationConfigItem* _comboBoxAnimations; FollowMouseAnimationConfigItem* _toolBarAnimations; FollowMouseAnimationConfigItem* _menuBarAnimations; FollowMouseAnimationConfigItem* _menuAnimations; }; } #endif diff --git a/kstyle/config/oxygenfollowmouseanimationconfigitem.h b/kstyle/config/oxygenfollowmouseanimationconfigitem.h index ad2f39af..82e33aed 100644 --- a/kstyle/config/oxygenfollowmouseanimationconfigitem.h +++ b/kstyle/config/oxygenfollowmouseanimationconfigitem.h @@ -1,156 +1,153 @@ #ifndef oxygenfollowmouseanimationconfigitem_h #define oxygenfollowmouseanimationconfigitem_h ////////////////////////////////////////////////////////////////////////////// // oxygenanimationconfigitem.h // animation configuration item // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimationconfigitem.h" #include "../oxygen.h" #include #include #include #include class Ui_FollowMouseAnimationConfigBox; namespace Oxygen { class FollowMouseAnimationConfigBox: public QFrame { Q_OBJECT public: - //! constructor + //* constructor explicit FollowMouseAnimationConfigBox(QWidget*); - //! destructor - virtual ~FollowMouseAnimationConfigBox( void ); + //* destructor + ~FollowMouseAnimationConfigBox( void ) override; - //! type ComboBox + //* type ComboBox KComboBox* typeComboBox( void ) const; - //! duration spin box + //* duration spin box QSpinBox* durationSpinBox( void ) const; - //! duration spin box + //* duration spin box QLabel* durationLabel( void ) const; - //! follow mouse duration spinbox + //* follow mouse duration spinbox QSpinBox* followMouseDurationSpinBox( void ) const; - protected Q_SLOTS: + private Q_SLOTS: - //! type changed + //* type changed void typeChanged( int ); private: Ui_FollowMouseAnimationConfigBox* ui; }; - //! generic animation config item + //* generic animation config item class FollowMouseAnimationConfigItem: public AnimationConfigItem { Q_OBJECT public: - //! constructor + //* constructor explicit FollowMouseAnimationConfigItem( QWidget* parent, const QString& title = QString(), const QString& description = QString() ): AnimationConfigItem( parent, title, description ) {} - //! initialize configuration widget - void initializeConfigurationWidget( QWidget* ) ; + //* initialize configuration widget + void initializeConfigurationWidget( QWidget* ) override; - //! configuration widget - QWidget* configurationWidget( void ) const - { - Q_CHECK_PTR( _configurationWidget ); - return _configurationWidget.data(); - } + //* configuration widget + QWidget* configurationWidget( void ) const override + { return _configurationWidget.data(); } - //! type - virtual int type( void ) const + //* type + int type( void ) const { return (_configurationWidget) ? _configurationWidget.data()->typeComboBox()->currentIndex():0; } - //! duration - virtual int duration( void ) const + //* duration + int duration( void ) const { return (_configurationWidget) ? _configurationWidget.data()->durationSpinBox()->value():0; } - //! duration - virtual int followMouseDuration( void ) const + //* duration + int followMouseDuration( void ) const { return (_configurationWidget) ? _configurationWidget.data()->followMouseDurationSpinBox()->value():0; } - //! hide duration spinbox - virtual void hideDurationSpinBox( void ) + //* hide duration spinbox + void hideDurationSpinBox( void ) { if( _configurationWidget ) { _configurationWidget.data()->durationLabel()->hide(); _configurationWidget.data()->durationSpinBox()->hide(); } } public Q_SLOTS: - //! type - virtual void setType( int value ) + //* type + void setType( int value ) { if( _configurationWidget ) { _configurationWidget.data()->typeComboBox()->setCurrentIndex( value ); } } - //! duration - virtual void setDuration( int value ) + //* duration + void setDuration( int value ) { if( _configurationWidget ) { _configurationWidget.data()->durationSpinBox()->setValue( value ); } } - //! follow mouse duration - virtual void setFollowMouseDuration( int value ) + //* follow mouse duration + void setFollowMouseDuration( int value ) { if( _configurationWidget ) { _configurationWidget.data()->followMouseDurationSpinBox()->setValue( value ); } } private: - //! configuration widget + //* configuration widget WeakPointer _configurationWidget; }; } #endif diff --git a/kstyle/config/oxygenstyleconfig.h b/kstyle/config/oxygenstyleconfig.h index 3ec89961..aa3de1b3 100644 --- a/kstyle/config/oxygenstyleconfig.h +++ b/kstyle/config/oxygenstyleconfig.h @@ -1,93 +1,89 @@ #ifndef oxygenstyleconfig_h #define oxygenstyleconfig_h /* Copyright (c) 2010 Hugo Pereira Da Costa Copyright (C) 2003 Sandro Giessl based on the Keramik configuration dialog: Copyright (c) 2003 Maksim Orlovich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "ui_oxygenstyleconfig.h" namespace Oxygen { class StyleConfig: public QWidget, Ui::OxygenStyleConfig { Q_OBJECT public: //* constructor explicit StyleConfig(QWidget*); - //* destructor - virtual ~StyleConfig( void ) - {} - Q_SIGNALS: //* emmited whenever one option is changed. void changed(bool); public Q_SLOTS: //* load setup from config data void load( void ); //* save current state void save( void ); //* restore all default values void defaults( void ); //Everything below this is internal. //* reset to saved configuration void reset( void ); protected Q_SLOTS: //* update layout /** needed in expert mode to accommodate with animations config widget size changes */ void updateLayout( void ); //* update modified state when option is checked/unchecked void updateChanged( void ); protected: - //! event processing - bool event( QEvent* ) ; + //* event processing + bool event( QEvent* ) override; // menu mode from ui int menuMode( void ) const; // expander size from ui int triangularExpanderSize( void ) const; }; } #endif diff --git a/kstyle/debug/oxygenwidgetexplorer.h b/kstyle/debug/oxygenwidgetexplorer.h index 2a6db067..857d8a2e 100644 --- a/kstyle/debug/oxygenwidgetexplorer.h +++ b/kstyle/debug/oxygenwidgetexplorer.h @@ -1,86 +1,86 @@ #ifndef oxygenwidgetexplorer_h #define oxygenwidgetexplorer_h ////////////////////////////////////////////////////////////////////////////// // oxygenwidgetexplorer.h // print widget's and parent's information on mouse click // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include namespace Oxygen { - //! print widget's and parent's information on mouse click + //* print widget's and parent's information on mouse click class WidgetExplorer: public QObject { Q_OBJECT public: - //! constructor + //* constructor explicit WidgetExplorer( QObject* ); - //! enable + //* enable bool enabled( void ) const; - //! enable + //* enable void setEnabled( bool ); - //! widget rects + //* widget rects void setDrawWidgetRects( bool value ) { _drawWidgetRects = value; } - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; protected: - //! event type + //* event type QString eventType( const QEvent::Type& ) const; - //! print widget information + //* print widget information QString widgetInformation( const QWidget* ) const; private: - //! enable state - bool _enabled; + //* enable state + bool _enabled = false; - //! widget rects - bool _drawWidgetRects; + //* widget rects + bool _drawWidgetRects = false; - //! map event types to string + //* map event types to string QMap _eventTypes; }; } #endif diff --git a/kstyle/demo/oxygenbuttondemowidget.h b/kstyle/demo/oxygenbuttondemowidget.h index e9c2c79f..e9416857 100644 --- a/kstyle/demo/oxygenbuttondemowidget.h +++ b/kstyle/demo/oxygenbuttondemowidget.h @@ -1,84 +1,80 @@ #ifndef oxygenbuttondemowidget_h #define oxygenbuttondemowidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenbuttondemowidget.h // oxygen buttons demo widget // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygendemowidget.h" #include "ui_oxygenbuttondemowidget.h" #include #include #include #include namespace Oxygen { class ButtonDemoWidget: public DemoWidget { Q_OBJECT public: - //! constructor - explicit ButtonDemoWidget( QWidget* = 0 ); - - //! destructor - virtual ~ButtonDemoWidget( void ) - {} + //* constructor + explicit ButtonDemoWidget( QWidget* = nullptr ); public Q_SLOTS: void benchmark( void ); protected Q_SLOTS: - //! change text position in tool buttons + //* change text position in tool buttons void textPosition( int ); - //! change tool button icon size + //* change tool button icon size void iconSize( int ); - //! set buttons as flat + //* set buttons as flat void toggleFlat( bool ); protected: void installMenu( QPushButton* ); void installMenu( QToolButton* ); private: Ui_ButtonDemoWidget ui; - QToolBar* _toolBar; + QToolBar* _toolBar = nullptr; QList _pushButtons; QList _toolButtons; }; } #endif diff --git a/kstyle/demo/oxygendemodialog.cpp b/kstyle/demo/oxygendemodialog.cpp index 112fe7ee..6e0149fc 100644 --- a/kstyle/demo/oxygendemodialog.cpp +++ b/kstyle/demo/oxygendemodialog.cpp @@ -1,252 +1,253 @@ ////////////////////////////////////////////////////////////////////////////// // oxygendemodialog.cpp // oxygen configuration dialog // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygendemodialog.h" #include "oxygenbenchmarkwidget.h" #include "oxygenbuttondemowidget.h" #include "oxygeninputdemowidget.h" #include "oxygenframedemowidget.h" #include "oxygenlistdemowidget.h" #include "oxygenmdidemowidget.h" #include "oxygensliderdemowidget.h" #include "oxygentabdemowidget.h" #include "config-liboxygen.h" #ifdef HAVE_SCHEME_CHOOSER #include "oxygenschemechooser.h" #include "oxygenstylechooser.h" #endif #include #include #include #include #include namespace Oxygen { //_______________________________________________________________ DemoDialog::DemoDialog( QWidget* parent ): KPageDialog( parent ) { setWindowTitle( i18n( "Oxygen Demo" ) ); #if OXYGEN_USE_KDE4 // install Quit shortcut connect( new QShortcut( KStandardShortcut::quit().primary(), this ), SIGNAL(activated()), SLOT(close()) ); connect( new QShortcut( KStandardShortcut::quit().alternate(), this ), SIGNAL(activated()), SLOT(close()) ); #else // install Quit shortcut foreach( const QKeySequence& sequence, KStandardShortcut::quit() ) { connect( new QShortcut( sequence, this ), SIGNAL(activated()), SLOT(close()) ); } #endif // button box auto buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok, Qt::Horizontal ); setButtonBox( buttonBox ); // connection connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL(clicked()), SLOT(close()) ); // customize button box _enableCheckBox = new QCheckBox( i18n( "Enabled" ) ); _enableCheckBox->setChecked( true ); connect( _enableCheckBox, SIGNAL(toggled(bool)), SLOT(toggleEnable(bool)) ); buttonBox->addButton( _enableCheckBox, QDialogButtonBox::ResetRole ); _rightToLeftCheckBox = new QCheckBox( i18n( "Right to left layout" ) ); connect( _rightToLeftCheckBox, SIGNAL(toggled(bool)), SLOT(toggleRightToLeft(bool)) ); buttonBox->addButton( _rightToLeftCheckBox, QDialogButtonBox::ResetRole ); #ifdef HAVE_SCHEME_CHOOSER auto styleChooser = new WidgetStyleChooser(this); styleChooser->createStyleSelectionMenu( i18n( "Style" ) ); buttonBox->addButton( styleChooser, QDialogButtonBox::ResetRole ); auto colChooser = new ColorSchemeChooser( this ); buttonBox->addButton( colChooser, QDialogButtonBox::ResetRole ); #endif // connections connect( this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(updateWindowTitle(KPageWidgetItem*)) ); connect( this, SIGNAL(currentPageChanged(KPageWidgetItem*,KPageWidgetItem*)), SLOT(updateEnableState(KPageWidgetItem*)) ); auto setPageIcon = []( KPageWidgetItem* page, const QString& iconName ) { #if OXYGEN_USE_KDE4 page->setIcon( KIcon( iconName ) ); #else page->setIcon( QIcon::fromTheme( iconName ) ); #endif }; KPageWidgetItem* page = nullptr; QVector items; // inputs { page = new KPageWidgetItem( new InputDemoWidget() ); page->setName( i18n("Input Widgets") ); setPageIcon( page, QStringLiteral( "edit-rename" ) ); page->setHeader( i18n("Shows the appearance of text input widgets") ); addPage( page ); items.append( page ); } // tab { page = new KPageWidgetItem( new TabDemoWidget() ); page->setName( i18n("Tab Widgets") ); setPageIcon( page, QStringLiteral( "tab-detach" ) ); page->setHeader( i18n("Shows the appearance of tab widgets") ); addPage( page ); items.append( page ); } // buttons { page = new KPageWidgetItem( new ButtonDemoWidget() ); page->setName( i18n("Buttons") ); setPageIcon( page, QStringLiteral( "go-jump-locationbar" ) ); page->setHeader( i18n("Shows the appearance of buttons") ); addPage( page ); items.append( page ); } // lists { page = new KPageWidgetItem( new ListDemoWidget() ); page->setName( i18n("Lists") ); setPageIcon( page, QStringLiteral( "view-list-tree" ) ); page->setHeader( i18n("Shows the appearance of lists, trees and tables") ); addPage( page ); items.append( page ); } // frames { page = new KPageWidgetItem( new FrameDemoWidget() ); page->setName( i18n("Frames") ); setPageIcon( page, QStringLiteral( "draw-rectangle" ) ); page->setHeader( i18n("Shows the appearance of various framed widgets") ); addPage( page ); items.append( page ); } // mdi { page = new KPageWidgetItem( new MdiDemoWidget() ); page->setName( i18n( "MDI Windows" ) ); setPageIcon( page, QStringLiteral( "preferences-system-windows" ) ); page->setHeader( i18n( "Shows the appearance of MDI windows" ) ); addPage( page ); items.append( page ); } // sliders { page = new KPageWidgetItem( new SliderDemoWidget() ); page->setName( i18n("Sliders") ); setPageIcon( page, QStringLiteral( "measure" ) ); page->setHeader( i18n("Shows the appearance of sliders, progress bars and scrollbars") ); addPage( page ); items.append( page ); } // benchmark { auto benchmarkWidget( new BenchmarkWidget() ); page = new KPageWidgetItem( benchmarkWidget ); page->setName( i18n("Benchmark") ); setPageIcon( page, QStringLiteral( "system-run" ) ); page->setHeader( i18n("Emulates user interaction with widgets for benchmarking") ); benchmarkWidget->init( this, items ); addPage( page ); items.append( page ); } // connections QShortcut* shortcut( new QShortcut( Qt::CTRL + Qt::Key_X, this ) ); for( auto item:items ) { - connect( shortcut, SIGNAL(activated()), item->widget(), SLOT(benchmark()) ); + if( item->widget()->metaObject()->indexOfSlot( "benchmark()" ) >= 0 ) + { connect( shortcut, SIGNAL(activated()), item->widget(), SLOT(benchmark()) ); } connect( this, SIGNAL(abortSimulations()), &static_cast(item->widget())->simulator(), SLOT(abort()) ); } } //_______________________________________________________________ void DemoDialog::updateWindowTitle( KPageWidgetItem* item ) { QString title; QTextStream what( &title ); if( item ) { what << item->name(); what << " - "; } what << i18n( "Oxygen Demo" ); setWindowTitle( title ); } //_______________________________________________________________ void DemoDialog::updateEnableState( KPageWidgetItem* item ) { if( !( item && item->widget() && _enableCheckBox ) ) return; item->widget()->setEnabled( _enableCheckBox->isChecked() ); } //_______________________________________________________________ void DemoDialog::toggleEnable( bool value ) { if( !( currentPage() && currentPage()->widget() ) ) return; currentPage()->widget()->setEnabled( value ); } //_______________________________________________________________ void DemoDialog::toggleRightToLeft( bool value ) { qApp->setLayoutDirection( value ? Qt::RightToLeft:Qt::LeftToRight ); } //_______________________________________________________________ void DemoDialog::closeEvent( QCloseEvent* event ) { emit abortSimulations(); KPageDialog::closeEvent( event ); } //_______________________________________________________________ void DemoDialog::hideEvent( QHideEvent* event ) { emit abortSimulations(); KPageDialog::hideEvent( event ); } } diff --git a/kstyle/demo/oxygendemodialog.h b/kstyle/demo/oxygendemodialog.h index 1d69dd48..4b8bd4ab 100644 --- a/kstyle/demo/oxygendemodialog.h +++ b/kstyle/demo/oxygendemodialog.h @@ -1,96 +1,96 @@ #ifndef oxygendemodialog_h #define oxygendemodialog_h ////////////////////////////////////////////////////////////////////////////// // oxygendemodialog.h // oxygen demo dialog // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygendemowidget.h" #include #include #include #include namespace Oxygen { class ButtonDemoWidget; class FrameDemoWidget; class InputDemoWidget; class ListDemoWidget; class MdiDemoWidget; class SliderDemoWidget; class TabDemoWidget; class DemoDialog: public KPageDialog { Q_OBJECT public: - //! constructor + //* constructor explicit DemoDialog( QWidget* parent = nullptr ); Q_SIGNALS: - //! emitted when dialog is closed + //* emitted when dialog is closed void abortSimulations( void ); protected: - //! close event + //* close event void closeEvent( QCloseEvent* ) override; - //! hide event + //* hide event void hideEvent( QHideEvent* ) override; private Q_SLOTS: - //! update window title when page is changed + //* update window title when page is changed void updateWindowTitle( KPageWidgetItem* ); - //! update page enability + //* update page enability void updateEnableState( KPageWidgetItem* ); - //! toggle enable state + //* toggle enable state void toggleEnable( bool ); - //! toggle RightToLeft + //* toggle RightToLeft void toggleRightToLeft( bool ); private: - //! enable state checkbox + //* enable state checkbox QCheckBox* _enableCheckBox = nullptr; - //! reverse layout checkbox + //* reverse layout checkbox QCheckBox* _rightToLeftCheckBox = nullptr; }; } #endif diff --git a/kstyle/demo/oxygenframedemowidget.h b/kstyle/demo/oxygenframedemowidget.h index a9459c3b..9d7fa5ee 100644 --- a/kstyle/demo/oxygenframedemowidget.h +++ b/kstyle/demo/oxygenframedemowidget.h @@ -1,85 +1,81 @@ #ifndef oxygenframedemowidget_h #define oxygenframedemowidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenframedemowidget.h // oxygen frames demo widget // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include #include "oxygendemowidget.h" #include "ui_oxygenframedemowidget.h" namespace Oxygen { class FrameDemoWidget: public DemoWidget { Q_OBJECT public: - //! constructor + //* constructor explicit FrameDemoWidget( QWidget* = 0 ); - //! destructor - virtual ~FrameDemoWidget( void ) - {} + public Q_SLOTS: + + //* benchmarking + void benchmark( void ); protected Q_SLOTS: - //! groupbox + //* groupbox void toggleFlatGroupBox( bool value ) { ui.groupBox->setFlat( value ); } - //! frame style + //* frame style void toggleRaisedFrame( bool value ) { if( value ) ui.frame->setFrameStyle( QFrame::StyledPanel|QFrame::Raised ); } void togglePlainFrame( bool value ) { if( value ) ui.frame->setFrameStyle( QFrame::StyledPanel|QFrame::Plain ); } void toggleSunkenFrame( bool value ) { if( value ) ui.frame->setFrameStyle( QFrame::StyledPanel|QFrame::Sunken ); } - //! layout direction + //* layout direction void updateLayoutDirection( int ); - public Q_SLOTS: - - // benchmarking - void benchmark( void ); - private: Ui_FrameDemoWidget ui; }; } #endif diff --git a/kstyle/demo/oxygeninputdemowidget.h b/kstyle/demo/oxygeninputdemowidget.h index 6896af06..3c0ccde7 100644 --- a/kstyle/demo/oxygeninputdemowidget.h +++ b/kstyle/demo/oxygeninputdemowidget.h @@ -1,73 +1,69 @@ #ifndef oxygeninputdemowidget_h #define oxygeninputdemowidget_h ////////////////////////////////////////////////////////////////////////////// // oxygeninputdemowidget.h // oxygen input widgets (e.g. text editors) demo widget // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include "oxygendemowidget.h" #include "ui_oxygeninputdemowidget.h" namespace Oxygen { class InputDemoWidget: public DemoWidget { Q_OBJECT public: - //! constructor - explicit InputDemoWidget( QWidget* = 0 ); - - //! destructor - virtual ~InputDemoWidget( void ) - {} + //* constructor + explicit InputDemoWidget( QWidget* = nullptr ); public Q_SLOTS: - //! run benchmark + //* run benchmark void benchmark( void ); - protected Q_SLOTS: + private Q_SLOTS: - //! flat widgets + //* flat widgets void toggleFlatWidgets( bool ); - //! wrap mode + //* wrap mode void toggleWrapMode( bool ); private: Ui_InputDemoWidget ui; }; } #endif diff --git a/kstyle/demo/oxygenlistdemowidget.h b/kstyle/demo/oxygenlistdemowidget.h index ad07f2bc..9e16900b 100644 --- a/kstyle/demo/oxygenlistdemowidget.h +++ b/kstyle/demo/oxygenlistdemowidget.h @@ -1,66 +1,62 @@ #ifndef oxygenlistdemowidget_h #define oxygenlistdemowidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenlistdemowidget.h // oxygen lists (and trees) demo widget // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include "oxygendemowidget.h" #include "ui_oxygenlistdemowidget.h" namespace Oxygen { class ListDemoWidget: public DemoWidget { Q_OBJECT public: - //! constructor + //* constructor explicit ListDemoWidget( QWidget* = 0 ); - //! destructor - virtual ~ListDemoWidget( void ) - {} - public Q_SLOTS: - //! benchmark + //* benchmark void benchmark( void ); private: - //! ui + //* ui Ui_ListDemoWidget ui; }; } #endif diff --git a/kstyle/demo/oxygenmdidemowidget.h b/kstyle/demo/oxygenmdidemowidget.h index eafbeeeb..53259326 100644 --- a/kstyle/demo/oxygenmdidemowidget.h +++ b/kstyle/demo/oxygenmdidemowidget.h @@ -1,68 +1,64 @@ #ifndef oxygenmdidemowidget_h #define oxygenmdidemowidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenmdidemowidget.h // oxygen mdi windows demo widget // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include "oxygendemowidget.h" #include "ui_oxygenmdidemowidget.h" namespace Oxygen { class MdiDemoWidget: public DemoWidget { Q_OBJECT public: - //! constructor - explicit MdiDemoWidget( QWidget* = 0 ); - - //! destructor - virtual ~MdiDemoWidget( void ) - {} + //* constructor + explicit MdiDemoWidget( QWidget* = nullptr ); public Q_SLOTS: void setLayoutTiled( void ); void setLayoutCascade( void ); void setLayoutTabbed( void ); void benchmark( void ); private: Ui_MdiDemoWidget ui; }; } #endif diff --git a/kstyle/demo/oxygensimulator.cpp b/kstyle/demo/oxygensimulator.cpp index 18a0db67..f6a932b0 100644 --- a/kstyle/demo/oxygensimulator.cpp +++ b/kstyle/demo/oxygensimulator.cpp @@ -1,857 +1,853 @@ // krazy:excludeall=qclasses ////////////////////////////////////////////////////////////////////////////// // oxygensimulator.cpp // simulates event chain passed to the application // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygensimulator.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef Q_OS_WIN /* need windows.h include for Sleep function*/ #include #endif #ifdef Q_OS_UNIX #include #endif namespace Oxygen { //_______________________________________________________________________ bool Simulator::_grabMouse = true; int Simulator::_defaultDelay = 250; - //_______________________________________________________________________ - Simulator::~Simulator( void ) - {} - //_______________________________________________________________________ void Simulator::wait( int delay ) { _events.append( Event( Event::Wait, 0, delay ) ); } //_______________________________________________________________________ void Simulator::click( QWidget* receiver, int delay ) { QPoint position; if( QCheckBox* checkbox = qobject_cast( receiver ) ) { QStyleOptionButton option; option.initFrom( checkbox ); position = checkbox->style()->subElementRect( QStyle::SE_CheckBoxIndicator, &option, checkbox).center(); } else if( QRadioButton* radiobutton = qobject_cast( receiver ) ) { QStyleOptionButton option; option.initFrom( radiobutton ); position = radiobutton->style()->subElementRect( QStyle::SE_RadioButtonIndicator, &option, radiobutton).center(); } else if( const QMdiSubWindow* window = qobject_cast( receiver ) ) { QStyleOptionTitleBar option; option.initFrom( window ); int titleBarHeight( window->style()->pixelMetric( QStyle::PM_TitleBarHeight, &option, window ) ); QRect titleBarRect( QPoint(0,0), QSize( window->width(), titleBarHeight ) ); if( !titleBarRect.isValid() ) return; position = titleBarRect.center(); } else { position = receiver->rect().center(); } click( receiver, position, delay ); } //_______________________________________________________________________ void Simulator::click( QWidget* receiver, const QPoint& position, int delay ) { Event event( Event::Click, receiver, delay ); event._position = position; _events.append( event ); } //_______________________________________________________________________ void Simulator::slide( QWidget* receiver, const QPoint& position, int delay ) { Event event( Event::Slide, receiver, delay ); event._position = position; _events.append( event ); } //_______________________________________________________________________ void Simulator::selectItem( QWidget* receiver, int row, int column, int delay ) { Event event( Event::SelectItem, receiver, delay ); event._position = QPoint( column, row ); _events.append( event ); } //_______________________________________________________________________ void Simulator::selectComboBoxItem( QWidget* receiver, int index, int delay ) { Event event( Event::SelectComboBoxItem, receiver, delay ); event._position.setX( index ); _events.append( event ); } //_______________________________________________________________________ void Simulator::selectMenuItem( QWidget* receiver, int index, int delay ) { Event event( Event::SelectMenuItem, receiver, delay ); event._position.setX( index ); _events.append( event ); } //_______________________________________________________________________ void Simulator::selectTab( QTabWidget* tabwidget, int index, int delay ) { foreach( QObject* child, tabwidget->children() ) { if( QTabBar* tabbar = qobject_cast( child ) ) { selectTab( tabbar, index, delay ); break; } } } //_______________________________________________________________________ void Simulator::selectTab( QTabBar* receiver, int index, int delay ) { Event event( Event::SelectTab, receiver, delay ); event._position.setX( index ); _events.append( event ); } //_______________________________________________________________________ void Simulator::writeText( QWidget* receiver, QString text, int delay ) { Event event( Event::WriteText, receiver, delay ); event._text = text; _events.append( event ); } //_______________________________________________________________________ void Simulator::clearText( QWidget* receiver, int delay ) { _events.append( Event( Event::ClearText, receiver, delay ) ); } //_______________________________________________________________________ void Simulator::run( void ) { if( _events.isEmpty() ) return; // clear abort state _aborted = false; emit stateChanged( true ); foreach( const Event& event, _events ) { if( _aborted ) { _events.clear(); return; } processEvent( event ); } // add last event to reset previousWidget and previousPosition if( _previousWidget ) { postEvent( _previousWidget.data(), QEvent::Leave ); if( _previousWidget.data()->testAttribute( Qt::WA_Hover ) ) { const QPoint oldPosition( _previousWidget.data()->mapFromGlobal( _previousPosition ) ); const QPoint newPosition( _previousWidget.data()->mapFromGlobal( QPoint( -1, -1 ) ) ); postHoverEvent( _previousWidget.data(), QEvent::HoverLeave, newPosition, oldPosition ); } _previousWidget.clear(); _previousPosition = QPoint(-1, -1 ); } _events.clear(); emit stateChanged( false ); return; } //_______________________________________________________________________ void Simulator::abort( void ) { _aborted = true; emit stateChanged( true ); } //_______________________________________________________________________ void Simulator::timerEvent( QTimerEvent* event ) { if( event->timerId() == _timer.timerId() ) { _timer.stop(); } else if( event->timerId() == _pendingEventsTimer.timerId() ) { if( _aborted ) { foreach( QEvent* event, _pendingEvents ) { delete event; } _pendingEvents.clear(); _pendingWidget.clear(); } else if( _pendingWidget && _pendingWidget.data()->isVisible() ) { _pendingEventsTimer.stop(); foreach( QEvent* event, _pendingEvents ) { if( event->type() == QEvent::MouseMove ) { QPoint position( static_cast( event )->pos() ); moveCursor( _pendingWidget.data()->mapToGlobal( position ) ); } postQEvent( _pendingWidget.data(), event ); postDelay( 150 ); } _pendingEvents.clear(); _pendingWidget.clear(); } } else return QObject::timerEvent( event ); } //_______________________________________________________________________ void Simulator::processEvent( const Event& event ) { if( _aborted ) return; if( !event._receiver ) { if( event._type == Event::Wait ) { postDelay( event._delay ); } return; } QWidget* receiver( event._receiver.data() ); switch( event._type ) { // click event case Event::Click: { // enter widget or move cursor to relevant position if( !enter( receiver, event._position, event._delay ) ) { moveCursor( receiver->mapToGlobal( event._position ) ); postMouseEvent( receiver, QEvent::MouseMove, Qt::NoButton, event._position ); } postMouseClickEvent( receiver, Qt::LeftButton, event._position ); break; } // slide case Event::Slide: { const QPoint& delta( event._position ); // calculate begin position depending on widget type QPoint begin; if( const QSlider* slider = qobject_cast( receiver ) ) { // this is copied from QSlider::initStyleOption QStyleOptionSlider option; option.initFrom( slider ); option.orientation = slider->orientation(); option.sliderPosition = slider->sliderPosition(); option.minimum = slider->minimum(); option.maximum = slider->maximum(); option.upsideDown = (slider->orientation() == Qt::Horizontal) ? ( slider->invertedAppearance() != (option.direction == Qt::RightToLeft)) : (!slider->invertedAppearance() ); QRect handleRect( slider->style()->subControlRect( QStyle::CC_Slider, &option, QStyle::SC_SliderHandle, slider ) ); if( !handleRect.isValid() ) break; begin = handleRect.center(); } else if( const QScrollBar* scrollbar = qobject_cast( receiver ) ) { // this is copied from QSlider::initStyleOption QStyleOptionSlider option; option.initFrom( scrollbar ); option.orientation = scrollbar->orientation(); option.sliderPosition = scrollbar->sliderPosition(); option.minimum = scrollbar->minimum(); option.maximum = scrollbar->maximum(); option.upsideDown = scrollbar->invertedAppearance(); if( scrollbar->orientation() == Qt::Horizontal ) { option.state |= QStyle::State_Horizontal; } QRect handleRect( scrollbar->style()->subControlRect( QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarSlider, scrollbar ) ); if( !handleRect.isValid() ) break; begin = handleRect.center(); } else if( const QMdiSubWindow* window = qobject_cast( receiver ) ) { QStyleOptionTitleBar option; option.initFrom( window ); int titleBarHeight( window->style()->pixelMetric( QStyle::PM_TitleBarHeight, &option, window ) ); QRect titleBarRect( QPoint(0,0), QSize( window->width(), titleBarHeight ) ); if( !titleBarRect.isValid() ) break; begin = titleBarRect.center(); } else { begin = receiver->rect().center(); } // enter widget or move cursor to relevant position if( !enter( receiver, begin, event._delay ) ) { moveCursor( receiver->mapToGlobal( begin ) ); postMouseEvent( receiver, QEvent::MouseMove, Qt::NoButton, begin ); } const QPoint end( begin + delta ); postMouseEvent( receiver, QEvent::MouseButtonPress, Qt::LeftButton, begin, Qt::LeftButton ); setFocus( receiver ); postDelay( 50 ); const int steps = 10; for( int i=0; imapToGlobal( current ), 1 ); postMouseEvent( receiver, QEvent::MouseMove, Qt::NoButton, current, Qt::LeftButton, Qt::NoModifier ); postDelay( 20 ); } postMouseEvent( receiver, QEvent::MouseButtonRelease, Qt::LeftButton, end ); break; } case Event::SelectItem: { const QAbstractItemView* view = qobject_cast( receiver ); if( !( view && view->model() ) ) break; const int column( event._position.x() ); const int row( event._position.y() ); // find index const QModelIndex modelIndex( view->model()->index( row, column ) ); if( !modelIndex.isValid() ) break; // get rect QRect r( view->visualRect( modelIndex ) ); if( !r.isValid() ) break; // enter widget or move cursor to relevant position const QPoint position( r.center() ); if( !enter( view->viewport(), position, event._delay ) ) { moveCursor( view->viewport()->mapToGlobal( position ) ); postMouseEvent( view->viewport(), QEvent::MouseMove, Qt::NoButton, position ); postDelay( event._delay ); } postMouseClickEvent( view->viewport(), Qt::LeftButton, position ); break; } case Event::SelectComboBoxItem: { QComboBox* combobox = qobject_cast( receiver ); if( !combobox ) break; // get arrow rect QStyleOptionComboBox option; option.initFrom( combobox ); QRect arrowRect( combobox->style()->subControlRect( QStyle::CC_ComboBox, &option, QStyle::SC_ComboBoxArrow, combobox ) ); // enter widget or move cursor to relevant position QPoint position( arrowRect.center() ); if( !enter( combobox, position, event._delay ) ) { moveCursor( combobox->mapToGlobal( position ) ); postMouseEvent( combobox, QEvent::MouseMove, Qt::NoButton, position ); postDelay( event._delay ); } postMouseClickEvent( combobox, Qt::LeftButton, position ); // select item in view QAbstractItemView* view = combobox->view(); const int row( event._position.x() ); const int column( 0 ); // find index const QModelIndex modelIndex( view->model()->index( row, column ) ); if( !modelIndex.isValid() ) break; // get rect QRect r( view->visualRect( modelIndex ) ); if( !r.isValid() ) break; // send event position = QPoint( r.center() ); moveCursor( view->viewport()->mapToGlobal( position ) ); postMouseEvent( view->viewport(), QEvent::MouseMove, Qt::NoButton, position, Qt::NoButton, Qt::NoModifier ); postDelay(100); postMouseClickEvent( view->viewport(), Qt::LeftButton, position ); break; } case Event::SelectMenuItem: { // retrieve menu QMenu* menu( 0 ); if( const QToolButton* button = qobject_cast( receiver ) ) menu = button->menu(); else if( const QPushButton* button = qobject_cast( receiver ) ) menu = button->menu(); // abort if not found if( !menu ) break; // get action and geometry const int row( event._position.x() ); QList actions( menu->actions() ); if( row >= actions.size() ) break; menu->sizeHint(); QRect r( menu->actionGeometry( actions[row] ) ); if( !r.isValid() ) break; /*! HACK: As soon as leftMouseButton is pressed on a button with menu, the menu is shown and code is interrupted until an action is selected in the menu. As a consequence, one must first generate the events, execute them with a delay, and then click on the button (before delay is expired). This way, the menu events will be executed even if the menu is visible (and blocking further code execution). */ QPoint position( r.center() ); _pendingWidget = menu; _pendingEvents.append( new QMouseEvent( QEvent::MouseMove, position, Qt::NoButton, Qt::NoButton, Qt::NoModifier ) ); _pendingEvents.append( new QMouseEvent( QEvent::MouseButtonPress, position, Qt::LeftButton, Qt::NoButton, Qt::NoModifier ) ); _pendingEvents.append( new QMouseEvent( QEvent::MouseButtonRelease, position, Qt::LeftButton, Qt::NoButton, Qt::NoModifier ) ); _pendingEventsTimer.start( 10, this ); // enter widget or move cursor to relevant position position = receiver->rect().center(); if( !enter( receiver, position, event._delay ) ) { moveCursor( receiver->mapToGlobal( position ) ); postMouseEvent( receiver, QEvent::MouseMove, Qt::NoButton, position ); postDelay( event._delay ); } // click postMouseEvent( receiver, QEvent::MouseButtonPress, Qt::LeftButton, position, Qt::NoButton, Qt::NoModifier ); break; } case Event::SelectTab: { const QTabBar* tabbar = qobject_cast( receiver ); if( !tabbar ) break; const int index( event._position.x() ); const QRect r( tabbar->tabRect( index ) ); if( !r.isValid() ) break; // enter widget or move cursor to relevant position const QPoint position( r.center() ); if( !enter( receiver, position, event._delay ) ) { moveCursor( receiver->mapToGlobal( position ) ); postMouseEvent( receiver, QEvent::MouseMove, Qt::NoButton, position ); postDelay( event._delay ); } postMouseClickEvent( receiver, Qt::LeftButton, position ); break; } case Event::WriteText: { enter( receiver, receiver->rect().center(), event._delay ); setFocus( receiver ); const QString& text( event._text ); for( int i=0; i < text.length(); ++i ) { const Qt::Key key( toKey( text.at(i) ) ); const QString local( text.at(i) ); postKeyEvent( receiver, QEvent::KeyPress, key, local, Qt::NoModifier ); postKeyEvent( receiver, QEvent::KeyRelease, key, local, Qt::NoModifier ); postDelay( 20 ); } break; } case Event::ClearText: { enter( receiver, receiver->rect().center(), event._delay ); setFocus( receiver ); postKeyEvent( receiver, QEvent::KeyPress, Qt::Key_A, QStringLiteral( "a" ), Qt::ControlModifier ); postKeyEvent( receiver, QEvent::KeyRelease, Qt::Key_A, QStringLiteral( "a" ), Qt::ControlModifier ); postDelay( 20 ); postKeyClickEvent( receiver, Qt::Key_Backspace, QString() ); } default: break; } // delay postDelay( event._delay ); return; } //_______________________________________________________________________ void Simulator::postEvent( QWidget* receiver, QEvent::Type type ) const { postQEvent( receiver, new QEvent( type ) ); } //_______________________________________________________________________ void Simulator::postHoverEvent( QWidget* receiver, QEvent::Type type, const QPoint& newPosition, const QPoint& oldPosition ) const { postQEvent( receiver, new QHoverEvent( type, newPosition, oldPosition ) ); } //_______________________________________________________________________ bool Simulator::enter( QWidget* receiver, const QPoint& position, int delay ) { if( receiver == _previousWidget.data() ) return false; // store position moveCursor( receiver->mapToGlobal( position ) ); // leave previous widget if( _previousWidget ) { postEvent( _previousWidget.data(), QEvent::Leave ); if( _previousWidget.data()->testAttribute( Qt::WA_Hover ) ) { const QPoint oldPosition( _previousWidget.data()->mapFromGlobal( _previousPosition ) ); const QPoint newPosition( _previousWidget.data()->mapFromGlobal( receiver->mapToGlobal( position ) ) ); postHoverEvent( _previousWidget.data(), QEvent::HoverLeave, newPosition, oldPosition ); } } // enter or move in current widget if( !receiver->rect().contains( receiver->mapFromGlobal( _previousPosition ) ) ) { // enter current widget if needed postEvent( receiver, QEvent::Enter ); if( receiver->testAttribute( Qt::WA_Hover ) ) { const QPoint oldPosition( receiver->mapFromGlobal( _previousPosition ) ); const QPoint newPosition( position ); postHoverEvent( receiver, QEvent::HoverEnter, newPosition, oldPosition ); } } else if( receiver->mapFromGlobal( _previousPosition ) != position ) { // move mouse if needed postMouseEvent( receiver, QEvent::MouseMove, Qt::NoButton, position ); if( receiver->testAttribute( Qt::WA_Hover ) ) { const QPoint oldPosition( receiver->mapFromGlobal( _previousPosition ) ); const QPoint newPosition( position ); postHoverEvent( receiver, QEvent::HoverMove, newPosition, oldPosition ); } } // update previous widget and position _previousWidget = receiver; _previousPosition = receiver->mapToGlobal( position ); postDelay( delay ); return true; } //_______________________________________________________________________ void Simulator::postMouseClickEvent( QWidget* receiver, Qt::MouseButton button, const QPoint& position ) { // button press and button release postMouseEvent( receiver, QEvent::MouseButtonPress, button, position, button ); setFocus( receiver ); postDelay(50); postMouseEvent( receiver, QEvent::MouseButtonRelease, button, position, button ); } //_______________________________________________________________________ void Simulator::postMouseEvent( QWidget* receiver, QEvent::Type type, Qt::MouseButton button, const QPoint& position, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers ) const { postQEvent( receiver, new QMouseEvent( type, position, receiver->mapToGlobal( position ), button, buttons, modifiers ) ); } //_______________________________________________________________________ void Simulator::postKeyClickEvent( QWidget* receiver, Qt::Key key, QString text, Qt::KeyboardModifiers modifiers ) const { postKeyModifiersEvent( receiver, QEvent::KeyPress, modifiers ); postKeyEvent( receiver, QEvent::KeyPress, key, text, modifiers ); postKeyEvent( receiver, QEvent::KeyRelease, key, text, modifiers ); postKeyModifiersEvent( receiver, QEvent::KeyRelease, modifiers ); } //_______________________________________________________________________ void Simulator::postKeyModifiersEvent( QWidget* receiver, QEvent::Type type, Qt::KeyboardModifiers modifiers ) const { if( modifiers == Qt::NoModifier ) return; switch( type ) { case QEvent::KeyPress: { if( modifiers & Qt::ShiftModifier) { postKeyEvent( receiver, QEvent::KeyPress, Qt::Key_Shift, QString() ); } if( modifiers & Qt::ControlModifier ) { postKeyEvent( receiver, QEvent::KeyPress, Qt::Key_Control, QString(), modifiers & Qt::ShiftModifier ); } if( modifiers & Qt::AltModifier ) { postKeyEvent( receiver, QEvent::KeyPress, Qt::Key_Alt, QString(), modifiers & (Qt::ShiftModifier|Qt::ControlModifier) ); } if( modifiers & Qt::MetaModifier ) { postKeyEvent( receiver, QEvent::KeyPress, Qt::Key_Meta, QString(), modifiers & (Qt::ShiftModifier|Qt::ControlModifier|Qt::AltModifier) ); } break; } case QEvent::KeyRelease: { if( modifiers & Qt::MetaModifier ) { postKeyEvent( receiver, QEvent::KeyRelease, Qt::Key_Meta, QString() ); } if( modifiers & Qt::AltModifier ) { postKeyEvent( receiver, QEvent::KeyRelease, Qt::Key_Alt, QString(), modifiers & Qt::MetaModifier ); } if( modifiers & Qt::ControlModifier ) { postKeyEvent( receiver, QEvent::KeyRelease, Qt::Key_Control, QString(), modifiers & (Qt::MetaModifier|Qt::AltModifier) ); } if( modifiers & Qt::ShiftModifier) { postKeyEvent( receiver, QEvent::KeyRelease, Qt::Key_Shift, QString(), modifiers & (Qt::MetaModifier|Qt::AltModifier|Qt::ControlModifier) ); } } default: break; } } //_______________________________________________________________________ void Simulator::postKeyEvent( QWidget* receiver, QEvent::Type type, Qt::Key key, QString text, Qt::KeyboardModifiers modifiers ) const { postQEvent( receiver, new QKeyEvent( type, key, modifiers, text ) ); } //_______________________________________________________________________ void Simulator::postDelay( int delay ) { // check value if( delay == -1 ) delay = _defaultDelay; if( delay <= 0 ) return; // this is largely inspired from qtestlib's qsleep implementation _timer.start( delay, this ); while( _timer.isActive() ) { // flush events in loop QCoreApplication::processEvents(QEventLoop::AllEvents, delay); int ms( 10 ); // sleep #ifdef Q_OS_WIN Sleep(uint(ms)); #else struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; nanosleep(&ts, nullptr); #endif } } //_______________________________________________________________________ void Simulator::moveCursor( const QPoint& position, int steps ) { // do nothing if mouse grab is disabled if( !_grabMouse ) return; if( _aborted ) return; const QPoint begin( QCursor::pos() ); const QPoint end( position ); if( begin == end ) return; if( steps > 1 ) { for( int i = 0; ifocusPolicy() != Qt::NoFocus ) { receiver->setFocus(); } } //_______________________________________________________________________ Qt::Key Simulator::toKey( QChar a ) const { return (Qt::Key) QKeySequence( a )[0]; } //_______________________________________________________________________ void Simulator::postQEvent( QWidget* receiver, QEvent* event ) const { if( _aborted ) delete event; else qApp->postEvent( receiver, event ); } } diff --git a/kstyle/demo/oxygensimulator.h b/kstyle/demo/oxygensimulator.h index 7af8187c..fe45ed80 100644 --- a/kstyle/demo/oxygensimulator.h +++ b/kstyle/demo/oxygensimulator.h @@ -1,266 +1,259 @@ #ifndef oxygensimulator_h #define oxygensimulator_h ////////////////////////////////////////////////////////////////////////////// // oxygensimulator.h // simulates event chain passed to the application // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "../oxygen.h" #include #include #include #include #include #include #include #include #include #include namespace Oxygen { class Simulator: public QObject { Q_OBJECT public: - //! constructor + //* constructor explicit Simulator( QObject* parent ): QObject( parent ), _previousPosition( -1, -1 ) {} - //! destructor - virtual ~Simulator( void ); - - //!@name high level interface + //*@name high level interface //@{ - //! click on button + //* click on button void click( QWidget* receiver, int delay = -1 ); - //! click on button + //* click on button void click( QWidget*, const QPoint&, int = -1 ); - //! slide + //* slide void slide( QWidget* receiver, const QPoint& delta, int delay = -1 ); - //! select item + //* select item void selectItem( QWidget*, int row, int column = 0, int = -1 ); - //! select combobox item + //* select combobox item void selectComboBoxItem( QWidget*, int, int = -1 ); - //! select menu item + //* select menu item void selectMenuItem( QWidget*, int, int = -1 ); - //! select tab in tabwidget + //* select tab in tabwidget void selectTab( QTabWidget*, int, int = -1 ); - //! select tab in tabbar + //* select tab in tabbar void selectTab( QTabBar*, int, int = -1 ); - //! write sample text + //* write sample text void writeSampleText( QWidget* widget, int delay = -1 ) { writeText( widget, i18n( "This is a sample text" ), delay ); } - //! write string + //* write string void writeText( QWidget*, QString, int = -1 ); - //! clear text + //* clear text void clearText( QWidget*, int = -1 ); - //! delay + //* delay void wait( int delay ); //@} - //! true if aborted + //* true if aborted bool aborted( void ) const { return _aborted; } - //! run stored events + //* run stored events void run( void ); - //! gab mouse + //* gab mouse static bool grabMouse( void ) { return _grabMouse; } - //! mouse grab + //* mouse grab static void setGrabMouse( bool value ) { _grabMouse = value; } - //! default delay + //* default delay static void setDefaultDelay( int value ) { _defaultDelay = value; } Q_SIGNALS: - //! emitted when simulator starts and stops + //* emitted when simulator starts and stops void stateChanged( bool ); public Q_SLOTS: - //! abort simulations + //* abort simulations void abort( void ); protected: - //! timer event + //* timer event void timerEvent( QTimerEvent* ) override; - //!@name low level interface + private: + + //*@name low level interface //@{ - //! enter widget + //* enter widget bool enter( QWidget* receiver, int delay = -1 ) { return enter( receiver, receiver->rect().center(), delay ); } - //! enter receiver + //* enter receiver bool enter( QWidget*, const QPoint&, int = -1 ); - //! mouse click event + //* mouse click event void postMouseClickEvent( QWidget* widget ) { postMouseClickEvent( widget, Qt::LeftButton, widget->rect().center() ); } - //! mouse click event + //* mouse click event void postMouseClickEvent( QWidget*, Qt::MouseButton, const QPoint& ); - //! 'basic' event + //* 'basic' event void postEvent( QWidget*, QEvent::Type ) const; - //! hover + //* hover void postHoverEvent( QWidget*, QEvent::Type, const QPoint&, const QPoint& ) const; - //! mouse event + //* mouse event void postMouseEvent( QWidget*, QEvent::Type, Qt::MouseButton , const QPoint&, Qt::MouseButtons = Qt::NoButton, Qt::KeyboardModifiers = Qt::NoModifier ) const; - //! key event + //* key event void postKeyClickEvent( QWidget*, Qt::Key, QString, Qt::KeyboardModifiers = Qt::NoModifier ) const; - //! key event + //* key event void postKeyModifiersEvent( QWidget*, QEvent::Type, Qt::KeyboardModifiers ) const; - //! key event + //* key event void postKeyEvent( QWidget*, QEvent::Type, Qt::Key, QString, Qt::KeyboardModifiers = Qt::NoModifier ) const; - //! delay + //* delay void postDelay( int ); - //! set focus to widget + //* set focus to widget void setFocus( QWidget* ); - //! move cursor + //* move cursor void moveCursor( const QPoint&, int steps = 10 ); //@} - private: - using WidgetPointer = WeakPointer; - //! event + //* event class Event { public: enum Type { Wait, Click, Slide, SelectItem, SelectComboBoxItem, SelectMenuItem, SelectTab, WriteText, ClearText }; - //! constructor + //* constructor Event( Type type, QWidget* receiver, int delay = 0 ): _type( type ), _receiver( receiver ), _delay( delay ) {} - //! destructor - virtual ~Event( void ) - {} - Type _type; WidgetPointer _receiver; QPoint _position; QString _text; - int _delay; + int _delay = 0; }; - //! process event + //* process event void processEvent( const Event& ); - //! process Qt event + //* process Qt event void postQEvent( QWidget*, QEvent* ) const; - //! convert QChar to key + //* convert QChar to key Qt::Key toKey( QChar ) const; - //! list of events + //* list of events using EventList = QList; EventList _events; - //! previous position in global coordinates - /*! this is needed to have proper handling of enter/leave/hover events */ + //* previous position in global coordinates + /** this is needed to have proper handling of enter/leave/hover events */ QPoint _previousPosition; - //! previous widget + //* previous widget WidgetPointer _previousWidget; - //! basic timer, for wait + //* basic timer, for wait QBasicTimer _timer; - //! pending events timer + //* pending events timer QBasicTimer _pendingEventsTimer; - //! pending event + //* pending event WidgetPointer _pendingWidget; QList _pendingEvents; - //! true when simulations must be aborted + //* true when simulations must be aborted bool _aborted = false; - //! true if simulations also grab mouse + //* true if simulations also grab mouse static bool _grabMouse; - //! default delay + //* default delay static int _defaultDelay; }; } #endif diff --git a/kstyle/demo/oxygensliderdemowidget.h b/kstyle/demo/oxygensliderdemowidget.h index 849a60c9..187e89f8 100644 --- a/kstyle/demo/oxygensliderdemowidget.h +++ b/kstyle/demo/oxygensliderdemowidget.h @@ -1,115 +1,111 @@ #ifndef oxygensliderdemowidget_h #define oxygensliderdemowidget_h ////////////////////////////////////////////////////////////////////////////// // oxygensliderdemowidget.h // oxygen sliders demo widget // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include #include "oxygendemowidget.h" #include "ui_oxygensliderdemowidget.h" namespace Oxygen { class ProgressBar: public QObject { Q_OBJECT public: - //! constructor + //* constructor ProgressBar( QObject*, QProgressBar*, QCheckBox* ); - //! set value + //* set value void setValue( int ); public Q_SLOTS: - //! toggle invertex appearance + //* toggle invertex appearance void toggleInvertedAppearance( bool value ) { _progressBar->setInvertedAppearance( value ); } protected Q_SLOTS: - //! toggle bussy state + //* toggle bussy state void toggleBusy( bool ); private: - //! progressBar + //* progressBar QProgressBar* _progressBar; - //! checkbox + //* checkbox QCheckBox* _checkBox; - //! saved value + //* saved value int _value; }; class SliderDemoWidget: public DemoWidget { Q_OBJECT public: - //! constructor - explicit SliderDemoWidget( QWidget* = 0 ); - - //! destructor - virtual ~SliderDemoWidget( void ) - {} + //* constructor + explicit SliderDemoWidget( QWidget* = nullptr ); public Q_SLOTS: - //! benchmark + //* benchmark void benchmark( void ); - protected Q_SLOTS: + private Q_SLOTS: void updateSliders( int ); void updateTickPosition( int ); private: - bool _locked; + bool _locked = false; Ui_SliderDemoWidget ui; - //! progressbars + //* progressbars ProgressBar* _horizontalProgressBar; ProgressBar* _verticalProgressBar; }; } #endif diff --git a/kstyle/demo/oxygentabdemowidget.h b/kstyle/demo/oxygentabdemowidget.h index 2ecf6db9..bfea2811 100644 --- a/kstyle/demo/oxygentabdemowidget.h +++ b/kstyle/demo/oxygentabdemowidget.h @@ -1,90 +1,86 @@ #ifndef oxygentabdemowidget_h #define oxygentabdemowidget_h ////////////////////////////////////////////////////////////////////////////// // oxygentabdemowidget.h // oxygen tabwidget demo widget // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include "ui_oxygentabdemowidget.h" #include "oxygendemowidget.h" namespace Oxygen { class TabDemoWidget: public DemoWidget { Q_OBJECT public: - //! constructor - explicit TabDemoWidget( QWidget* = 0 ); - - //! destructor - virtual ~TabDemoWidget( void ) - {} + //* constructor + explicit TabDemoWidget( QWidget* = nullptr ); public Q_SLOTS: - //! benchmark + //* benchmark void benchmark( void ); protected Q_SLOTS: - //! show/hide corner buttons + //* show/hide corner buttons void toggleCornerWidgets( bool ); - //! change document mode + //* change document mode void toggleDocumentMode( bool ); - //! show tab close buttons + //* show tab close buttons void toggleTabCloseButtons( bool ); // change tab position void changeTabPosition( int ); // change tab position void changeTextPosition( int ); private: - //! ui + //* ui Ui_TabDemoWidget ui; - //! tabbar left button - QToolButton* _left; + //* tabbar left button + QToolButton* _left = nullptr; - //! tabbar right button - QToolButton* _right; + //* tabbar right button + QToolButton* _right = nullptr; }; } #endif diff --git a/kstyle/kstylekde4compat.cpp b/kstyle/kstylekde4compat.cpp index 4d1b4ea1..9b8db594 100644 --- a/kstyle/kstylekde4compat.cpp +++ b/kstyle/kstylekde4compat.cpp @@ -1,122 +1,118 @@ /************************************************************************* * Copyright (C) 2015 by David Edmundson * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ #include "kstylekde4compat.h" #include #include #include static const QStyle::StyleHint SH_KCustomStyleElement = (QStyle::StyleHint)0xff000001; static const int X_KdeBase = 0xff000000; //_____________________________________________________________________ KStyleKDE4Compat::KStyleKDE4Compat() { controlCounter = subElementCounter = X_KdeBase; hintCounter = X_KdeBase + 1; //sic! X_KdeBase is covered by SH_KCustomStyleElement } -//_____________________________________________________________________ -KStyleKDE4Compat::~KStyleKDE4Compat() -{} - //_____________________________________________________________________ static inline int newStyleElement(const QString &element, const char *check, int &counter, QHash *elements) { if (!element.contains(check)) return 0; int id = elements->value(element, 0); if (!id) { ++counter; id = counter; elements->insert(element, id); } return id; } //_____________________________________________________________________ QStyle::StyleHint KStyleKDE4Compat::newStyleHint(const QString &element) { return (StyleHint)newStyleElement(element, "SH_", hintCounter, &styleElements); } //_____________________________________________________________________ QStyle::ControlElement KStyleKDE4Compat::newControlElement(const QString &element) { return (ControlElement)newStyleElement(element, "CE_", controlCounter, &styleElements); } //_____________________________________________________________________ QStyle::SubElement KStyleKDE4Compat::newSubElement(const QString &element) { return (SubElement)newStyleElement(element, "SE_", subElementCounter, &styleElements); } //_____________________________________________________________________ int KStyleKDE4Compat::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const { if( hint == SH_KCustomStyleElement && widget ) { return styleElements.value(widget->objectName(), 0); } switch (hint) { case SH_ItemView_ActivateItemOnSingleClick: { KConfigGroup g(KSharedConfig::openConfig(), "KDE"); return g.readEntry("SingleClick", true); } case SH_DialogButtonBox_ButtonsHaveIcons: { // was KGlobalSettings::showIconsOnPushButtons() : KConfigGroup g(KSharedConfig::openConfig(), "KDE"); return g.readEntry("ShowIconsOnPushButtons", true); } case SH_ItemView_ArrowKeysNavigateIntoChildren: return true; case SH_ToolButtonStyle: { KConfigGroup g(KSharedConfig::openConfig(), "Toolbar style"); bool useOthertoolbars = false; const QWidget *parent = widget ? widget->parentWidget() : nullptr; //If the widget parent is a QToolBar and the magic property is set if (parent && qobject_cast< const QToolBar * >(parent)) { if (parent->property("otherToolbar").isValid()) { useOthertoolbars = true; } } QString buttonStyle; if (useOthertoolbars) { buttonStyle = g.readEntry("ToolButtonStyleOtherToolbars", "NoText").toLower(); } else { buttonStyle = g.readEntry("ToolButtonStyle", "TextBesideIcon").toLower(); } return buttonStyle == QLatin1String("textbesideicon") ? Qt::ToolButtonTextBesideIcon : buttonStyle == QLatin1String("icontextright") ? Qt::ToolButtonTextBesideIcon : buttonStyle == QLatin1String("textundericon") ? Qt::ToolButtonTextUnderIcon : buttonStyle == QLatin1String("icontextbottom") ? Qt::ToolButtonTextUnderIcon : buttonStyle == QLatin1String("textonly") ? Qt::ToolButtonTextOnly : Qt::ToolButtonIconOnly; } default: break; }; return QCommonStyle::styleHint(hint, option, widget, returnData); } diff --git a/kstyle/kstylekde4compat.h b/kstyle/kstylekde4compat.h index ad713c02..3116b9e7 100644 --- a/kstyle/kstylekde4compat.h +++ b/kstyle/kstylekde4compat.h @@ -1,58 +1,60 @@ /************************************************************************* * Copyright (C) 2015 by David Edmundson * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ /** * This class copies the features of KF5's KStyle for use in KDE4 only * * kdelibs4 also has a KStyle class but this isn't a 1-1 mapping and * provides a lot of features we do not want */ #ifndef KSTYLE_KDE4_COMPAT_H #define KSTYLE_KDE4_COMPAT_H #include #include class KStyleKDE4Compat : public QCommonStyle { Q_OBJECT public: + //* constructor KStyleKDE4Compat(); - ~KStyleKDE4Compat(); - virtual int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *returnData) const; + + //* style hint + int styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *w, QStyleHintReturn *returnData) const override; protected: StyleHint newStyleHint(const QString &element); ControlElement newControlElement(const QString &element); SubElement newSubElement(const QString &element); private: QHash styleElements; - int hintCounter; - int controlCounter; - int subElementCounter; + int hintCounter = 0; + int controlCounter = 0; + int subElementCounter = 0; }; #endif diff --git a/kstyle/oxygenaddeventfilter.h b/kstyle/oxygenaddeventfilter.h index 81432311..4365fce7 100644 --- a/kstyle/oxygenaddeventfilter.h +++ b/kstyle/oxygenaddeventfilter.h @@ -1,63 +1,58 @@ #ifndef oxygenaddeventfilter_h #define oxygenaddeventfilter_h ////////////////////////////////////////////////////////////////////////////// // oxygenaddeventfilter.h // used to block add a child to a widget, blocking AddChild parent events // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Largely inspired from BeSpin style // Copyright (C) 2007 Thomas Luebking // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include namespace Oxygen { class AddEventFilter: public QObject { public: - //! constructor + //* constructor AddEventFilter( void ): QObject() {} - //! destructor - virtual ~AddEventFilter( void ) - {} - - - //! event filter + //* event filter /*! blocks all AddChild events */ - bool eventFilter( QObject*, QEvent* event ) + bool eventFilter( QObject*, QEvent* event ) override { return event->type() == QEvent::ChildAdded; } }; } #endif diff --git a/kstyle/oxygenblurhelper.h b/kstyle/oxygenblurhelper.h index 02db27de..8553c581 100644 --- a/kstyle/oxygenblurhelper.h +++ b/kstyle/oxygenblurhelper.h @@ -1,172 +1,168 @@ #ifndef oxygenblurhelper_h #define oxygenblurhelper_h ////////////////////////////////////////////////////////////////////////////// // oxygenblurhelper.h // handle regions passed to kwin for blurring // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Loosely inspired (and largely rewritten) from BeSpin style // Copyright (C) 2007 Thomas Luebking // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenstylehelper.h" #include "oxygen.h" #include #include #include #include #include #include #include #include #include #if OXYGEN_HAVE_X11 #include #endif namespace Oxygen { class BlurHelper: public QObject { Q_OBJECT public: - //! constructor + //* constructor BlurHelper( QObject*, StyleHelper& ); - //! destructor - virtual ~BlurHelper( void ) - {} - - //! enable state + //* enable state void setEnabled( bool value ) { _enabled = value; } - //! enabled + //* enabled bool enabled( void ) const { return _enabled; } - //! register widget + //* register widget void registerWidget( QWidget* ); - //! register widget + //* register widget void unregisterWidget( QWidget* ); - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; protected: - //! timer event + //* timer event /*! used to perform delayed blur region update of pending widgets */ - void timerEvent( QTimerEvent* event ) + void timerEvent( QTimerEvent* event ) override { if( event->timerId() == _timer.timerId() ) { _timer.stop(); update(); } else QObject::timerEvent( event ); } - //! install event filter to object, in a unique way + private Q_SLOTS: + + //* wiget destroyed + void widgetDestroyed( QObject* object ) + { _widgets.remove( object ); } + + private: + + //* install event filter to object, in a unique way void addEventFilter( QObject* object ) { object->removeEventFilter( this ); object->installEventFilter( this ); } - //! get list of blur-behind regions matching a given widget + //* get list of blur-behind regions matching a given widget QRegion blurRegion( QWidget* ) const; - //! trim blur region to remove unnecessary areas (recursive) + //* trim blur region to remove unnecessary areas (recursive) void trimBlurRegion( QWidget*, QWidget*, QRegion& ) const; - //! update blur region for all pending widgets + //* update blur region for all pending widgets void update( void ) { foreach( const WidgetPointer& widget, _pendingWidgets ) { if( widget ) update( widget.data() ); } _pendingWidgets.clear(); } - //! update blur regions for given widget + //* update blur regions for given widget void update( QWidget* ) const; - //! clear blur regions for given widget + //* clear blur regions for given widget void clear( QWidget* ) const; - //! returns true if a given widget is opaque + //* returns true if a given widget is opaque bool isOpaque( const QWidget* widget ) const; - //! true if widget is a transparent window + //* true if widget is a transparent window /*! some additional checks are performed to make sure stuff like plasma tooltips don't get their blur region overwritten */ bool isTransparent( const QWidget* widget ) const; - protected Q_SLOTS: - - //! wiget destroyed - void widgetDestroyed( QObject* object ) - { _widgets.remove( object ); } - - private: - - //! helper + //* helper StyleHelper& _helper; - //! enability + //* enability bool _enabled; - //! list of widgets for which blur region must be updated + //* list of widgets for which blur region must be updated using WidgetPointer = WeakPointer; using WidgetSet = QHash; WidgetSet _pendingWidgets; - //! set of registered widgets + //* set of registered widgets QSet _widgets; - //! delayed update timer + //* delayed update timer QBasicTimer _timer; #if OXYGEN_HAVE_X11 - //! blur atom + //* blur atom xcb_atom_t _blurAtom; xcb_atom_t _opaqueAtom; #endif }; } #endif diff --git a/kstyle/oxygenframeshadow.h b/kstyle/oxygenframeshadow.h index 7d4061f6..6f99536e 100644 --- a/kstyle/oxygenframeshadow.h +++ b/kstyle/oxygenframeshadow.h @@ -1,293 +1,271 @@ #ifndef oxygenframeshadow_h #define oxygenframeshadow_h ////////////////////////////////////////////////////////////////////////////// // oxygenframeshadow.h // handle frames' shadows and rounded corners // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Largely inspired from skulpture widget style // Copyright (c) 2007-2009 Christoph Feck // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenaddeventfilter.h" #include "oxygenstylehelper.h" #include #include #include #include #include #include namespace Oxygen { //* shadow manager class FrameShadowFactory: public QObject { Q_OBJECT public: //* constructor explicit FrameShadowFactory( QObject* parent ): QObject( parent ) {} - //* destructor - virtual ~FrameShadowFactory( void ) - {} - //* register widget bool registerWidget( QWidget*, StyleHelper& ); //* unregister void unregisterWidget( QWidget* ); //* true if widget is registered bool isRegistered( const QWidget* widget ) const { return _registeredWidgets.contains( widget ); } //* event filter - bool eventFilter( QObject*, QEvent*) ; + bool eventFilter( QObject*, QEvent*) override; //* set contrast void setHasContrast( const QWidget* widget, bool ) const; //* update state void updateState( const QWidget*, bool focus, bool hover, qreal opacity, AnimationMode ) const; //* update shadows geometry void updateShadowsGeometry( const QObject*, QRect ) const; protected: //* install shadows on given widget void installShadows( QWidget*, StyleHelper&, bool flat = false ); //* update shadows geometry void updateShadowsGeometry( QObject* ) const; //* remove shadows from widget void removeShadows( QWidget* ); //* raise shadows void raiseShadows( QObject* ) const; //* update shadows void update( QObject* ) const; //* install shadow on given side void installShadow( QWidget*, StyleHelper&, ShadowArea, bool flat = false ) const; protected Q_SLOTS: //* triggered by object destruction void widgetDestroyed( QObject* ); private: //* needed to block ChildAdded events when creating shadows AddEventFilter _addEventFilter; //* set of registered widgets QSet _registeredWidgets; }; //* frame shadow - /*! this allows the shadow to be painted over the widgets viewport */ + /** this allows the shadow to be painted over the widgets viewport */ class FrameShadowBase: public QWidget { Q_OBJECT public: //* constructor explicit FrameShadowBase( ShadowArea area ): - _area( area ), - _contrast( false ) - {} - - //* destructor - virtual ~FrameShadowBase( void ) + _area( area ) {} //* shadow area void setShadowArea(ShadowArea area) { _area = area; } //* shadow area const ShadowArea& shadowArea() const { return _area; } //* set contrast void setHasContrast( bool value ) { if( _contrast == value ) return; _contrast = value; } //* true if contrast pixel is enabled bool hasContrast( void ) const { return _contrast; } //* update geometry virtual void updateGeometry( void ) = 0; //* update geometry virtual void updateGeometry( QRect ) = 0; //* update state virtual void updateState( bool, bool, qreal, AnimationMode ) {} protected: //* initialization virtual void init(); //* return viewport associated to parent widget virtual QWidget* viewport( void ) const; //* parent margins /** offsets between update rect and parent widget rect. It is set via updateGeometry */ - virtual const QMargins& margins( void ) const + const QMargins& margins( void ) const { return _margins; } //* margins /** offsets between update rect and parent widget rect. It is set via updateGeometry */ - virtual void setMargins( const QMargins& margins ) + void setMargins( const QMargins& margins ) { _margins = margins; } private: //* shadow area ShadowArea _area; //* margins /** offsets between update rect and parent widget rect. It is set via updateGeometry */ QMargins _margins; //* contrast pixel - bool _contrast; + bool _contrast = false; }; //* frame shadow - /*! this allows the shadow to be painted over the widgets viewport */ + /** this allows the shadow to be painted over the widgets viewport */ class SunkenFrameShadow : public FrameShadowBase { Q_OBJECT public: //* constructor SunkenFrameShadow( ShadowArea area, StyleHelper& helper ): FrameShadowBase( area ), - _helper( helper ), - _hasFocus( false ), - _mouseOver( false ), - _opacity( -1 ), - _mode( AnimationNone ) + _helper( helper ) { init(); } - //* destructor - virtual ~SunkenFrameShadow() - {} - //* update geometry /** nothing is done. Rect must be passed explicitly */ - void updateGeometry( void ) + void updateGeometry( void ) override {} //* update geometry - void updateGeometry( QRect ) ; + void updateGeometry( QRect ) override; //* update state - void updateState( bool focus, bool hover, qreal opacity, AnimationMode ) ; + void updateState( bool focus, bool hover, qreal opacity, AnimationMode ) override; protected: //* painting - void paintEvent(QPaintEvent *) ; + void paintEvent(QPaintEvent *) override; private: //* helper StyleHelper& _helper; //*@name widget state //@{ - bool _hasFocus; - bool _mouseOver; - qreal _opacity; - AnimationMode _mode; + bool _hasFocus = false; + bool _mouseOver = false; + qreal _opacity = -1; + AnimationMode _mode = AnimationNone; }; //* frame shadow - /*! this allows the shadow to be painted over the widgets viewport */ + /** this allows the shadow to be painted over the widgets viewport */ class FlatFrameShadow : public FrameShadowBase { Q_OBJECT public: //* constructor FlatFrameShadow( ShadowArea area, StyleHelper& helper ): FrameShadowBase( area ), _helper( helper ) { init(); } - - //* destructor - virtual ~FlatFrameShadow() - {} - //* update geometry - void updateGeometry( void ) ; + void updateGeometry( void ) override; //* update geometry - void updateGeometry( QRect ) ; + void updateGeometry( QRect ) override; protected: //* painting - void paintEvent(QPaintEvent *) ; + void paintEvent(QPaintEvent *) override; private: //* helper StyleHelper& _helper; }; } #endif diff --git a/kstyle/oxygenmdiwindowshadow.h b/kstyle/oxygenmdiwindowshadow.h index 40727418..e4e09eda 100644 --- a/kstyle/oxygenmdiwindowshadow.h +++ b/kstyle/oxygenmdiwindowshadow.h @@ -1,181 +1,175 @@ #ifndef oxygenmdiwindowshadow_h #define oxygenmdiwindowshadow_h ////////////////////////////////////////////////////////////////////////////// // oxygenmdiwindowshadow.h // handle MDI windows' shadows // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Largely inspired from skulpture widget style // Copyright (c) 2007-2009 Christoph Feck // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include #include "oxygenstylehelper.h" #include "oxygentileset.h" namespace Oxygen { //* frame shadow /*! this allows the shadow to be painted over the widgets viewport */ class MdiWindowShadow: public QWidget { Q_OBJECT public: //* shadow size (hard coded) enum { ShadowSize = 10 }; //* constructor explicit MdiWindowShadow( QWidget*, TileSet ); //* update geometry void updateGeometry( void ); //* update ZOrder void updateZOrder( void ); //* set associated window void setWidget( QWidget* value ) { _widget = value; } //* associated window QWidget* widget( void ) const { return _widget; } protected: //* painting - void paintEvent(QPaintEvent *) ; + void paintEvent(QPaintEvent *) override; private: //* associated widget QWidget* _widget = nullptr; //* tileset rect, used for painting QRect _shadowTilesRect; //* tileset used to draw shadow TileSet _shadowTiles; }; //* shadow manager class MdiWindowShadowFactory: public QObject { Q_OBJECT public: //* constructor MdiWindowShadowFactory( QObject*, StyleHelper& ); - //* destructor - virtual ~MdiWindowShadowFactory( void ) - {} - //* register widget bool registerWidget( QWidget* ); //* unregister void unregisterWidget( QWidget* ); //* true if widget is registered bool isRegistered( const QObject* widget ) const { return _registeredWidgets.contains( widget ); } //* event filter - bool eventFilter( QObject*, QEvent*) ; + bool eventFilter( QObject*, QEvent*) override; - protected: + private Q_SLOTS: + + //* triggered by object destruction + void widgetDestroyed( QObject* ); + + private: //* find shadow matching a given object MdiWindowShadow* findShadow( QObject* ) const; //* install shadows on given widget void installShadow( QObject* ); //* remove shadows from widget void removeShadow( QObject* ); //* hide shadows void hideShadows( QObject* object ) const { if( MdiWindowShadow* windowShadow = findShadow( object ) ) { windowShadow->hide(); } } //* update ZOrder void updateShadowZOrder( QObject* object ) const { if( MdiWindowShadow* windowShadow = findShadow( object ) ) { if( !windowShadow->isVisible() ) windowShadow->show(); windowShadow->updateZOrder(); } } //* update shadows geometry void updateShadowGeometry( QObject* object ) const { if( MdiWindowShadow* windowShadow = findShadow( object ) ) { windowShadow->updateGeometry(); } } //* update shadows void update( QObject* object ) const { if( MdiWindowShadow* windowShadow = findShadow( object ) ) { windowShadow->update(); } } - protected Q_SLOTS: - - //* triggered by object destruction - void widgetDestroyed( QObject* ); - - private: - //* set of registered widgets QSet _registeredWidgets; //* tileset used to draw shadow TileSet _shadowTiles; }; } #endif diff --git a/kstyle/oxygenmnemonics.h b/kstyle/oxygenmnemonics.h index 621bafc3..f66fe743 100644 --- a/kstyle/oxygenmnemonics.h +++ b/kstyle/oxygenmnemonics.h @@ -1,78 +1,71 @@ #ifndef oxygenmnemonics_h #define oxygenmnemonics_h ////////////////////////////////////////////////////////////////////////////// // oxygenmnemonics.h // enable/disable mnemonics display // ------------------- // // Copyright (C) 2011 Hugo Pereira Da Costa // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License version 2 as published by the Free Software Foundation. // // This library 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 // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with this library; see the file COPYING.LIB. If not, write to // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. ////////////////////////////////////////////////////////////////////////////// #include #include #include #include "oxygenstyleconfigdata.h" namespace Oxygen { class Mnemonics: public QObject { public: - //! constructor + //* constructor explicit Mnemonics( QObject* parent ): - QObject( parent ), - _enabled( true ) + QObject( parent ) {} - //! destructor - virtual ~Mnemonics( void ) - {} - - //! set mode + //* set mode void setMode( int ); - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! true if mnemonics are enabled + //* true if mnemonics are enabled const bool& enabled( void ) const { return _enabled; } //* alignment flag int textFlags( void ) const { return _enabled ? Qt::TextShowMnemonic : Qt::TextHideMnemonic; } - protected: + private: - //! set enable state + //* set enable state void setEnabled( bool ); - private: - - //! enable state - bool _enabled; + //* enable state + bool _enabled = true; }; } #endif diff --git a/kstyle/oxygenshadowhelper.h b/kstyle/oxygenshadowhelper.h index 10097cac..e17202d4 100644 --- a/kstyle/oxygenshadowhelper.h +++ b/kstyle/oxygenshadowhelper.h @@ -1,213 +1,211 @@ #ifndef oxygenshadowhelper_h #define oxygenshadowhelper_h ////////////////////////////////////////////////////////////////////////////// // oxygenshadowhelper.h // handle shadow pixmaps passed to window manager via X property // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygen.h" #include "oxygentileset.h" #include "config-liboxygen.h" #include #include #include #if OXYGEN_HAVE_X11 #include #endif #if OXYGEN_HAVE_KWAYLAND namespace KWayland { namespace Client { class ShadowManager; class ShmPool; } } #endif namespace Oxygen { - //! forward declaration + //* forward declaration class ShadowCache; class StyleHelper; - //! handle shadow pixmaps passed to window manager via X property + //* handle shadow pixmaps passed to window manager via X property class ShadowHelper: public QObject { Q_OBJECT public: - //!@name property names + //*@name property names //@{ static const char netWMShadowAtomName[]; //@} - //! constructor + //* constructor ShadowHelper( QObject*, StyleHelper& ); - //! destructor - virtual ~ShadowHelper( void ); + //* destructor + ~ShadowHelper( void ) override; - //! reset + //* reset void reset( void ); - //! register widget + //* register widget bool registerWidget( QWidget*, bool force = false ); - //! unregister widget + //* unregister widget void unregisterWidget( QWidget* ); - //! reparse cache config (must be followed by loadConfig) + //* reparse cache config (must be followed by loadConfig) void reparseCacheConfig( void ); - //! load config + //* load config void loadConfig( void ); - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - protected Q_SLOTS: + private Q_SLOTS: - //! unregister widget + //* unregister widget void objectDeleted( QObject* ); - protected: + private: - //! true if widget is a menu + //* true if widget is a menu bool isMenu( QWidget* ) const; - //! true if widget is a tooltip + //* true if widget is a tooltip bool isToolTip( QWidget* ) const; - //! dock widget + //* dock widget bool isDockWidget( QWidget* ) const; - //! toolbar + //* toolbar bool isToolBar( QWidget* ) const; - //! accept widget + //* accept widget bool acceptWidget( QWidget* ) const; - //! shadow cache + //* shadow cache const ShadowCache& shadowCache( void ) const { return *_shadowCache; } - //! shadow cache + //* shadow cache ShadowCache& shadowCache( void ) { return *_shadowCache; } // create pixmap handles from tileset const QVector& createPixmapHandles( bool isDockWidget ); // create pixmap handle from pixmap quint32 createPixmap( const QPixmap& ); //* installs shadow on given widget in a platform independent way bool installShadows( QWidget * ); //* uninstalls shadow on given widget in a platform independent way void uninstallShadows( QWidget * ) const; - //! install shadow X11 property on given widget - /*! + //* install shadow X11 property on given widget + /** shadow atom and property specification available at http://community.kde.org/KWin/Shadow */ bool installX11Shadows( QWidget* ); - //! uninstall shadow X11 property on given widget + //* uninstall shadow X11 property on given widget void uninstallX11Shadows( QWidget* ) const; //* install shadow on given widget for Wayland bool installWaylandShadows( QWidget * ); //* uninstall shadow on given widget for Wayland void uninstallWaylandShadows( QWidget* ) const; //* initializes the Wayland specific parts void initializeWayland(); //* gets the shadow margins for the given widget QMargins shadowMargins( QWidget* ) const; - private: - - //! helper + //* helper StyleHelper& _helper; - //! cache + //* cache ShadowCache* _shadowCache; - //! set of registered widgets + //* set of registered widgets QMap _widgets; - //!@name shadow tilesets + //*@name shadow tilesets //@{ TileSet _tiles; TileSet _dockTiles; //@} - //! number of pixmaps + //* number of pixmaps enum { numPixmaps = 8 }; - //!@name pixmaps + //*@name pixmaps //@{ QVector _pixmaps; QVector _dockPixmaps; //@} - //! shadow size + //* shadow size int _size; #if OXYGEN_HAVE_X11 - //! graphical context + //* graphical context xcb_gcontext_t _gc; - //! shadow atom + //* shadow atom xcb_atom_t _atom; #endif #if OXYGEN_HAVE_KWAYLAND //* The Wayland shadow manager to create Shadows for Surfaces (QWindow) KWayland::Client::ShadowManager* _shadowManager; //* The Wayland Shared memory pool to share the shadow pixmaps with compositor KWayland::Client::ShmPool* _shmPool; #endif }; } #endif diff --git a/kstyle/oxygensplitterproxy.cpp b/kstyle/oxygensplitterproxy.cpp index 1c983113..a2b18da3 100644 --- a/kstyle/oxygensplitterproxy.cpp +++ b/kstyle/oxygensplitterproxy.cpp @@ -1,355 +1,351 @@ ////////////////////////////////////////////////////////////////////////////// // oxygensplitterproxy.cpp // Extended hit area for Splitters // ------------------- // // Copyright (C) 2011 Hugo Pereira Da Costa // // Based on Bespin splitterproxy code // Copyright (C) 2011 Thomas Luebking // // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License version 2 as published by the Free Software Foundation. // // This library 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 // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with this library; see the file COPYING.LIB. If not, write to // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. ////////////////////////////////////////////////////////////////////////////// #include "oxygensplitterproxy.h" #include "oxygenstyleconfigdata.h" #include #include #include namespace Oxygen { //____________________________________________________________________ void SplitterFactory::setEnabled( bool value ) { if( _enabled != value ) { // store _enabled = value; // assign to existing splitters for( WidgetMap::iterator iter = _widgets.begin(); iter != _widgets.end(); ++iter ) { if( iter.value() ) iter.value().data()->setEnabled( value ); } } } //____________________________________________________________________ bool SplitterFactory::registerWidget( QWidget *widget ) { // check widget type if( qobject_cast( widget ) ) { WidgetMap::iterator iter( _widgets.find( widget ) ); if( iter == _widgets.end() || !iter.value() ) { widget->installEventFilter( &_addEventFilter ); SplitterProxy* proxy( new SplitterProxy( widget, _enabled ) ); widget->removeEventFilter( &_addEventFilter ); widget->installEventFilter( proxy ); _widgets.insert( widget, proxy ); } else { widget->removeEventFilter( iter.value().data() ); widget->installEventFilter( iter.value().data() ); } return true; } else if( qobject_cast( widget ) ) { QWidget* window( widget->window() ); WidgetMap::iterator iter( _widgets.find( window ) ); if( iter == _widgets.end() || !iter.value() ) { window->installEventFilter( &_addEventFilter ); SplitterProxy* proxy( new SplitterProxy( window, _enabled ) ); window->removeEventFilter( &_addEventFilter ); widget->installEventFilter( proxy ); _widgets.insert( window, proxy ); } else { widget->removeEventFilter( iter.value().data() ); widget->installEventFilter( iter.value().data() ); } return true; } else return false; } //____________________________________________________________________ void SplitterFactory::unregisterWidget( QWidget *widget ) { WidgetMap::iterator iter( _widgets.find( widget ) ); if( iter != _widgets.end() ) { if( iter.value() ) iter.value().data()->deleteLater(); _widgets.erase( iter ); } } //____________________________________________________________________ SplitterProxy::SplitterProxy( QWidget* parent, bool enabled ): QWidget( parent ), _enabled( enabled ), _timerId( 0 ) { setAttribute( Qt::WA_TranslucentBackground, true ); setAttribute( Qt::WA_OpaquePaintEvent, false ); hide(); } - //____________________________________________________________________ - SplitterProxy::~SplitterProxy( void ) - {} - //____________________________________________________________________ void SplitterProxy::setEnabled( bool value ) { // make sure status has changed if( _enabled != value ) { _enabled = value; if( _enabled ) clearSplitter(); } } //____________________________________________________________________ bool SplitterProxy::eventFilter( QObject* object, QEvent* event ) { // do nothing if disabled if( !_enabled ) return false; // do nothing in case of mouse grab if( mouseGrabber() ) return false; switch( event->type() ) { case QEvent::HoverEnter: if( !isVisible() ) { // cast to splitter handle if( QSplitterHandle* handle = qobject_cast( object ) ) { setSplitter( handle ); } } return false; case QEvent::HoverMove: case QEvent::HoverLeave: return isVisible() && object == _splitter.data(); case QEvent::MouseMove: case QEvent::Timer: case QEvent::Move: return false; case QEvent::CursorChange: if( QWidget *window = qobject_cast( object ) ) { if( window->cursor().shape() == Qt::SplitHCursor || window->cursor().shape() == Qt::SplitVCursor ) { setSplitter( window ); } } return false; case QEvent::WindowDeactivate: case QEvent::MouseButtonRelease: clearSplitter(); return false; default: return false; } } //____________________________________________________________________ bool SplitterProxy::event( QEvent *event ) { switch( event->type() ) { case QEvent::MouseMove: case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: { // check splitter if( !_splitter ) return false; event->accept(); // grab on mouse press if( event->type() == QEvent::MouseButtonPress) { grabMouse(); resize(1,1); } // cast to mouse event QMouseEvent *mouseEvent( static_cast( event ) ); // get relevant position to post mouse drag event to application if( event->type() == QEvent::MouseButtonPress ) { // use hook, to make sure splitter is properly dragged QMouseEvent mouseEvent2( mouseEvent->type(), _hook, _splitter.data()->mapToGlobal(_hook), mouseEvent->button(), mouseEvent->buttons(), mouseEvent->modifiers()); QCoreApplication::sendEvent( _splitter.data(), &mouseEvent2 ); } else { // map event position to current splitter and post. QMouseEvent mouseEvent2( mouseEvent->type(), _splitter.data()->mapFromGlobal( mouseEvent->globalPos() ), mouseEvent->globalPos(), mouseEvent->button(), mouseEvent->buttons(), mouseEvent->modifiers()); QCoreApplication::sendEvent( _splitter.data(), &mouseEvent2 ); } // release grab on mouse-Release if( event->type() == QEvent::MouseButtonRelease && mouseGrabber() == this ) { releaseMouse(); } return true; } case QEvent::Timer: if( static_cast( event )->timerId() != _timerId ) { return QWidget::event( event ); } /* Fall through is intended. We somehow lost a QEvent::Leave before timeout. We fix it from here */ case QEvent::HoverLeave: case QEvent::Leave: { if( mouseGrabber() == this ) { return true; } // reset splitter if( isVisible() && !rect().contains( mapFromGlobal( QCursor::pos() ) ) ) { clearSplitter(); } return true; } default: return QWidget::event( event ); } } //____________________________________________________________________ void SplitterProxy::setSplitter( QWidget* widget ) { // check if changed if( _splitter.data() == widget ) return; // get cursor position const QPoint position( QCursor::pos() ); // store splitter and hook _splitter = widget; _hook = _splitter.data()->mapFromGlobal( position ); // adjust rect QRect rect( 0, 0, 2*StyleConfigData::splitterProxyWidth(), 2*StyleConfigData::splitterProxyWidth() ); rect.moveCenter( parentWidget()->mapFromGlobal( position ) ); setGeometry( rect ); setCursor( _splitter.data()->cursor().shape() ); // show raise(); show(); // timer used to automatically hide proxy in case leave events are lost if( !_timerId ) _timerId = startTimer(150); } //____________________________________________________________________ void SplitterProxy::clearSplitter( void ) { // check if changed if( !_splitter ) return; // release mouse if( mouseGrabber() == this ) releaseMouse(); // hide parentWidget()->setUpdatesEnabled(false); hide(); parentWidget()->setUpdatesEnabled(true); // send hover event if( _splitter ) { QHoverEvent hoverEvent( qobject_cast(_splitter.data()) ? QEvent::HoverLeave : QEvent::HoverMove, _splitter.data()->mapFromGlobal(QCursor::pos()), _hook); QCoreApplication::sendEvent( _splitter.data(), &hoverEvent ); _splitter.clear(); } // kill timer if any if( _timerId ) { killTimer( _timerId ); _timerId = 0; } } } diff --git a/kstyle/oxygensplitterproxy.h b/kstyle/oxygensplitterproxy.h index 4eaea9c7..92e04b44 100644 --- a/kstyle/oxygensplitterproxy.h +++ b/kstyle/oxygensplitterproxy.h @@ -1,142 +1,132 @@ #ifndef oxygensplitterproxy_h #define oxygensplitterproxy_h ////////////////////////////////////////////////////////////////////////////// // oxygensplitterproxy.h // Extended hit area for Splitters // ------------------- // // Copyright (C) 2011 Hugo Pereira Da Costa // // Based on Bespin splitterproxy code // Copyright (C) 2011 Thomas Luebking // // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License version 2 as published by the Free Software Foundation. // // This library 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 // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with this library; see the file COPYING.LIB. If not, write to // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. ////////////////////////////////////////////////////////////////////////////// #include "oxygen.h" #include #include #include #include #include #include #include #include "oxygenaddeventfilter.h" namespace Oxygen { class SplitterProxy; - //! factory + //* factory class SplitterFactory: public QObject { public: - //! constructor + //* constructor explicit SplitterFactory( QObject* parent ): - QObject( parent ), - _enabled( false ) + QObject( parent ) {} - //! destructor - virtual ~SplitterFactory( void ) - {} - - //! enabled state + //* enabled state void setEnabled( bool ); - //! register widget + //* register widget bool registerWidget( QWidget* ); - //! unregister widget + //* unregister widget void unregisterWidget( QWidget* ); private: - //! enabled state - bool _enabled; + //* enabled state + bool _enabled = false; - //! needed to block ChildAdded events when creating proxy + //* needed to block ChildAdded events when creating proxy AddEventFilter _addEventFilter; - //! pointer to SplitterProxy + //* pointer to SplitterProxy using SplitterProxyPointer = WeakPointer; - //! registered widgets + //* registered widgets using WidgetMap = QMap; WidgetMap _widgets; }; - //! splitter 'proxy' widget, with extended hit area + //* splitter 'proxy' widget, with extended hit area class SplitterProxy : public QWidget { public: - //! constructor + //* constructor explicit SplitterProxy( QWidget*, bool = false ); - //! destructor - virtual ~SplitterProxy( void ); - - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! enable state + //* enable state void setEnabled( bool ); - //! enable state + //* enable state bool enabled( void ) const { return _enabled; } protected: - //! event handler - bool event( QEvent* ) ; + //* event handler + bool event( QEvent* ) override; - protected: + private: - //! reset 'true' splitter widget + //* reset 'true' splitter widget void clearSplitter( void ); - //! keep track of 'true' splitter widget + //* keep track of 'true' splitter widget void setSplitter( QWidget* ); - private: - - //! enabled state - bool _enabled; + //* enabled state + bool _enabled = false; - //! splitter object + //* splitter object WeakPointer _splitter; - //! hook + //* hook QPoint _hook; - //! timer id - int _timerId; + //* timer id + int _timerId = 0; }; } #endif diff --git a/kstyle/oxygenstyle.cpp b/kstyle/oxygenstyle.cpp index d55d438e..0e78ff13 100644 --- a/kstyle/oxygenstyle.cpp +++ b/kstyle/oxygenstyle.cpp @@ -1,8811 +1,8802 @@ // krazy:excludeall=qclasses ////////////////////////////////////////////////////////////////////////////// // oxygenstyle.cpp // Oxygen widget style for KDE 4 // ------------------- // // Copyright ( C ) 2009-2010 Hugo Pereira Da Costa // Copyright ( C ) 2008 Long Huynh Huu // Copyright ( C ) 2007-2008 Casper Boemann // Copyright ( C ) 2007 Matthew Woehlke // Copyright ( C ) 2003-2005 Sandro Giessl // // based on the KDE style "dotNET": // Copyright ( C ) 2001-2002, Chris Lee // Carsten Pfeiffer // Karol Szwed // Drawing routines completely reimplemented from KDE3 +HighColor, which was // originally based on some stuff from the KDE2 HighColor. // // based on drawing routines of the style "Keramik": // Copyright ( c ) 2002 Malte Starostik // ( c ) 2002,2003 Maksim Orlovich // based on the KDE3 HighColor Style // Copyright ( C ) 2001-2002 Karol Szwed // ( C ) 2001-2002 Fredrik H?glund // Drawing routines adapted from the KDE2 HCStyle, // Copyright ( C ) 2000 Daniel M. Duley // ( C ) 2000 Dirk Mueller // ( C ) 2001 Martijn Klingens // Progressbar code based on KStyle, // Copyright ( C ) 2001-2002 Karol Szwed // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License version 2 as published by the Free Software Foundation. // // This library 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 // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with this library; see the file COPYING.LIB. If not, write to // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. ////////////////////////////////////////////////////////////////////////////// #include "oxygenstyle.h" #include "oxygen.h" #include "oxygenanimations.h" #include "oxygenblurhelper.h" #include "oxygenframeshadow.h" #include "oxygenmdiwindowshadow.h" #include "oxygenmnemonics.h" #include "oxygenpropertynames.h" #include "oxygenshadowhelper.h" #include "oxygensplitterproxy.h" #include "oxygenstyleconfigdata.h" #include "oxygentransitions.h" #include "oxygenwidgetexplorer.h" #include "oxygenwindowmanager.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace OxygenPrivate { /*! tabBar data class needed for the rendering of tabbars when one tab is being drawn */ class TabBarData: public QObject { public: - //! constructor + //* constructor explicit TabBarData( Oxygen::Style* parent ): QObject( parent ), - _style( parent ), - _dirty( false ) + _style( parent ) {} - //! destructor - virtual ~TabBarData( void ) - {} - - //! assign target tabBar + //* assign target tabBar void lock( const QWidget* widget ) { _tabBar = widget; } - //! true if tabbar is locked + //* true if tabbar is locked bool locks( const QWidget* widget ) const { return _tabBar && _tabBar.data() == widget; } - //! set dirty + //* set dirty void setDirty( const bool& value = true ) { _dirty = value; } - //! release + //* release void release( void ) { _tabBar.clear(); } - //! draw tabBarBase + //* draw tabBarBase virtual void drawTabBarBaseControl( const QStyleOptionTab*, QPainter*, const QWidget* ); private: - //! pointer to parent style object + //* pointer to parent style object Oxygen::WeakPointer _style; - //! pointer to target tabBar + //* pointer to target tabBar Oxygen::WeakPointer _tabBar; - //! if true, will paint on next TabBarTabShapeControl call - bool _dirty; + //* if true, will paint on next TabBarTabShapeControl call + bool _dirty = false; }; - //! needed to have spacing added to items in combobox + //* needed to have spacing added to items in combobox class ComboBoxItemDelegate: public QItemDelegate { public: - //! constructor + //* constructor ComboBoxItemDelegate( QAbstractItemView* parent ): QItemDelegate( parent ), _proxy( parent->itemDelegate() ), _itemMargin( Oxygen::Metrics::ItemView_ItemMarginWidth ) {} - //! destructor - virtual ~ComboBoxItemDelegate( void ) - {} - - //! paint - void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const + //* paint + void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override { // call either proxy or parent class if( _proxy ) _proxy.data()->paint( painter, option, index ); else QItemDelegate::paint( painter, option, index ); } - //! size hint for index - QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const + //* size hint for index + QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const override { // get size from either proxy or parent class QSize size( _proxy ? _proxy.data()->sizeHint( option, index ): QItemDelegate::sizeHint( option, index ) ); // adjust and return if( size.isValid() ) { size.rheight() += _itemMargin*2; } return size; } private: - //! proxy + //* proxy Oxygen::WeakPointer _proxy; - //! margin + //* margin int _itemMargin; }; } namespace Oxygen { - //! toplevel manager + //* toplevel manager class TopLevelManager: public QObject { public: - //! constructor + //* constructor TopLevelManager( QObject* parent, const StyleHelper& helper ): QObject( parent ), _helper( helper ) {} - //! event filter - bool eventFilter(QObject* object, QEvent* event ) + //* event filter + bool eventFilter(QObject* object, QEvent* event ) override { // cast to QWidget QWidget *widget = static_cast( object ); if( event->type() == QEvent::Show && _helper.hasDecoration( widget ) ) { _helper.setHasBackgroundGradient( widget->winId(), true ); } return false; } private: - //! helper + //* helper const StyleHelper& _helper; }; //______________________________________________________________ Style::Style( void ): #if OXYGEN_USE_KDE4 _helper( new StyleHelper( "oxygen" ) ) #else _helper( new StyleHelper( StyleConfigData::self()->sharedConfig() ) ) #endif ,_shadowHelper( new ShadowHelper( this, *_helper ) ) ,_animations( new Animations( this ) ) ,_transitions( new Transitions( this ) ) ,_windowManager( new WindowManager( this ) ) ,_topLevelManager( new TopLevelManager( this, *_helper ) ) ,_frameShadowFactory( new FrameShadowFactory( this ) ) ,_mdiWindowShadowFactory( new MdiWindowShadowFactory( this, *_helper ) ) ,_mnemonics( new Mnemonics( this ) ) ,_blurHelper( new BlurHelper( this, *_helper ) ) ,_widgetExplorer( new WidgetExplorer( this ) ) ,_tabBarData( new OxygenPrivate::TabBarData( this ) ) ,_splitterFactory( new SplitterFactory( this ) ) ,SH_ArgbDndWindow( newStyleHint( QStringLiteral( "SH_ArgbDndWindow" ) ) ) ,CE_CapacityBar( newControlElement( QStringLiteral( "CE_CapacityBar" ) ) ) { // use DBus connection to update on oxygen configuration change QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.connect( QString(), QStringLiteral( "/OxygenStyle" ), QStringLiteral( "org.kde.Oxygen.Style" ), QStringLiteral( "reparseConfiguration" ), this, SLOT(configurationChanged()) ); // call the slot directly; this initial call will set up things that also // need to be reset when the system palette changes loadConfiguration(); } //______________________________________________________________ Style::~Style( void ) { // _shadowHelper is a child of us, but its destructor uses _helper so we // delete it manually to ensure it is deleted *before* _helper is // deleted delete _shadowHelper; delete _helper; } //______________________________________________________________ void Style::polish( QWidget* widget ) { if( !widget ) return; // register widget to animations _animations->registerWidget( widget ); _transitions->registerWidget( widget ); _windowManager->registerWidget( widget ); _frameShadowFactory->registerWidget( widget, *_helper ); _mdiWindowShadowFactory->registerWidget( widget ); _shadowHelper->registerWidget( widget ); _splitterFactory->registerWidget( widget ); // scroll areas if( QAbstractScrollArea* scrollArea = qobject_cast( widget ) ) { polishScrollArea( scrollArea ); } // several widgets set autofill background to false, which effectively breaks the background // gradient rendering. Instead of patching all concerned applications, // we change the background here if( widget->inherits( "MessageList::Core::Widget" ) ) { widget->setAutoFillBackground( false ); } // adjust layout for K3B themed headers // FIXME: to be removed when fixed upstream if( widget->inherits( "K3b::ThemedHeader" ) && widget->layout() ) { widget->layout()->setMargin( 0 ); _frameShadowFactory->setHasContrast( widget, true ); } // adjust flags for windows and dialogs switch( widget->windowFlags() & Qt::WindowType_Mask ) { case Qt::Window: case Qt::Dialog: // set background as styled widget->setAttribute( Qt::WA_StyledBackground ); widget->installEventFilter( _topLevelManager ); break; default: break; } // enforce translucency for drag and drop window if( widget->testAttribute( Qt::WA_X11NetWmWindowTypeDND ) && _helper->compositingActive() ) { widget->setAttribute( Qt::WA_TranslucentBackground ); widget->clearMask(); } if( qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || widget->inherits( "KTextEditor::View" ) ) { widget->setAttribute( Qt::WA_Hover ); } // transparent tooltips if( widget->inherits( "QTipLabel" ) ) { widget->setAttribute( Qt::WA_TranslucentBackground ); #ifdef Q_WS_WIN //FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint ); #endif } if( QAbstractItemView *itemView = qobject_cast( widget ) ) { // enable hover effects in itemviews' viewport itemView->viewport()->setAttribute( Qt::WA_Hover ); } else if( QAbstractScrollArea* scrollArea = qobject_cast( widget ) ) { // enable hover effect in sunken scrollareas that support focus if( scrollArea->frameShadow() == QFrame::Sunken && widget->focusPolicy()&Qt::StrongFocus ) { widget->setAttribute( Qt::WA_Hover ); } } else if( QGroupBox* groupBox = qobject_cast( widget ) ) { // checkable group boxes if( groupBox->isCheckable() ) { groupBox->setAttribute( Qt::WA_Hover ); } } else if( qobject_cast( widget ) && qobject_cast( widget->parent() ) ) { widget->setAttribute( Qt::WA_Hover ); } else if( qobject_cast( widget ) && qobject_cast( widget->parent() ) ) { widget->setAttribute( Qt::WA_Hover ); } if( qobject_cast( widget ) ) { if( qobject_cast( widget->parent() ) ) { // this hack is needed to have correct text color // rendered in toolbars. This does not really update nicely when changing styles // but is the best I can do for now since setting the palette color at painting // time is not doable QPalette palette( widget->palette() ); palette.setColor( QPalette::Disabled, QPalette::ButtonText, palette.color( QPalette::Disabled, QPalette::WindowText ) ); palette.setColor( QPalette::Active, QPalette::ButtonText, palette.color( QPalette::Active, QPalette::WindowText ) ); palette.setColor( QPalette::Inactive, QPalette::ButtonText, palette.color( QPalette::Inactive, QPalette::WindowText ) ); widget->setPalette( palette ); } widget->setBackgroundRole( QPalette::NoRole ); if( widget->parentWidget() && widget->parentWidget()->parentWidget() && widget->parentWidget()->parentWidget()->inherits( "Gwenview::SideBarGroup" ) ) { widget->setProperty( PropertyNames::toolButtonAlignment, Qt::AlignLeft ); } } else if( qobject_cast( widget ) ) { widget->setBackgroundRole( QPalette::NoRole ); } else if( widget->inherits( "KMultiTabBar" ) ) { // kMultiTabBar margins are set to unity for alignment // with ( usually sunken ) neighbor frames widget->setContentsMargins( 1, 1, 1, 1 ); } else if( qobject_cast( widget ) ) { widget->setBackgroundRole( QPalette::NoRole ); addEventFilter( widget ); } else if( qobject_cast( widget ) ) { addEventFilter( widget ); } else if( widget->inherits( "QTipLabel" ) ) { widget->setBackgroundRole( QPalette::NoRole ); widget->setAttribute( Qt::WA_TranslucentBackground ); #ifdef Q_WS_WIN //FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint ); #endif } else if( qobject_cast( widget ) ) { widget->setAttribute( Qt::WA_OpaquePaintEvent, false ); // when painted in konsole, one needs to paint the window background below // the scrollarea, otherwise an ugly flat background is used if( widget->parent() && widget->parent()->inherits( "Konsole::TerminalDisplay" ) ) { addEventFilter( widget ); } } else if( qobject_cast( widget ) ) { widget->setBackgroundRole( QPalette::NoRole ); widget->setContentsMargins( 3,3,3,3 ); addEventFilter( widget ); } else if( qobject_cast( widget ) ) { widget->setAutoFillBackground( false ); addEventFilter( widget ); } else if( qobject_cast( widget ) ) { widget->setBackgroundRole( QPalette::NoRole ); widget->setAutoFillBackground( false ); widget->setContentsMargins( 5,5,5,5 ); addEventFilter( widget ); } else if( widget->parentWidget() && widget->parentWidget()->parentWidget() && qobject_cast( widget->parentWidget()->parentWidget()->parentWidget() ) ) { widget->setBackgroundRole( QPalette::NoRole ); widget->setAutoFillBackground( false ); widget->parentWidget()->setAutoFillBackground( false ); } else if( qobject_cast( widget ) ) { widget->setAttribute( Qt::WA_TranslucentBackground ); #ifdef Q_WS_WIN //FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint ); #endif #if QT_VERSION >= 0x050000 } else if( qobject_cast( widget ) ) { addEventFilter( widget ); #endif } else if( QComboBox *comboBox = qobject_cast( widget ) ) { if( !hasParent( widget, "QWebView" ) ) { QAbstractItemView *itemView( comboBox->view() ); if( itemView && itemView->itemDelegate() && itemView->itemDelegate()->inherits( "QComboBoxDelegate" ) ) { itemView->setItemDelegate( new OxygenPrivate::ComboBoxItemDelegate( itemView ) ); } } } else if( widget->inherits( "QComboBoxPrivateContainer" ) ) { addEventFilter( widget ); widget->setAttribute( Qt::WA_TranslucentBackground ); #ifdef Q_WS_WIN //FramelessWindowHint is needed on windows to make WA_TranslucentBackground work properly widget->setWindowFlags( widget->windowFlags() | Qt::FramelessWindowHint ); #endif } else if( qobject_cast( widget ) && widget->parent() && widget->parent()->inherits( "KTitleWidget" ) ) { widget->setAutoFillBackground( false ); widget->setBackgroundRole( QPalette::Window ); } // base class polishing ParentStyleClass::polish( widget ); } //_______________________________________________________________ void Style::unpolish( QWidget* widget ) { // register widget to animations _animations->unregisterWidget( widget ); _transitions->unregisterWidget( widget ); _windowManager->unregisterWidget( widget ); _frameShadowFactory->unregisterWidget( widget ); _mdiWindowShadowFactory->unregisterWidget( widget ); _shadowHelper->unregisterWidget( widget ); _splitterFactory->unregisterWidget( widget ); _blurHelper->unregisterWidget( widget ); // event filters switch( widget->windowFlags() & Qt::WindowType_Mask ) { case Qt::Window: case Qt::Dialog: widget->removeEventFilter( this ); widget->setAttribute( Qt::WA_StyledBackground, false ); break; default: break; } // checkable group boxes if( QGroupBox* groupBox = qobject_cast( widget ) ) { if( groupBox->isCheckable() ) { groupBox->setAttribute( Qt::WA_Hover, false ); } } // hover flags if( qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) ) { widget->setAttribute( Qt::WA_Hover, false ); } // checkable group boxes if( QGroupBox* groupBox = qobject_cast( widget ) ) { if( groupBox->isCheckable() ) { groupBox->setAttribute( Qt::WA_Hover, false ); } } if( qobject_cast( widget ) || qobject_cast( widget ) || ( widget && qobject_cast( widget->parent() ) ) || qobject_cast( widget ) ) { widget->setBackgroundRole( QPalette::Button ); widget->removeEventFilter( this ); widget->clearMask(); } if( qobject_cast( widget ) ) { widget->removeEventFilter( this ); } else if( widget->inherits( "QTipLabel" ) ) { widget->setAttribute( Qt::WA_PaintOnScreen, false ); widget->setAttribute( Qt::WA_NoSystemBackground, false ); widget->clearMask(); } else if( qobject_cast( widget ) ) { widget->setAttribute( Qt::WA_OpaquePaintEvent ); } else if( qobject_cast( widget ) ) { widget->setContentsMargins( 0,0,0,0 ); widget->clearMask(); } else if( qobject_cast( widget ) ) { widget->setBackgroundRole( QPalette::Button ); widget->setContentsMargins( 0,0,0,0 ); widget->removeEventFilter( this ); } else if( qobject_cast( widget ) ) { widget->setAttribute( Qt::WA_PaintOnScreen, false ); widget->setAttribute( Qt::WA_NoSystemBackground, false ); widget->clearMask(); } else if( widget->inherits( "QComboBoxPrivateContainer" ) ) widget->removeEventFilter( this ); ParentStyleClass::unpolish( widget ); } //______________________________________________________________ int Style::pixelMetric( PixelMetric metric, const QStyleOption* option, const QWidget* widget ) const { // handle special cases switch( metric ) { case PM_DefaultFrameWidth: if( qobject_cast( widget ) ) return Metrics::LineEdit_FrameWidth; #if QT_VERSION >= 0x050000 else if( isQtQuickControl( option, widget ) ) { const QString &elementType = option->styleObject->property( "elementType" ).toString(); if( elementType == QLatin1String( "edit" ) || elementType == QLatin1String( "spinbox" ) ) { return Metrics::LineEdit_FrameWidth; } else if( elementType == QLatin1String( "combobox" ) ) { return Metrics::ComboBox_FrameWidth; } } #endif // fallback return Metrics::Frame_FrameWidth; case PM_ComboBoxFrameWidth: { const QStyleOptionComboBox* comboBoxOption( qstyleoption_cast< const QStyleOptionComboBox*>( option ) ); return comboBoxOption && comboBoxOption->editable ? Metrics::LineEdit_FrameWidth : Metrics::ComboBox_FrameWidth; } case PM_SpinBoxFrameWidth: return Metrics::SpinBox_FrameWidth; case PM_ToolBarFrameWidth: return Metrics::ToolBar_FrameWidth; case PM_ToolTipLabelFrameWidth: return Metrics::ToolTip_FrameWidth; // layout case PM_LayoutLeftMargin: case PM_LayoutTopMargin: case PM_LayoutRightMargin: case PM_LayoutBottomMargin: { /* use either Child margin or TopLevel margin, depending on widget type */ if( ( option && ( option->state & QStyle::State_Window ) ) || ( widget && widget->isWindow() ) ) { return Metrics::Layout_TopLevelMarginWidth; } else { return Metrics::Layout_ChildMarginWidth; } } case PM_LayoutHorizontalSpacing: return Metrics::Layout_DefaultSpacing; case PM_LayoutVerticalSpacing: return Metrics::Layout_DefaultSpacing; // buttons case PM_ButtonMargin: { /* HACK: needs special case for kcalc buttons, to prevent the application to set too small margins */ if( widget && widget->inherits( "KCalcButton" ) ) return Metrics::Button_MarginWidth + 4; else return Metrics::Button_MarginWidth; } // buttons case PM_ButtonDefaultIndicator: return 0; case PM_ButtonShiftHorizontal: return 0; case PM_ButtonShiftVertical: return 0; // menubars case PM_MenuBarPanelWidth: return 0; case PM_MenuBarHMargin: return 0; case PM_MenuBarVMargin: return 0; case PM_MenuBarItemSpacing: return 0; case PM_MenuDesktopFrameWidth: return 0; // menu buttons case PM_MenuButtonIndicator: return Metrics::MenuButton_IndicatorWidth; // toolbars case PM_ToolBarHandleExtent: return Metrics::ToolBar_HandleExtent; case PM_ToolBarSeparatorExtent: return Metrics::ToolBar_SeparatorWidth; case PM_ToolBarExtensionExtent: return pixelMetric( PM_SmallIconSize, option, widget ) + 2*Metrics::ToolButton_MarginWidth; case PM_ToolBarItemMargin: return 0; case PM_ToolBarItemSpacing: return Metrics::ToolBar_ItemSpacing; // tabbars case PM_TabBarTabShiftVertical: return 0; case PM_TabBarTabShiftHorizontal: return 0; case PM_TabBarTabOverlap: return Metrics::TabBar_TabOverlap; case PM_TabBarBaseOverlap: return Metrics::TabBar_BaseOverlap; case PM_TabBarTabHSpace: return 2*Metrics::TabBar_TabMarginWidth; case PM_TabBarTabVSpace: return 2*Metrics::TabBar_TabMarginHeight; case PM_TabCloseIndicatorWidth: case PM_TabCloseIndicatorHeight: return pixelMetric( PM_SmallIconSize, option, widget ); // scrollbars case PM_ScrollBarExtent: return StyleConfigData::scrollBarWidth() + 2; case PM_ScrollBarSliderMin: return Metrics::ScrollBar_MinSliderHeight; // title bar case PM_TitleBarHeight: return 2*Metrics::TitleBar_MarginWidth + pixelMetric( PM_SmallIconSize, option, widget ); // sliders case PM_SliderThickness: return Metrics::Slider_ControlThickness; case PM_SliderControlThickness: return Metrics::Slider_ControlThickness; case PM_SliderLength: return Metrics::Slider_ControlThickness; // checkboxes and radio buttons case PM_IndicatorWidth: return Metrics::CheckBox_Size; case PM_IndicatorHeight: return Metrics::CheckBox_Size; case PM_ExclusiveIndicatorWidth: return Metrics::CheckBox_Size; case PM_ExclusiveIndicatorHeight: return Metrics::CheckBox_Size; // list heaaders case PM_HeaderMarkSize: return Metrics::Header_ArrowSize; case PM_HeaderMargin: return Metrics::Header_MarginWidth; // dock widget // return 0 here, since frame is handled directly in polish case PM_DockWidgetFrameWidth: return 0; case PM_DockWidgetTitleMargin: return Metrics::Frame_FrameWidth; case PM_DockWidgetTitleBarButtonMargin: return Metrics::ToolButton_MarginWidth; case PM_SplitterWidth: return Metrics::Splitter_SplitterWidth; case PM_DockWidgetSeparatorExtent: return Metrics::Splitter_SplitterWidth; // spacing between widget and scrollbars case PM_ScrollView_ScrollBarSpacing: if( const QFrame* frame = qobject_cast( widget ) ) { const bool framed( frame->frameShape() != QFrame::NoFrame ); return framed ? -1:0; } else return -1; // fallback default: return ParentStyleClass::pixelMetric( metric, option, widget ); } } //______________________________________________________________ int Style::styleHint( StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData ) const { /* special cases, that cannot be registered in styleHint map, because of conditional statements */ switch( hint ) { case SH_RubberBand_Mask: { if( QStyleHintReturnMask *mask = qstyleoption_cast( returnData ) ) { mask->region = option->rect; // need to check on widget before removing inner region // in order to still preserve rubberband in MainWindow and QGraphicsView // in QMainWindow because it looks better // in QGraphicsView because the painting fails completely otherwise if( widget && ( qobject_cast( widget->parent() ) || qobject_cast( widget->parent() ) || qobject_cast( widget->parent() ) ) ) { return true; } // also check if widget's parent is some itemView viewport if( widget && widget->parent() && qobject_cast( widget->parent()->parent() ) && static_cast( widget->parent()->parent() )->viewport() == widget->parent() ) { return true; } // mask out center mask->region -= insideMargin( option->rect, 1 ); return true; } return false; } case SH_ToolTip_Mask: case SH_Menu_Mask: { if( !_helper->hasAlphaChannel( widget ) && ( !widget || widget->isWindow() ) ) { // mask should be set only if compositing is disabled if( QStyleHintReturnMask *mask = qstyleoption_cast( returnData ) ) { mask->region = _helper->roundedMask( option->rect ); } } return true; } // mouse tracking case SH_ComboBox_ListMouseTracking: return true; case SH_MenuBar_MouseTracking: return true; case SH_Menu_MouseTracking: return true; case SH_Menu_SubMenuPopupDelay: return 150; case SH_Menu_SloppySubMenus: return true; case SH_ToolBox_SelectedPageTitleBold: return false; #if QT_VERSION >= 0x050000 case SH_Widget_Animate: return StyleConfigData::animationsEnabled(); case SH_Menu_SupportsSections: return true; #endif case SH_TitleBar_NoBorder: return false; case SH_GroupBox_TextLabelVerticalAlignment: return Qt::AlignVCenter; case SH_ScrollBar_MiddleClickAbsolutePosition: return true; case SH_ScrollView_FrameOnlyAroundContents: return true; case SH_FormLayoutFormAlignment: return Qt::AlignLeft | Qt::AlignTop; case SH_FormLayoutLabelAlignment: return Qt::AlignRight; case SH_FormLayoutFieldGrowthPolicy: return QFormLayout::ExpandingFieldsGrow; case SH_FormLayoutWrapPolicy: return QFormLayout::DontWrapRows; case SH_MessageBox_TextInteractionFlags: return Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse; case SH_RequestSoftwareInputPanel: return RSIP_OnMouseClick; case SH_ProgressDialog_CenterCancelButton: case SH_MessageBox_CenterButtons: return false; default: return ParentStyleClass::styleHint( hint, option, widget, returnData ); } } //______________________________________________________________ QRect Style::subElementRect( SubElement element, const QStyleOption* option, const QWidget* widget ) const { switch( element ) { case SE_PushButtonContents: return pushButtonContentsRect( option, widget ); case SE_CheckBoxContents: return checkBoxContentsRect( option, widget ); case SE_RadioButtonContents: return checkBoxContentsRect( option, widget ); case SE_LineEditContents: return lineEditContentsRect( option, widget ); case SE_ProgressBarGroove: return progressBarGrooveRect( option, widget ); case SE_ProgressBarContents: return progressBarContentsRect( option, widget ); case SE_ProgressBarLabel: return defaultSubElementRect( option, widget ); case SE_HeaderArrow: return headerArrowRect( option, widget ); case SE_HeaderLabel: return headerLabelRect( option, widget ); case SE_TabBarTabLeftButton: return tabBarTabLeftButtonRect( option, widget ); case SE_TabBarTabRightButton: return tabBarTabRightButtonRect( option, widget ); case SE_TabWidgetTabBar: return tabWidgetTabBarRect( option, widget ); case SE_TabWidgetTabContents: return tabWidgetTabContentsRect( option, widget ); case SE_TabWidgetTabPane: return tabWidgetTabPaneRect( option, widget ); case SE_TabWidgetLeftCorner: return tabWidgetCornerRect( SE_TabWidgetLeftCorner, option, widget ); case SE_TabWidgetRightCorner: return tabWidgetCornerRect( SE_TabWidgetRightCorner, option, widget ); case SE_ToolBoxTabContents: return toolBoxTabContentsRect( option, widget ); default: return ParentStyleClass::subElementRect( element, option, widget ); } } //______________________________________________________________ QRect Style::subControlRect( ComplexControl element, const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const { switch( element ) { case CC_GroupBox: return groupBoxSubControlRect( option, subControl, widget ); case CC_ToolButton: return toolButtonSubControlRect( option, subControl, widget ); case CC_ComboBox: return comboBoxSubControlRect( option, subControl, widget ); case CC_SpinBox: return spinBoxSubControlRect( option, subControl, widget ); case CC_ScrollBar: return scrollBarSubControlRect( option, subControl, widget ); case CC_Slider: return sliderSubControlRect( option, subControl, widget ); // fallback default: return ParentStyleClass::subControlRect( element, option, subControl, widget ); } } //______________________________________________________________ QSize Style::sizeFromContents( ContentsType element, const QStyleOption* option, const QSize& size, const QWidget* widget ) const { switch( element ) { case CT_CheckBox: return checkBoxSizeFromContents( option, size, widget ); case CT_RadioButton: return checkBoxSizeFromContents( option, size, widget ); case CT_LineEdit: return lineEditSizeFromContents( option, size, widget ); case CT_ComboBox: return comboBoxSizeFromContents( option, size, widget ); case CT_SpinBox: return spinBoxSizeFromContents( option, size, widget ); case CT_Slider: return sliderSizeFromContents( option, size, widget ); case CT_PushButton: return pushButtonSizeFromContents( option, size, widget ); case CT_ToolButton: return toolButtonSizeFromContents( option, size, widget ); case CT_MenuBar: return defaultSizeFromContents( option, size, widget ); case CT_MenuBarItem: return menuBarItemSizeFromContents( option, size, widget ); case CT_MenuItem: return menuItemSizeFromContents( option, size, widget ); case CT_TabWidget: return tabWidgetSizeFromContents( option, size, widget ); case CT_TabBarTab: return tabBarTabSizeFromContents( option, size, widget ); case CT_HeaderSection: return headerSectionSizeFromContents( option, size, widget ); case CT_ItemViewItem: return itemViewItemSizeFromContents( option, size, widget ); default: return ParentStyleClass::sizeFromContents( element, option, size, widget ); } } //______________________________________________________________ QStyle::SubControl Style::hitTestComplexControl( ComplexControl control, const QStyleOptionComplex* option, const QPoint& point, const QWidget* widget ) const { switch( control ) { case CC_ScrollBar: { QRect grooveRect = subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ); if( grooveRect.contains( point ) ) { //Must be either page up/page down, or just click on the slider. //Grab the slider to compare QRect sliderRect = subControlRect( CC_ScrollBar, option, SC_ScrollBarSlider, widget ); if( sliderRect.contains( point ) ) return SC_ScrollBarSlider; else if( preceeds( point, sliderRect, option ) ) return SC_ScrollBarSubPage; else return SC_ScrollBarAddPage; } //This is one of the up/down buttons. First, decide which one it is. if( preceeds( point, grooveRect, option ) ) { if( _subLineButtons == DoubleButton ) { QRect buttonRect = scrollBarInternalSubControlRect( option, SC_ScrollBarSubLine ); return scrollBarHitTest( buttonRect, point, option ); } else return SC_ScrollBarSubLine; } if( _addLineButtons == DoubleButton ) { QRect buttonRect = scrollBarInternalSubControlRect( option, SC_ScrollBarAddLine ); return scrollBarHitTest( buttonRect, point, option ); } else return SC_ScrollBarAddLine; } // fallback default: return ParentStyleClass::hitTestComplexControl( control, option, point, widget ); } } //______________________________________________________________ void Style::drawPrimitive( PrimitiveElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { StylePrimitive fcn( nullptr ); switch( element ) { case PE_PanelButtonCommand: fcn = &Style::drawPanelButtonCommandPrimitive; break; case PE_PanelButtonTool: fcn = &Style::drawPanelButtonToolPrimitive; break; case PE_PanelScrollAreaCorner: fcn = &Style::drawPanelScrollAreaCornerPrimitive; break; case PE_PanelMenu: fcn = &Style::drawPanelMenuPrimitive; break; case PE_PanelTipLabel: fcn = &Style::drawPanelTipLabelPrimitive; break; case PE_PanelItemViewItem: fcn = &Style::drawPanelItemViewItemPrimitive; break; case PE_IndicatorCheckBox: fcn = &Style::drawIndicatorCheckBoxPrimitive; break; case PE_IndicatorRadioButton: fcn = &Style::drawIndicatorRadioButtonPrimitive; break; case PE_IndicatorButtonDropDown: fcn = &Style::drawIndicatorButtonDropDownPrimitive; break; case PE_IndicatorTabClose: fcn = &Style::drawIndicatorTabClosePrimitive; break; case PE_IndicatorTabTear: fcn = &Style::drawIndicatorTabTearPrimitive; break; case PE_IndicatorArrowUp: fcn = &Style::drawIndicatorArrowUpPrimitive; break; case PE_IndicatorArrowDown: fcn = &Style::drawIndicatorArrowDownPrimitive; break; case PE_IndicatorArrowLeft: fcn = &Style::drawIndicatorArrowLeftPrimitive; break; case PE_IndicatorArrowRight: fcn = &Style::drawIndicatorArrowRightPrimitive; break; case PE_IndicatorMenuCheckMark: fcn = &Style::drawIndicatorMenuCheckMarkPrimitive; break; case PE_IndicatorHeaderArrow: fcn = &Style::drawIndicatorHeaderArrowPrimitive; break; case PE_IndicatorToolBarHandle: fcn = &Style::drawIndicatorToolBarHandlePrimitive; break; case PE_IndicatorToolBarSeparator: fcn = &Style::drawIndicatorToolBarSeparatorPrimitive; break; case PE_IndicatorBranch: fcn = &Style::drawIndicatorBranchPrimitive; break; case PE_IndicatorDockWidgetResizeHandle: fcn = &Style::drawIndicatorDockWidgetResizeHandlePrimitive; break; case PE_FrameStatusBar: fcn = &Style::emptyPrimitive; break; case PE_Frame: fcn = &Style::drawFramePrimitive; break; case PE_FrameLineEdit: fcn = &Style::drawFrameLineEditPrimitive; break; case PE_FrameMenu: fcn = &Style::drawFrameMenuPrimitive; break; case PE_FrameGroupBox: fcn = &Style::drawFrameGroupBoxPrimitive; break; case PE_FrameTabWidget: fcn = &Style::drawFrameTabWidgetPrimitive; break; case PE_FrameTabBarBase: fcn = &Style::drawFrameTabBarBasePrimitive; break; case PE_FrameWindow: fcn = &Style::drawFrameWindowPrimitive; break; case PE_FrameFocusRect: fcn = _frameFocusPrimitive; break; case PE_Widget: fcn = &Style::drawWidgetPrimitive; break; // fallback default: break; } painter->save(); // call function if implemented if( !( fcn && ( this->*fcn )( option, painter, widget ) ) ) { ParentStyleClass::drawPrimitive( element, option, painter, widget ); } painter->restore(); } //______________________________________________________________ void Style::drawControl( ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { StyleControl fcn( nullptr ); if( element == CE_CapacityBar ) { fcn = &Style::drawProgressBarControl; } else switch( element ) { case CE_ComboBoxLabel: break; case CE_DockWidgetTitle: fcn = &Style::drawDockWidgetTitleControl; break; case CE_HeaderEmptyArea: fcn = &Style::drawHeaderEmptyAreaControl; break; case CE_HeaderLabel: break; case CE_HeaderSection: fcn = &Style::drawHeaderSectionControl; break; case CE_MenuBarEmptyArea: fcn = &Style::emptyControl; break; case CE_MenuBarItem: fcn = &Style::drawMenuBarItemControl; break; case CE_MenuItem: fcn = &Style::drawMenuItemControl; break; case CE_ProgressBar: fcn = &Style::drawProgressBarControl; break; case CE_ProgressBarContents: fcn = &Style::drawProgressBarContentsControl; break; case CE_ProgressBarGroove: fcn = &Style::drawProgressBarGrooveControl; break; case CE_ProgressBarLabel: fcn = &Style::drawProgressBarLabelControl; break; case CE_PushButtonBevel: fcn = &Style::drawPanelButtonCommandPrimitive; break; case CE_PushButtonLabel: fcn = &Style::drawPushButtonLabelControl; break; case CE_RubberBand: fcn = &Style::drawRubberBandControl; break; case CE_ScrollBarSlider: fcn = &Style::drawScrollBarSliderControl; break; case CE_ScrollBarAddLine: fcn = &Style::drawScrollBarAddLineControl; break; case CE_ScrollBarSubLine: fcn = &Style::drawScrollBarSubLineControl; break; case CE_ScrollBarAddPage: fcn = &Style::emptyControl; break; case CE_ScrollBarSubPage: fcn = &Style::emptyControl; break; case CE_ShapedFrame: fcn = &Style::drawShapedFrameControl; break; case CE_SizeGrip: fcn = &Style::emptyControl; break; case CE_Splitter: fcn = &Style::drawSplitterControl; break; case CE_TabBarTabLabel: fcn = &Style::drawTabBarTabLabelControl; break; case CE_TabBarTabShape: fcn = &Style::drawTabBarTabShapeControl; break; case CE_ToolBar: fcn = &Style::drawToolBarControl; break; case CE_ToolBoxTabLabel: fcn = &Style::drawToolBoxTabLabelControl; break; case CE_ToolBoxTabShape: fcn = &Style::drawToolBoxTabShapeControl; break; case CE_ToolButtonLabel: fcn = &Style::drawToolButtonLabelControl; break; default: break; } painter->save(); // call function if implemented if( !( fcn && ( this->*fcn )( option, painter, widget ) ) ) { ParentStyleClass::drawControl( element, option, painter, widget ); } painter->restore(); } //______________________________________________________________ void Style::drawComplexControl( ComplexControl element, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { StyleComplexControl fcn( nullptr ); switch( element ) { case CC_GroupBox: break; case CC_ToolButton: fcn = &Style::drawToolButtonComplexControl; break; case CC_ComboBox: fcn = &Style::drawComboBoxComplexControl; break; case CC_SpinBox: fcn = &Style::drawSpinBoxComplexControl; break; case CC_Slider: fcn = &Style::drawSliderComplexControl; break; case CC_Dial: fcn = &Style::drawDialComplexControl; break; case CC_ScrollBar: fcn = &Style::drawScrollBarComplexControl; break; case CC_TitleBar: fcn = &Style::drawTitleBarComplexControl; break; // fallback default: break; } painter->save(); // call function if implemented if( !( fcn && ( this->*fcn )( option, painter, widget ) ) ) { ParentStyleClass::drawComplexControl( element, option, painter, widget ); } painter->restore(); } //___________________________________________________________________________________ void Style::drawItemText( QPainter* painter, const QRect& rect, int flags, const QPalette& palette, bool enabled, const QString &text, QPalette::ColorRole textRole ) const { // hide mnemonics if requested if( !_mnemonics->enabled() && ( flags&Qt::TextShowMnemonic ) && !( flags&Qt::TextHideMnemonic ) ) { flags &= ~Qt::TextShowMnemonic; flags |= Qt::TextHideMnemonic; } // make sure vertical alignment is defined // fallback on Align::VCenter if not if( !(flags&Qt::AlignVertical_Mask) ) flags |= Qt::AlignVCenter; - if( _animations->widgetEnabilityEngine().enabled() ) + if( _animations->widgetEnableStateEngine().enabled() ) { /* - check if painter engine is registered to WidgetEnabilityEngine, and animated + check if painter engine is registered to widgetEnableStateEngine, and animated if yes, merge the palettes. Note: a static_cast is safe here, since only the address of the pointer is used, not the actual content. */ const QWidget* widget( static_cast( painter->device() ) ); - if( _animations->widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) ) + if( _animations->widgetEnableStateEngine().isAnimated( widget, AnimationEnable ) ) { - const QPalette copy( _helper->disabledPalette( palette, _animations->widgetEnabilityEngine().opacity( widget, AnimationEnable ) ) ); + const QPalette copy( _helper->disabledPalette( palette, _animations->widgetEnableStateEngine().opacity( widget, AnimationEnable ) ) ); return ParentStyleClass::drawItemText( painter, rect, flags, copy, enabled, text, textRole ); } } // fallback return ParentStyleClass::drawItemText( painter, rect, flags, palette, enabled, text, textRole ); } //_____________________________________________________________________ bool Style::eventFilter( QObject *object, QEvent *event ) { if( QTabBar* tabBar = qobject_cast( object ) ) { return eventFilterTabBar( tabBar, event ); } else if( QToolBar* toolBar = qobject_cast( object ) ) { return eventFilterToolBar( toolBar, event ); } else if( QDockWidget* dockWidget = qobject_cast( object ) ) { return eventFilterDockWidget( dockWidget, event ); } else if( QToolBox* toolBox = qobject_cast( object ) ) { return eventFilterToolBox( toolBox, event ); } else if( QMdiSubWindow* subWindow = qobject_cast( object ) ) { return eventFilterMdiSubWindow( subWindow, event ); } else if( QScrollBar* scrollBar = qobject_cast( object ) ) { return eventFilterScrollBar( scrollBar, event ); } #if QT_VERSION >= 0x050000 else if( QCommandLinkButton* commandLinkButton = qobject_cast( object ) ) { return eventFilterCommandLinkButton( commandLinkButton, event ); } #endif // cast to QWidget QWidget *widget = static_cast( object ); if( widget->inherits( "QComboBoxPrivateContainer" ) ) { return eventFilterComboBoxContainer( widget, event ); } // fallback return ParentStyleClass::eventFilter( object, event ); } //_________________________________________________________ bool Style::eventFilterComboBoxContainer( QWidget* widget, QEvent* event ) { switch( event->type() ) { case QEvent::Show: case QEvent::Resize: { if( !_helper->hasAlphaChannel( widget ) ) widget->setMask( _helper->roundedMask( widget->size() ) ); else widget->clearMask(); return false; } case QEvent::Paint: { QPainter painter( widget ); QPaintEvent *paintEvent = static_cast( event ); painter.setClipRegion( paintEvent->region() ); const QRect rect( widget->rect() ); const QColor color( widget->palette().color( widget->window()->backgroundRole() ) ); const bool hasAlpha( _helper->hasAlphaChannel( widget ) ); if( hasAlpha ) { _helper->roundCorner( color ).render( rect, &painter ); painter.setCompositionMode( QPainter::CompositionMode_SourceOver ); painter.setClipPath( _helper->roundedPath( insideMargin( rect, 1 ) ), Qt::IntersectClip ); } // background _helper->renderMenuBackground( &painter, paintEvent->rect(), widget, widget->palette() ); // frame if( hasAlpha ) painter.setClipping( false ); _helper->drawFloatFrame( &painter, rect, color, !hasAlpha ); return false; } default: return false; } } //____________________________________________________________________________ bool Style::eventFilterDockWidget( QDockWidget* dockWidget, QEvent* event ) { switch( event->type() ) { case QEvent::Show: case QEvent::Resize: { // make sure mask is appropriate if( dockWidget->isFloating() ) dockWidget->setMask( _helper->roundedMask( dockWidget->size() ) ); else dockWidget->clearMask(); return false; } case QEvent::Paint: { QPainter painter( dockWidget ); QPaintEvent *paintEvent = static_cast( event ); painter.setClipRegion( paintEvent->region() ); const QColor color( dockWidget->palette().color( QPalette::Window ) ); const QRect rect( dockWidget->rect() ); if( dockWidget->isWindow() ) { _helper->renderWindowBackground( &painter, rect, dockWidget, color, 0 ); #ifndef Q_WS_WIN _helper->drawFloatFrame( &painter, rect, color, !_helper->compositingActive() ); #endif } else { // need to draw window background for autoFilled dockWidgets for better rendering if( dockWidget->autoFillBackground() ) { _helper->renderWindowBackground( &painter, rect, dockWidget, color ); } // adjust color QColor top( _helper->backgroundColor( color, dockWidget, rect.topLeft() ) ); QColor bottom( _helper->backgroundColor( color, dockWidget, rect.bottomLeft() ) ); _helper->dockFrame( top, bottom ).render( rect, &painter ); } return false; } default: return false; } } //____________________________________________________________________________ bool Style::eventFilterMdiSubWindow( QMdiSubWindow* subWindow, QEvent* event ) { if( event->type() == QEvent::Paint ) { QPainter painter( subWindow ); QRect clip( static_cast( event )->rect() ); if( subWindow->isMaximized() ) _helper->renderWindowBackground( &painter, clip, subWindow, subWindow->palette() ); else { painter.setClipRect( clip ); const QRect rect( subWindow->rect() ); _helper->roundCorner( subWindow->palette().color( subWindow->backgroundRole() ) ).render( rect, &painter ); painter.setClipPath( _helper->roundedPath( insideMargin( rect, 1 ) ), Qt::IntersectClip ); _helper->renderWindowBackground( &painter, clip, subWindow, subWindow, subWindow->palette(), 0 ); } } // continue with normal painting return false; } //____________________________________________________________________________ #if QT_VERSION >= 0x050000 bool Style::eventFilterCommandLinkButton( QCommandLinkButton* button, QEvent* event ) { if( event->type() == QEvent::Paint ) { // painter QPainter painter( button ); painter.setClipRegion( static_cast( event )->region() ); const bool isFlat = false; // option QStyleOptionButton option; option.initFrom( button ); option.features |= QStyleOptionButton::CommandLinkButton; if( isFlat ) option.features |= QStyleOptionButton::Flat; option.text = QString(); option.icon = QIcon(); if( button->isChecked() ) option.state|=State_On; if( button->isDown() ) option.state|=State_Sunken; // frame drawControl(QStyle::CE_PushButton, &option, &painter, button ); // offset const int margin( Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth ); QPoint offset( margin, margin ); // state const State& state( option.state ); const bool enabled( state & State_Enabled ); // icon if( !button->icon().isNull() ) { const QSize pixmapSize( button->icon().actualSize( button->iconSize() ) ); const QRect pixmapRect( QPoint( offset.x(), button->description().isEmpty() ? (button->height() - pixmapSize.height())/2:offset.y() ), pixmapSize ); const QPixmap pixmap( button->icon().pixmap(pixmapSize, enabled ? QIcon::Normal : QIcon::Disabled, button->isChecked() ? QIcon::On : QIcon::Off) ); drawItemPixmap( &painter, pixmapRect, Qt::AlignCenter, pixmap ); offset.rx() += pixmapSize.width() + 4; } // text rect QRect textRect( offset, QSize( button->size().width() - offset.x() - margin, button->size().height() - 2*margin ) ); const QPalette::ColorRole textRole = QPalette::ButtonText; if( !button->text().isEmpty() ) { QFont font( button->font() ); font.setBold( true ); painter.setFont( font ); if( button->description().isEmpty() ) { drawItemText( &painter, textRect, Qt::AlignLeft|Qt::AlignVCenter|Qt::TextHideMnemonic, button->palette(), enabled, button->text(), textRole ); } else { drawItemText( &painter, textRect, Qt::AlignLeft|Qt::AlignTop|Qt::TextHideMnemonic, button->palette(), enabled, button->text(), textRole ); textRect.setTop( textRect.top() + QFontMetrics( font ).height() ); } painter.setFont( button->font() ); } if( !button->description().isEmpty() ) { drawItemText( &painter, textRect, Qt::AlignLeft|Qt::AlignVCenter|Qt::TextWordWrap, button->palette(), enabled, button->description(), textRole ); } return true; } // continue with normal painting return false; } #endif //_________________________________________________________ bool Style::eventFilterScrollBar( QWidget* widget, QEvent* event ) { if( event->type() == QEvent::Paint ) { QPainter painter( widget ); painter.setClipRegion( static_cast( event )->region() ); _helper->renderWindowBackground( &painter, widget->rect(), widget,widget->palette() ); } return false; } //_____________________________________________________________________ bool Style::eventFilterTabBar( QWidget* widget, QEvent* event ) { if( event->type() == QEvent::Paint && _tabBarData->locks( widget ) ) { /* this makes sure that tabBar base is drawn ( and drawn only once ) every time a replaint is triggered by dragging a tab around */ _tabBarData->setDirty(); } return false; } //_____________________________________________________________________ bool Style::eventFilterToolBar( QToolBar* toolBar, QEvent* event ) { switch( event->type() ) { case QEvent::Show: case QEvent::Resize: { // make sure mask is appropriate if( toolBar->isFloating() ) { // TODO: should not be needed toolBar->setMask( _helper->roundedMask( toolBar->size() ) ); } else toolBar->clearMask(); return false; } case QEvent::Paint: { QPainter painter( toolBar ); QPaintEvent *paintEvent = static_cast( event ); painter.setClipRegion( paintEvent->region() ); const QRect rect( toolBar->rect() ); const QColor color( toolBar->palette().window().color() ); // default painting when not qrealing if( !toolBar->isFloating() ) { // background has to be rendered explicitly // when one of the parent has autofillBackground set to true if( _helper->checkAutoFillBackground( toolBar ) ) { _helper->renderWindowBackground( &painter, rect, toolBar, color, 0 ); } return false; } else { // background _helper->renderWindowBackground( &painter, rect, toolBar, color ); if( toolBar->isMovable() ) { // remaining painting: need to add handle // this is copied from QToolBar::paintEvent QStyleOptionToolBar opt; opt.initFrom( toolBar ); if( toolBar->orientation() == Qt::Horizontal ) { opt.rect = visualRect( &opt, QRect( rect.topLeft(), QSize( 8, rect.height() ) ) ); opt.state |= QStyle::State_Horizontal; } else { opt.rect = visualRect( &opt, QRect( rect.topLeft(), QSize( rect.width(), 8 ) ) ); } drawPrimitive( PE_IndicatorToolBarHandle, &opt, &painter, toolBar ); } #ifndef Q_WS_WIN if( _helper->compositingActive() ) _helper->drawFloatFrame( &painter, insideMargin( rect, -1 ), color, false ); else _helper->drawFloatFrame( &painter, rect, color, true ); #endif // do not propagate return true; } } default: return false; } } //____________________________________________________________________________ bool Style::eventFilterToolBox( QToolBox* toolBox, QEvent* event ) { if( event->type() == QEvent::Paint ) { if( toolBox->frameShape() != QFrame::NoFrame ) { const QRect rect( toolBox->rect() ); const StyleOptions styleOptions( NoFill ); QPainter painter( toolBox ); painter.setClipRegion( static_cast( event )->region() ); renderSlab( &painter, rect, toolBox->palette().color( QPalette::Button ), styleOptions ); } } return false; } //_____________________________________________________________________ void Style::configurationChanged() { // reload #if OXYGEN_USE_KDE4 StyleConfigData::self()->readConfig(); #else StyleConfigData::self()->load(); #endif _shadowHelper->reparseCacheConfig(); _helper->invalidateCaches(); loadConfiguration(); } //____________________________________________________________________ QIcon Style::standardIconImplementation( StandardPixmap standardPixmap, const QStyleOption *option, const QWidget *widget ) const { // MDI windows buttons // get button color ( unfortunately option and widget might not be set ) QColor buttonColor; QColor iconColor; if( option ) { buttonColor = option->palette.window().color(); iconColor = option->palette.windowText().color(); } else if( widget ) { buttonColor = widget->palette().window().color(); iconColor = widget->palette().windowText().color(); } else if( qApp ) { // might not have a QApplication buttonColor = QPalette().window().color(); iconColor = QPalette().windowText().color(); } else { // KCS is always safe buttonColor = KColorScheme( QPalette::Active, KColorScheme::Window, _helper->config() ).background().color(); iconColor = KColorScheme( QPalette::Active, KColorScheme::Window, _helper->config() ).foreground().color(); } // contrast const QColor contrast( _helper->calcLightColor( buttonColor ) ); const int iconSize( pixelMetric( QStyle::PM_SmallIconSize ) ); const QRect rect( 0, 0, iconSize, iconSize ); switch( standardPixmap ) { case SP_TitleBarNormalButton: { QPixmap pixmap( _helper->highDpiPixmap( rect.size() ) ); pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); renderTitleBarButton( &painter, rect, buttonColor, iconColor, SC_TitleBarNormalButton ); return QIcon( pixmap ); } case SP_TitleBarShadeButton: { QPixmap pixmap( _helper->highDpiPixmap( rect.size() ) ); pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); renderTitleBarButton( &painter, rect, buttonColor, iconColor, SC_TitleBarShadeButton ); return QIcon( pixmap ); } case SP_TitleBarUnshadeButton: { QPixmap pixmap( _helper->highDpiPixmap( rect.size() ) ); pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); renderTitleBarButton( &painter, rect, buttonColor, iconColor, SC_TitleBarUnshadeButton ); return QIcon( pixmap ); } case SP_TitleBarCloseButton: case SP_DockWidgetCloseButton: { QPixmap pixmap( _helper->highDpiPixmap( rect.size() ) ); pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); renderTitleBarButton( &painter, rect, buttonColor, iconColor, SC_TitleBarCloseButton ); return QIcon( pixmap ); } case SP_ToolBarHorizontalExtensionButton: { QIcon icon; // default icon sizes static const QList iconSizes = { 8, 16, 22, 32, 48 }; foreach( const int& iconSize, iconSizes ) { QPixmap pixmap( iconSize, iconSize ); pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); painter.setRenderHints( QPainter::Antialiasing ); painter.setWindow( rect ); painter.setBrush( Qt::NoBrush ); painter.translate( QRectF( rect ).center() ); const bool reverseLayout( option && option->direction == Qt::RightToLeft ); QPolygonF arrow = genericArrow( reverseLayout ? ArrowLeft:ArrowRight, ArrowTiny ); const qreal width( 1.1 ); painter.translate( 0, 0.5 ); painter.setBrush( Qt::NoBrush ); painter.setPen( QPen( _helper->calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter.drawPolyline( arrow ); painter.translate( 0,-1 ); painter.setBrush( Qt::NoBrush ); painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter.drawPolyline( arrow ); painter.end(); icon.addPixmap( pixmap ); } return icon; } case SP_ToolBarVerticalExtensionButton: { QIcon icon; // default icon sizes static const QList iconSizes = { 8, 16, 22, 32, 48 }; foreach( const int& iconSize, iconSizes ) { QPixmap pixmap( iconSize, iconSize ); pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); painter.setRenderHints( QPainter::Antialiasing ); painter.setWindow( rect ); painter.setBrush( Qt::NoBrush ); painter.translate( QRectF( rect ).center() ); QPolygonF arrow = genericArrow( ArrowDown, ArrowTiny ); const qreal width( 1.1 ); painter.translate( 0, 0.5 ); painter.setBrush( Qt::NoBrush ); painter.setPen( QPen( _helper->calcLightColor( buttonColor ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter.drawPolyline( arrow ); painter.translate( 0,-1 ); painter.setBrush( Qt::NoBrush ); painter.setPen( QPen( iconColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter.drawPolyline( arrow ); painter.end(); icon.addPixmap( pixmap ); } return icon; } default: // do not cache parent style icon, since it may change at runtime #if QT_VERSION >= 0x050000 return ParentStyleClass::standardIcon( standardPixmap, option, widget ); #else return ParentStyleClass::standardIconImplementation( standardPixmap, option, widget ); #endif } } //_____________________________________________________________________ void Style::loadConfiguration() { // set helper configuration _helper->loadConfig(); // background gradient _helper->setUseBackgroundGradient( StyleConfigData::useBackgroundGradient() ); // update top level window hints foreach( QWidget* widget, qApp->topLevelWidgets() ) { // make sure widget has a valid WId if( !(widget->testAttribute(Qt::WA_WState_Created) || widget->internalWinId() ) ) continue; // make sure widget has a decoration if( !_helper->hasDecoration( widget ) ) continue; // update flags _helper->setHasBackgroundGradient( widget->winId(), true ); } // update caches size int cacheSize( StyleConfigData::cacheEnabled() ? StyleConfigData::maxCacheSize():0 ); _helper->setMaxCacheSize( cacheSize ); // always enable blur helper _blurHelper->setEnabled( true ); // reinitialize engines _animations->setupEngines(); _transitions->setupEngines(); _windowManager->initialize(); _shadowHelper->loadConfig(); // mnemonics _mnemonics->setMode( StyleConfigData::mnemonicsMode() ); // widget explorer _widgetExplorer->setEnabled( StyleConfigData::widgetExplorerEnabled() ); _widgetExplorer->setDrawWidgetRects( StyleConfigData::drawWidgetRects() ); // splitter proxy _splitterFactory->setEnabled( StyleConfigData::splitterProxyEnabled() ); // scrollbar button dimentions. /* it has to be reinitialized here because scrollbar width might have changed */ _noButtonHeight = 0; _singleButtonHeight = qMax( StyleConfigData::scrollBarWidth() * 7 / 10, 14 ); _doubleButtonHeight = 2*_singleButtonHeight; // scrollbar buttons switch( StyleConfigData::scrollBarAddLineButtons() ) { case 0: _addLineButtons = NoButton; break; case 1: _addLineButtons = SingleButton; break; default: case 2: _addLineButtons = DoubleButton; break; } switch( StyleConfigData::scrollBarSubLineButtons() ) { case 0: _subLineButtons = NoButton; break; case 1: _subLineButtons = SingleButton; break; default: case 2: _subLineButtons = DoubleButton; break; } // frame focus if( StyleConfigData::viewDrawFocusIndicator() ) _frameFocusPrimitive = &Style::drawFrameFocusRectPrimitive; else _frameFocusPrimitive = &Style::emptyPrimitive; } //___________________________________________________________________________________________________________________ QRect Style::pushButtonContentsRect( const QStyleOption* option, const QWidget* ) const { return insideMargin( option->rect, Metrics::Frame_FrameWidth ); } //___________________________________________________________________________________________________________________ QRect Style::checkBoxContentsRect( const QStyleOption* option, const QWidget* ) const { return visualRect( option, option->rect.adjusted( Metrics::CheckBox_Size + Metrics::CheckBox_ItemSpacing, 0, 0, 0 ) ); } //___________________________________________________________________________________________________________________ QRect Style::lineEditContentsRect( const QStyleOption* option, const QWidget* widget ) const { // cast option and check const QStyleOptionFrame* frameOption( qstyleoption_cast( option ) ); if( !frameOption ) return option->rect; // check flatness const bool flat( frameOption->lineWidth == 0 ); if( flat ) return option->rect; // copy rect and take out margins QRect rect( option->rect ); // take out margins if there is enough room const int frameWidth( pixelMetric( PM_DefaultFrameWidth, option, widget ) ); if( rect.height() > option->fontMetrics.height() + 2*frameWidth ) return insideMargin( rect, frameWidth ); else return rect; } //____________________________________________________________________ QRect Style::progressBarGrooveRect( const QStyleOption* option, const QWidget* ) const { const QRect rect( option->rect ); const QStyleOptionProgressBarV2 *progressBarOption2( qstyleoption_cast( option ) ); const bool horizontal( !progressBarOption2 || progressBarOption2->orientation == Qt::Horizontal ); if( horizontal ) return insideMargin( rect, 1, 0 ); else return insideMargin( rect, 0, 1 ); } //____________________________________________________________________ QRect Style::progressBarContentsRect( const QStyleOption* option, const QWidget* widget ) const { // cast option and check const QStyleOptionProgressBar* progressBarOption( qstyleoption_cast( option ) ); if( !progressBarOption ) return QRect(); // get orientation const QStyleOptionProgressBarV2* progressBarOption2( qstyleoption_cast( option ) ); const bool horizontal( !progressBarOption2 || progressBarOption2->orientation == Qt::Horizontal ); // check inverted appearance const bool inverted( progressBarOption2 ? progressBarOption2->invertedAppearance : false ); // get groove rect const QRect rect( progressBarGrooveRect( option, widget ) ); // get progress qreal progress = progressBarOption->progress - progressBarOption->minimum; const bool busy = ( progressBarOption->minimum == 0 && progressBarOption->maximum == 0 ); if( busy ) progress = _animations->busyIndicatorEngine().value(); if( !( progress || busy ) ) return QRect(); const int steps = qMax( progressBarOption->maximum - progressBarOption->minimum, 1 ); //Calculate width fraction qreal widthFrac( busy ? qreal(Metrics::ProgressBar_BusyIndicatorSize)/100 : progress/steps ); widthFrac = qMin( (qreal)1, widthFrac ); // And now the pixel width const int indicatorSize( widthFrac*( horizontal ? rect.width():rect.height() ) ); // do nothing if indicator size is too small if( indicatorSize < 4 ) return QRect(); QRect indicatorRect; if( busy ) { // The space around which we move around... int remSize = ( ( 1 - widthFrac )*( horizontal ? rect.width():rect.height() ) ); remSize = qMax( remSize, 1 ); int pstep = remSize*2*progress; if( pstep > remSize ) { pstep = -( pstep - 2*remSize ); } if( horizontal ) { indicatorRect = QRect( inverted ? (rect.right() - pstep - indicatorSize + 1) : (rect.left() + pstep), rect.top(), indicatorSize, rect.height() ); indicatorRect = visualRect( option->direction, rect, indicatorRect ); } else { indicatorRect = QRect( rect.left(), inverted ? (rect.bottom() - pstep - indicatorSize + 1) : (rect.top() + pstep), rect.width(), indicatorSize ); } } else { if( horizontal ) { indicatorRect = QRect( inverted ? (rect.right() - indicatorSize + 1) : rect.left(), rect.top(), indicatorSize, rect.height() ); indicatorRect = visualRect( option->direction, rect, indicatorRect ); } else { indicatorRect = QRect( rect.left(), inverted ? rect.top() : (rect.bottom()- indicatorSize + 1), rect.width(), indicatorSize ); } } // adjust return insideMargin( indicatorRect, 1 ); } //___________________________________________________________________________________________________________________ QRect Style::headerArrowRect( const QStyleOption* option, const QWidget* ) const { // cast option and check const QStyleOptionHeader* headerOption( qstyleoption_cast( option ) ); if( !headerOption ) return option->rect; // check if arrow is necessary if( headerOption->sortIndicator == QStyleOptionHeader::None ) return QRect(); QRect arrowRect( insideMargin( option->rect, Metrics::Header_MarginWidth ) ); arrowRect.setLeft( arrowRect.right() - Metrics::Header_ArrowSize + 1 ); return visualRect( option, arrowRect ); } //___________________________________________________________________________________________________________________ QRect Style::headerLabelRect( const QStyleOption* option, const QWidget* ) const { // cast option and check const QStyleOptionHeader* headerOption( qstyleoption_cast( option ) ); if( !headerOption ) return option->rect; // check if arrow is necessary // QRect labelRect( insideMargin( option->rect, Metrics::Header_MarginWidth ) ); QRect labelRect( insideMargin( option->rect, Metrics::Header_MarginWidth, 0 ) ); if( headerOption->sortIndicator == QStyleOptionHeader::None ) return labelRect; labelRect.adjust( 0, 0, -Metrics::Header_ArrowSize-Metrics::Header_ItemSpacing, 0 ); return visualRect( option, labelRect ); } //____________________________________________________________________ QRect Style::tabBarTabLeftButtonRect( const QStyleOption* option, const QWidget* ) const { // cast option and check const QStyleOptionTabV3 *tabOptionV3( qstyleoption_cast( option ) ); if( !tabOptionV3 || tabOptionV3->leftButtonSize.isEmpty() ) return QRect(); const QRect rect( option->rect ); const QSize size( tabOptionV3->leftButtonSize ); QRect buttonRect( QPoint(0,0), size ); // vertical positioning switch( tabOptionV3->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: buttonRect.moveLeft( rect.left() + Metrics::TabBar_TabMarginWidth ); buttonRect.moveTop( ( rect.height() - buttonRect.height() )/2 ); buttonRect = visualRect( option, buttonRect ); break; case QTabBar::RoundedWest: case QTabBar::TriangularWest: buttonRect.moveBottom( rect.bottom() - Metrics::TabBar_TabMarginWidth ); buttonRect.moveLeft( ( rect.width() - buttonRect.width() )/2 ); break; case QTabBar::RoundedEast: case QTabBar::TriangularEast: buttonRect.moveTop( rect.top() + Metrics::TabBar_TabMarginWidth ); buttonRect.moveLeft( ( rect.width() - buttonRect.width() )/2 ); break; default: break; } return buttonRect; } //____________________________________________________________________ QRect Style::tabBarTabRightButtonRect( const QStyleOption* option, const QWidget* ) const { // cast option and check const QStyleOptionTabV3 *tabOptionV3( qstyleoption_cast( option ) ); if( !tabOptionV3 || tabOptionV3->rightButtonSize.isEmpty() ) return QRect(); const QRect rect( option->rect ); const QSize size( tabOptionV3->rightButtonSize ); QRect buttonRect( QPoint(0,0), size ); // vertical positioning switch( tabOptionV3->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: buttonRect.moveRight( rect.right() - Metrics::TabBar_TabMarginWidth ); buttonRect.moveTop( ( rect.height() - buttonRect.height() )/2 ); buttonRect = visualRect( option, buttonRect ); break; case QTabBar::RoundedWest: case QTabBar::TriangularWest: buttonRect.moveTop( rect.top() + Metrics::TabBar_TabMarginWidth ); buttonRect.moveLeft( ( rect.width() - buttonRect.width() )/2 ); break; case QTabBar::RoundedEast: case QTabBar::TriangularEast: buttonRect.moveBottom( rect.bottom() - Metrics::TabBar_TabMarginWidth ); buttonRect.moveLeft( ( rect.width() - buttonRect.width() )/2 ); break; default: break; } return buttonRect; } //____________________________________________________________________ QRect Style::tabWidgetTabBarRect( const QStyleOption* option, const QWidget* widget ) const { // cast option and check const QStyleOptionTabWidgetFrame* tabOption = qstyleoption_cast( option ); if( !tabOption ) return ParentStyleClass::subElementRect( SE_TabWidgetTabBar, option, widget ); // do nothing if tabbar is hidden const QSize tabBarSize( tabOption->tabBarSize ); QRect rect( option->rect ); QRect tabBarRect( QPoint(0, 0), tabBarSize ); // horizontal positioning const bool verticalTabs( isVerticalTab( tabOption->shape ) ); if( verticalTabs ) { tabBarRect.setHeight( qMin( tabBarRect.height(), rect.height() - 2 ) ); tabBarRect.moveTop( rect.top()+1 ); } else { // account for corner rects // need to re-run visualRect to remove right-to-left handling, since it is re-added on tabBarRect at the end const QRect leftButtonRect( visualRect( option, subElementRect( SE_TabWidgetLeftCorner, option, widget ) ) ); const QRect rightButtonRect( visualRect( option, subElementRect( SE_TabWidgetRightCorner, option, widget ) ) ); rect.setLeft( leftButtonRect.width() ); rect.setRight( rightButtonRect.left() - 1 ); tabBarRect.setWidth( qMin( tabBarRect.width(), rect.width() - 2 ) ); tabBarRect.moveLeft( rect.left() + 1 ); tabBarRect = visualRect( option, tabBarRect ); } // vertical positioning switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: tabBarRect.moveTop( rect.top()+1 ); break; case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: tabBarRect.moveBottom( rect.bottom()-1 ); break; case QTabBar::RoundedWest: case QTabBar::TriangularWest: tabBarRect.moveLeft( rect.left()+1 ); break; case QTabBar::RoundedEast: case QTabBar::TriangularEast: tabBarRect.moveRight( rect.right()-1 ); break; default: break; } return tabBarRect; } //____________________________________________________________________ QRect Style::tabWidgetTabContentsRect( const QStyleOption* option, const QWidget* widget ) const { // cast option and check const QStyleOptionTabWidgetFrame* tabOption = qstyleoption_cast( option ); if( !tabOption ) return option->rect; // do nothing if tabbar is hidden if( tabOption->tabBarSize.isEmpty() ) return option->rect; const QRect rect = tabWidgetTabPaneRect( option, widget ); const bool documentMode( tabOption->lineWidth == 0 ); if( documentMode ) { // add margin only to the relevant side switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: return rect.adjusted( 0, Metrics::TabWidget_MarginWidth, 0, 0 ); case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: return rect.adjusted( 0, 0, 0, -Metrics::TabWidget_MarginWidth ); case QTabBar::RoundedWest: case QTabBar::TriangularWest: return rect.adjusted( Metrics::TabWidget_MarginWidth, 0, 0, 0 ); case QTabBar::RoundedEast: case QTabBar::TriangularEast: return rect.adjusted( 0, 0, -Metrics::TabWidget_MarginWidth, 0 ); default: return rect; } } else return insideMargin( rect, Metrics::TabWidget_MarginWidth ); } //____________________________________________________________________ QRect Style::tabWidgetTabPaneRect( const QStyleOption* option, const QWidget* ) const { const QStyleOptionTabWidgetFrame* tabOption = qstyleoption_cast( option ); if( !tabOption || tabOption->tabBarSize.isEmpty() ) return option->rect; const int overlap = Metrics::TabBar_BaseOverlap - 1; const QSize tabBarSize( tabOption->tabBarSize - QSize( overlap, overlap ) ); QRect rect( option->rect ); switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: rect.adjust( 0, tabBarSize.height(), 0, 0 ); break; case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: rect.adjust( 0, 0, 0, -tabBarSize.height() ); break; case QTabBar::RoundedWest: case QTabBar::TriangularWest: rect.adjust( tabBarSize.width(), 0, 0, 0 ); break; case QTabBar::RoundedEast: case QTabBar::TriangularEast: rect.adjust( 0, 0, -tabBarSize.width(), 0 ); break; default: break; } return rect; } //____________________________________________________________________ QRect Style::tabWidgetCornerRect( SubElement element, const QStyleOption* option, const QWidget* widget ) const { // cast option and check const QStyleOptionTabWidgetFrame *tabOption = qstyleoption_cast( option ); if( !tabOption ) return QRect(); // copy rect const QRect paneRect( subElementRect( SE_TabWidgetTabPane, option, widget ) ); QRect rect; switch( element ) { case SE_TabWidgetLeftCorner: rect = QRect( QPoint(0,0), tabOption->leftCornerWidgetSize ); break; case SE_TabWidgetRightCorner: rect = QRect( QPoint(0,0), tabOption->rightCornerWidgetSize ); break; default: break; } if( element == SE_TabWidgetRightCorner ) rect.moveRight( paneRect.right() ); else rect.moveLeft( paneRect.left() ); switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: rect.moveBottom( paneRect.top() - 1 ); rect.translate( 0, 3 ); break; case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: rect.moveTop( paneRect.bottom() + 1 ); rect.translate( 0, -3 ); break; default: return QRect(); } rect = visualRect( tabOption, rect ); return rect; } //____________________________________________________________________ QRect Style::toolBoxTabContentsRect( const QStyleOption* option, const QWidget* widget ) const { // cast option and check const QStyleOptionToolBox* toolBoxOption( qstyleoption_cast( option ) ); if( !toolBoxOption ) return option->rect; // copy rect const QRect& rect( option->rect ); int contentsWidth(0); if( !toolBoxOption->icon.isNull() ) { const int iconSize( pixelMetric( QStyle::PM_SmallIconSize, option, widget ) ); contentsWidth += iconSize; if( !toolBoxOption->text.isEmpty() ) contentsWidth += Metrics::ToolBox_TabItemSpacing; } if( !toolBoxOption->text.isEmpty() ) { const int textWidth = toolBoxOption->fontMetrics.size( _mnemonics->textFlags(), toolBoxOption->text ).width(); contentsWidth += textWidth; } contentsWidth = qMin( contentsWidth, rect.width() ); contentsWidth = qMax( contentsWidth, int(Metrics::ToolBox_TabMinWidth) ); return centerRect( rect, contentsWidth, rect.height() ); } //______________________________________________________________ QRect Style::groupBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const { QRect rect = option->rect; switch( subControl ) { case SC_GroupBoxFrame: return rect; case SC_GroupBoxContents: { // cast option and check const QStyleOptionGroupBox *groupBoxOption = qstyleoption_cast( option ); if( !groupBoxOption ) break; // take out frame width rect = insideMargin( rect, Metrics::Frame_FrameWidth ); // get state const bool checkable( groupBoxOption->subControls & QStyle::SC_GroupBoxCheckBox ); const bool emptyText( groupBoxOption->text.isEmpty() ); // calculate title height int titleHeight( 0 ); if( !emptyText ) titleHeight = groupBoxOption->fontMetrics.height(); if( checkable ) titleHeight = qMax( titleHeight, int(Metrics::CheckBox_Size) ); // add margin if( titleHeight > 0 ) titleHeight += 2*Metrics::GroupBox_TitleMarginWidth; rect.adjust( 0, titleHeight, 0, 0 ); return rect; } case SC_GroupBoxCheckBox: case SC_GroupBoxLabel: { // cast option and check const QStyleOptionGroupBox *groupBoxOption = qstyleoption_cast( option ); if( !groupBoxOption ) break; // take out frame width rect = insideMargin( rect, Metrics::Frame_FrameWidth ); const bool emptyText( groupBoxOption->text.isEmpty() ); const bool checkable( groupBoxOption->subControls & QStyle::SC_GroupBoxCheckBox ); // calculate title height int titleHeight( 0 ); int titleWidth( 0 ); if( !emptyText ) { const QFontMetrics fontMetrics = option->fontMetrics; titleHeight = qMax( titleHeight, fontMetrics.height() ); titleWidth += fontMetrics.size( _mnemonics->textFlags(), groupBoxOption->text ).width(); } if( checkable ) { titleHeight = qMax( titleHeight, int(Metrics::CheckBox_Size) ); titleWidth += Metrics::CheckBox_Size; if( !emptyText ) titleWidth += Metrics::CheckBox_ItemSpacing; } // adjust height QRect titleRect( rect ); titleRect.setHeight( titleHeight ); titleRect.translate( 0, Metrics::GroupBox_TitleMarginWidth ); // center titleRect = centerRect( titleRect, titleWidth, titleHeight ); if( subControl == SC_GroupBoxCheckBox ) { // vertical centering titleRect = centerRect( titleRect, titleWidth, Metrics::CheckBox_Size ); // horizontal positioning const QRect subRect( titleRect.topLeft(), QSize( Metrics::CheckBox_Size, titleRect.height() ) ); return visualRect( option->direction, titleRect, subRect ); } else { // vertical centering QFontMetrics fontMetrics = option->fontMetrics; titleRect = centerRect( titleRect, titleWidth, fontMetrics.height() ); // horizontal positioning QRect subRect( titleRect ); if( checkable ) subRect.adjust( Metrics::CheckBox_Size + Metrics::CheckBox_ItemSpacing, 0, 0, 0 ); return visualRect( option->direction, titleRect, subRect ); } } default: break; } return ParentStyleClass::subControlRect( CC_GroupBox, option, subControl, widget ); } //___________________________________________________________________________________________________________________ QRect Style::toolButtonSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const { // cast option and check const QStyleOptionToolButton* toolButtonOption = qstyleoption_cast( option ); if( !toolButtonOption ) return ParentStyleClass::subControlRect( CC_ToolButton, option, subControl, widget ); const bool hasPopupMenu( toolButtonOption->features & QStyleOptionToolButton::MenuButtonPopup ); const bool hasInlineIndicator( toolButtonOption->features&QStyleOptionToolButton::HasMenu && toolButtonOption->features&QStyleOptionToolButton::PopupDelay && !hasPopupMenu ); // store rect const QRect& rect( option->rect ); const int menuButtonWidth( Metrics::MenuButton_IndicatorWidth ); switch( subControl ) { case SC_ToolButtonMenu: { // check fratures if( !(hasPopupMenu || hasInlineIndicator ) ) return QRect(); // check features QRect menuRect( rect ); menuRect.setLeft( rect.right() - menuButtonWidth + 1 ); if( hasInlineIndicator ) { menuRect.setTop( menuRect.bottom() - menuButtonWidth + 1 ); } return visualRect( option, menuRect ); } case SC_ToolButton: { if( hasPopupMenu ) { QRect contentsRect( rect ); contentsRect.setRight( rect.right() - menuButtonWidth ); return visualRect( option, contentsRect ); } else return rect; } default: return QRect(); } } //___________________________________________________________________________________________________________________ QRect Style::comboBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const { // cast option and check const QStyleOptionComboBox *comboBoxOption( qstyleoption_cast( option ) ); if( !comboBoxOption ) return ParentStyleClass::subControlRect( CC_ComboBox, option, subControl, widget ); const bool editable( comboBoxOption->editable ); const bool flat( editable && !comboBoxOption->frame ); // copy rect QRect rect( option->rect ); switch( subControl ) { case SC_ComboBoxFrame: return flat ? rect : QRect(); case SC_ComboBoxListBoxPopup: return rect; case SC_ComboBoxArrow: { // take out frame width if( !flat ) rect = insideMargin( rect, Metrics::Frame_FrameWidth ); QRect arrowRect( rect.right() - Metrics::MenuButton_IndicatorWidth + 1, rect.top(), Metrics::MenuButton_IndicatorWidth, rect.height() ); arrowRect = centerRect( arrowRect, Metrics::MenuButton_IndicatorWidth, Metrics::MenuButton_IndicatorWidth ); return visualRect( option, arrowRect ); } case SC_ComboBoxEditField: { QRect labelRect; const int frameWidth( pixelMetric( PM_ComboBoxFrameWidth, option, widget ) ); labelRect = QRect( rect.left(), rect.top(), rect.width() - Metrics::MenuButton_IndicatorWidth, rect.height() ); // remove margins if( !flat && rect.height() > option->fontMetrics.height() + 2*frameWidth ) { labelRect.adjust( frameWidth, frameWidth, 0, -frameWidth ); } return visualRect( option, labelRect ); } default: break; } return ParentStyleClass::subControlRect( CC_ComboBox, option, subControl, widget ); } //___________________________________________________________________________________________________________________ QRect Style::spinBoxSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const { // cast option and check const QStyleOptionSpinBox *spinBoxOption( qstyleoption_cast( option ) ); if( !spinBoxOption ) return ParentStyleClass::subControlRect( CC_SpinBox, option, subControl, widget ); const bool flat( !spinBoxOption->frame ); // copy rect QRect rect( option->rect ); switch( subControl ) { case SC_SpinBoxFrame: return flat ? QRect():rect; case SC_SpinBoxUp: case SC_SpinBoxDown: { // take out frame width if( !flat && rect.height() >= 2*Metrics::Frame_FrameWidth + Metrics::SpinBox_ArrowButtonWidth ) rect = insideMargin( rect, Metrics::Frame_FrameWidth ); QRect arrowRect; arrowRect = QRect( rect.right() - Metrics::SpinBox_ArrowButtonWidth + 1, rect.top(), Metrics::SpinBox_ArrowButtonWidth, rect.height() ); const int arrowHeight( qMin( rect.height(), int(Metrics::SpinBox_ArrowButtonWidth) ) ); arrowRect = centerRect( arrowRect, Metrics::SpinBox_ArrowButtonWidth, arrowHeight ); arrowRect.setHeight( arrowHeight/2 ); if( subControl == SC_SpinBoxDown ) arrowRect.translate( 0, arrowHeight/2 ); return visualRect( option, arrowRect ); } case SC_SpinBoxEditField: { QRect labelRect; labelRect = QRect( rect.left(), rect.top(), rect.width() - Metrics::SpinBox_ArrowButtonWidth, rect.height() ); // remove right side line editor margins const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) ); if( !flat && labelRect.height() > option->fontMetrics.height() + 2*frameWidth ) { labelRect.adjust( frameWidth, frameWidth, 0, -frameWidth ); } return visualRect( option, labelRect ); } default: break; } return ParentStyleClass::subControlRect( CC_SpinBox, option, subControl, widget ); } //___________________________________________________________________________________________________________________ QRect Style::scrollBarInternalSubControlRect( const QStyleOptionComplex* option, SubControl subControl ) const { const QRect& rect = option->rect; const State& state( option->state ); const bool horizontal( state & State_Horizontal ); switch( subControl ) { case SC_ScrollBarSubLine: { int majorSize( scrollBarButtonHeight( _subLineButtons ) ); if( horizontal ) return visualRect( option, QRect( rect.left(), rect.top(), majorSize, rect.height() ) ); else return visualRect( option, QRect( rect.left(), rect.top(), rect.width(), majorSize ) ); } case SC_ScrollBarAddLine: { int majorSize( scrollBarButtonHeight( _addLineButtons ) ); if( horizontal ) return visualRect( option, QRect( rect.right() - majorSize + 1, rect.top(), majorSize, rect.height() ) ); else return visualRect( option, QRect( rect.left(), rect.bottom() - majorSize + 1, rect.width(), majorSize ) ); } default: return QRect(); } } //___________________________________________________________________________________________________________________ QRect Style::scrollBarSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const { // cast option and check const QStyleOptionSlider* sliderOption( qstyleoption_cast( option ) ); if( !sliderOption ) return ParentStyleClass::subControlRect( CC_ScrollBar, option, subControl, widget ); // get relevant state const State& state( option->state ); const bool horizontal( state & State_Horizontal ); switch( subControl ) { case SC_ScrollBarSubLine: case SC_ScrollBarAddLine: return scrollBarInternalSubControlRect( option, subControl ); case SC_ScrollBarGroove: { QRect topRect = visualRect( option, scrollBarInternalSubControlRect( option, SC_ScrollBarSubLine ) ); QRect bottomRect = visualRect( option, scrollBarInternalSubControlRect( option, SC_ScrollBarAddLine ) ); QPoint topLeftCorner; QPoint botRightCorner; if( horizontal ) { topLeftCorner = QPoint( topRect.right() + 1, topRect.top() ); botRightCorner = QPoint( bottomRect.left() - 1, topRect.bottom() ); } else { topLeftCorner = QPoint( topRect.left(), topRect.bottom() + 1 ); botRightCorner = QPoint( topRect.right(), bottomRect.top() - 1 ); } // define rect return visualRect( option, QRect( topLeftCorner, botRightCorner ) ); } case SC_ScrollBarSlider: { // We handle RTL here to unreflect things if need be QRect groove = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) ); if( sliderOption->minimum == sliderOption->maximum ) return groove; //Figure out how much room we have.. int space( horizontal ? groove.width() : groove.height() ); //Calculate the portion of this space that the slider should take up. int sliderSize = space * qreal( sliderOption->pageStep ) / ( sliderOption->maximum - sliderOption->minimum + sliderOption->pageStep ); sliderSize = qMax( sliderSize, static_cast(Metrics::ScrollBar_MinSliderHeight ) ); sliderSize = qMin( sliderSize, space ); space -= sliderSize; if( space <= 0 ) return groove; int pos = qRound( qreal( sliderOption->sliderPosition - sliderOption->minimum )/ ( sliderOption->maximum - sliderOption->minimum )*space ); if( sliderOption->upsideDown ) pos = space - pos; if( horizontal ) return visualRect( option, QRect( groove.left() + pos, groove.top(), sliderSize, groove.height() ) ); else return visualRect( option, QRect( groove.left(), groove.top() + pos, groove.width(), sliderSize ) ); } case SC_ScrollBarSubPage: { //We do visualRect here to unreflect things if need be QRect slider = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarSlider, widget ) ); QRect groove = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) ); if( horizontal ) return visualRect( option, QRect( groove.left(), groove.top(), slider.left() - groove.left(), groove.height() ) ); else return visualRect( option, QRect( groove.left(), groove.top(), groove.width(), slider.top() - groove.top() ) ); } case SC_ScrollBarAddPage: { //We do visualRect here to unreflect things if need be QRect slider = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarSlider, widget ) ); QRect groove = visualRect( option, subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) ); if( horizontal ) return visualRect( option, QRect( slider.right() + 1, groove.top(), groove.right() - slider.right(), groove.height() ) ); else return visualRect( option, QRect( groove.left(), slider.bottom() + 1, groove.width(), groove.bottom() - slider.bottom() ) ); } default: return ParentStyleClass::subControlRect( CC_ScrollBar, option, subControl, widget );; } } //___________________________________________________________________________________________________________________ QRect Style::sliderSubControlRect( const QStyleOptionComplex* option, SubControl subControl, const QWidget* widget ) const { // cast option and check const QStyleOptionSlider* sliderOption( qstyleoption_cast( option ) ); if( !sliderOption ) return ParentStyleClass::subControlRect( CC_Slider, option, subControl, widget ); switch( subControl ) { case SC_SliderGroove: { // direction const bool horizontal( sliderOption->orientation == Qt::Horizontal ); // get base class rect QRect grooveRect( ParentStyleClass::subControlRect( CC_Slider, option, subControl, widget ) ); grooveRect = insideMargin( grooveRect, pixelMetric( PM_DefaultFrameWidth, option, widget ) ); // centering if( horizontal ) { grooveRect = centerRect( grooveRect, grooveRect.width(), Metrics::Slider_GrooveThickness ); grooveRect = insideMargin( grooveRect, 3, 0 ); } else { grooveRect = centerRect( grooveRect, Metrics::Slider_GrooveThickness, grooveRect.height() ); grooveRect = insideMargin( grooveRect, 0, 3 ); } return grooveRect; } case SC_SliderHandle: { QRect handleRect( ParentStyleClass::subControlRect( CC_Slider, option, subControl, widget ) ); handleRect = centerRect( handleRect, Metrics::Slider_ControlThickness, Metrics::Slider_ControlThickness ); return handleRect; } default: return ParentStyleClass::subControlRect( CC_Slider, option, subControl, widget ); } } //______________________________________________________________ QSize Style::checkBoxSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const { // get contents size QSize size( contentsSize ); // add focus height size = expandSize( size, 0, Metrics::CheckBox_FocusMarginWidth ); // make sure there is enough height for indicator size.setHeight( qMax( size.height(), int(Metrics::CheckBox_Size) ) ); // Add space for the indicator and the icon size.rwidth() += Metrics::CheckBox_Size + Metrics::CheckBox_ItemSpacing; // also add extra space, to leave room to the right of the label size.rwidth() += Metrics::CheckBox_ItemSpacing; return size; } //______________________________________________________________ QSize Style::lineEditSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const { // cast option and check const QStyleOptionFrame* frameOption( qstyleoption_cast( option ) ); if( !frameOption ) return contentsSize; const bool flat( frameOption->lineWidth == 0 ); const int frameWidth( pixelMetric( PM_DefaultFrameWidth, option, widget ) ); return flat ? contentsSize : expandSize( contentsSize, frameWidth ); } //______________________________________________________________ QSize Style::comboBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const { // cast option and check const QStyleOptionComboBox* comboBoxOption( qstyleoption_cast( option ) ); if( !comboBoxOption ) return contentsSize; // copy size QSize size( contentsSize ); // add relevant margin const bool flat( !comboBoxOption->frame ); const int frameWidth( pixelMetric( PM_ComboBoxFrameWidth, option, widget ) ); if( !flat ) size = expandSize( size, frameWidth ); // make sure there is enough height for the button size.setHeight( qMax( size.height(), int(Metrics::MenuButton_IndicatorWidth) ) ); // add button width and spacing size.rwidth() += Metrics::MenuButton_IndicatorWidth; return size; } //______________________________________________________________ QSize Style::spinBoxSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const { // cast option and check const QStyleOptionSpinBox *spinBoxOption( qstyleoption_cast( option ) ); if( !spinBoxOption ) return contentsSize; const bool flat( !spinBoxOption->frame ); // copy size QSize size( contentsSize ); // add editor margins const int frameWidth( pixelMetric( PM_SpinBoxFrameWidth, option, widget ) ); if( !flat ) size = expandSize( size, frameWidth ); // make sure there is enough height for the button size.setHeight( qMax( size.height(), int(Metrics::SpinBox_ArrowButtonWidth) ) ); // add button width and spacing size.rwidth() += Metrics::SpinBox_ArrowButtonWidth; return size; } //______________________________________________________________ QSize Style::sliderSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const { // cast option and check const QStyleOptionSlider *sliderOption( qstyleoption_cast( option ) ); if( !sliderOption ) return contentsSize; // store tick position and orientation const QSlider::TickPosition& tickPosition( sliderOption->tickPosition ); const bool horizontal( sliderOption->orientation == Qt::Horizontal ); const bool disableTicks( !StyleConfigData::sliderDrawTickMarks() ); /* Qt adds its own tick length directly inside QSlider. Take it out and replace by ours, if needed */ const int tickLength( disableTicks ? 0 : ( Metrics::Slider_TickLength + Metrics::Slider_TickMarginWidth + (Metrics::Slider_GrooveThickness - Metrics::Slider_ControlThickness)/2 ) ); const int builtInTickLength( 5 ); if( tickPosition == QSlider::NoTicks ) return contentsSize; QSize size( contentsSize ); if( horizontal ) { if(tickPosition & QSlider::TicksAbove) size.rheight() += tickLength - builtInTickLength; if(tickPosition & QSlider::TicksBelow) size.rheight() += tickLength - builtInTickLength; } else { if(tickPosition & QSlider::TicksAbove) size.rwidth() += tickLength - builtInTickLength; if(tickPosition & QSlider::TicksBelow) size.rwidth() += tickLength - builtInTickLength; } return size; } //______________________________________________________________ QSize Style::pushButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const { // cast option and check const QStyleOptionButton* buttonOption( qstyleoption_cast( option ) ); if( !buttonOption ) return contentsSize; QSize size( contentsSize ); // add space for arrow if( buttonOption->features & QStyleOptionButton::HasMenu ) { size.rheight() += 2*Metrics::Button_MarginWidth; size.setHeight( qMax( size.height(), int( Metrics::MenuButton_IndicatorWidth ) ) ); size.rwidth() += Metrics::Button_MarginWidth; if( !( buttonOption->icon.isNull() && buttonOption->text.isEmpty() ) ) { size.rwidth() += Metrics::Button_ItemSpacing; } } else size = expandSize( size, Metrics::Button_MarginWidth ); // add space for icon if( !buttonOption->icon.isNull() ) { QSize iconSize = buttonOption->iconSize; if( !iconSize.isValid() ) iconSize = QSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) ); size.setHeight( qMax( size.height(), iconSize.height() ) ); if( !buttonOption->text.isEmpty() ) { size.rwidth() += Metrics::Button_ItemSpacing; } } // make sure buttons have a minimum width if( !buttonOption->text.isEmpty() ) { size.rwidth() = qMax( size.rwidth(), int( Metrics::Button_MinWidth ) ); } // finally add margins return expandSize( size, Metrics::Frame_FrameWidth ); } //______________________________________________________________ QSize Style::toolButtonSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const { // cast option and check const QStyleOptionToolButton* toolButtonOption = qstyleoption_cast( option ); if( !toolButtonOption ) return contentsSize; // copy size QSize size = contentsSize; // get relevant state flags const State& state( option->state ); const bool autoRaise( state & State_AutoRaise ); const bool hasPopupMenu( toolButtonOption->features & QStyleOptionToolButton::MenuButtonPopup ); const bool hasInlineIndicator( toolButtonOption->features&QStyleOptionToolButton::HasMenu && toolButtonOption->features&QStyleOptionToolButton::PopupDelay && !hasPopupMenu ); const int marginWidth( autoRaise ? Metrics::ToolButton_MarginWidth : Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth ); if( hasInlineIndicator ) size.rwidth() += Metrics::ToolButton_InlineIndicatorWidth; size = expandSize( size, marginWidth ); return size; } //______________________________________________________________ QSize Style::menuBarItemSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const { return expandSize( contentsSize, Metrics::MenuBarItem_MarginWidth, Metrics::MenuBarItem_MarginHeight ); } //______________________________________________________________ QSize Style::menuItemSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const { // cast option and check const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast( option ); if( !menuItemOption ) return contentsSize; // First, we calculate the intrinsic size of the item. // this must be kept consistent with what's in drawMenuItemControl QSize size( contentsSize ); switch( menuItemOption->menuItemType ) { case QStyleOptionMenuItem::Normal: case QStyleOptionMenuItem::DefaultItem: case QStyleOptionMenuItem::SubMenu: { const int iconWidth( isQtQuickControl( option, widget ) ? qMax( pixelMetric(PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) : menuItemOption->maxIconWidth ); int leftColumnWidth( iconWidth ); // add space with respect to text leftColumnWidth += Metrics::MenuItem_ItemSpacing; // add checkbox indicator width if( menuItemOption->menuHasCheckableItems ) { leftColumnWidth += Metrics::CheckBox_Size + Metrics::MenuItem_ItemSpacing; } // add spacing for accelerator /* Note: The width of the accelerator itself is not included here since Qt will add that on separately after obtaining the sizeFromContents() for each menu item in the menu to be shown ( see QMenuPrivate::calcActionRects() ) */ const bool hasAccelerator( menuItemOption->text.indexOf( QLatin1Char( '\t' ) ) >= 0 ); if( hasAccelerator ) size.rwidth() += Metrics::MenuItem_AcceleratorSpace; // right column const int rightColumnWidth = Metrics::MenuButton_IndicatorWidth + Metrics::MenuItem_ItemSpacing; size.rwidth() += leftColumnWidth + rightColumnWidth; // make sure height is large enough for icon and arrow size.setHeight( qMax( size.height(), int(Metrics::MenuButton_IndicatorWidth) ) ); size.setHeight( qMax( size.height(), int(Metrics::CheckBox_Size) ) ); size.setHeight( qMax( size.height(), iconWidth ) ); return expandSize( size, Metrics::MenuItem_MarginWidth ); } case QStyleOptionMenuItem::Separator: { if( menuItemOption->text.isEmpty() && menuItemOption->icon.isNull() ) { return expandSize( QSize(0,1), Metrics::MenuItem_MarginWidth ); } else { // build toolbutton option const QStyleOptionToolButton toolButtonOption( separatorMenuItemOption( menuItemOption, widget ) ); // make sure height is large enough for icon and text const int iconWidth( qMax( pixelMetric(PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) ); const int textHeight( menuItemOption->fontMetrics.height() ); if( !menuItemOption->icon.isNull() ) size.setHeight( qMax( size.height(), iconWidth ) ); if( !menuItemOption->text.isEmpty() ) { size.setHeight( qMax( size.height(), textHeight ) ); size.setWidth( qMax( size.width(), menuItemOption->fontMetrics.width( menuItemOption->text ) ) ); } return sizeFromContents( CT_ToolButton, &toolButtonOption, size, widget ); } } // for all other cases, return input default: return contentsSize; } } //______________________________________________________________ QSize Style::tabWidgetSizeFromContents( const QStyleOption*, const QSize& contentsSize, const QWidget* ) const { return expandSize( contentsSize, Metrics::TabWidget_MarginWidth ); } //______________________________________________________________ QSize Style::tabBarTabSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const { const QStyleOptionTab *tabOption( qstyleoption_cast( option ) ); const QStyleOptionTabV3 *tabOptionV3( qstyleoption_cast( option ) ); const bool hasText( tabOption && !tabOption->text.isEmpty() ); const bool hasIcon( tabOption && !tabOption->icon.isNull() ); const bool hasLeftButton( tabOptionV3 && !tabOptionV3->leftButtonSize.isEmpty() ); const bool hasRightButton( tabOptionV3 && !tabOptionV3->leftButtonSize.isEmpty() ); // calculate width increment for horizontal tabs int widthIncrement = 0; if( hasIcon && !( hasText || hasLeftButton || hasRightButton ) ) widthIncrement -= 4; if( hasText && hasIcon ) widthIncrement += Metrics::TabBar_TabItemSpacing; if( hasLeftButton && ( hasText || hasIcon ) ) widthIncrement += Metrics::TabBar_TabItemSpacing; if( hasRightButton && ( hasText || hasIcon || hasLeftButton ) ) widthIncrement += Metrics::TabBar_TabItemSpacing; // add margins QSize size( contentsSize ); // compare to minimum size const bool verticalTabs( tabOption && isVerticalTab( tabOption ) ); if( verticalTabs ) { size.rwidth() += 2*Metrics::TabBar_TabOffset; size.rheight() += widthIncrement; if( hasIcon && !hasText ) size = size.expandedTo( QSize( Metrics::TabBar_TabMinHeight, 0 ) ); else size = size.expandedTo( QSize( Metrics::TabBar_TabMinHeight, Metrics::TabBar_TabMinWidth ) ); } else { size.rheight() += 2*Metrics::TabBar_TabOffset; size.rwidth() += widthIncrement; if( hasIcon && !hasText ) size = size.expandedTo( QSize( 0, Metrics::TabBar_TabMinHeight ) ); else size = size.expandedTo( QSize( Metrics::TabBar_TabMinWidth, Metrics::TabBar_TabMinHeight ) ); } return size; } //______________________________________________________________ QSize Style::headerSectionSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* ) const { // cast option and check const QStyleOptionHeader* headerOption( qstyleoption_cast( option ) ); if( !headerOption ) return contentsSize; // get text size const bool horizontal( headerOption->orientation == Qt::Horizontal ); const bool hasText( !headerOption->text.isEmpty() ); const bool hasIcon( !headerOption->icon.isNull() ); const QSize textSize( hasText ? headerOption->fontMetrics.size( 0, headerOption->text ) : QSize() ); const QSize iconSize( hasIcon ? QSize( 22,22 ) : QSize() ); // contents width int contentsWidth( 0 ); if( hasText ) contentsWidth += textSize.width(); if( hasIcon ) { contentsWidth += iconSize.width(); if( hasText ) contentsWidth += Metrics::Header_ItemSpacing; } // contents height int contentsHeight( headerOption->fontMetrics.height() ); if( hasIcon ) contentsHeight = qMax( contentsHeight, iconSize.height() ); if( horizontal && headerOption->sortIndicator != QStyleOptionHeader::None ) { // also add space for sort indicator contentsWidth += Metrics::Header_ArrowSize + Metrics::Header_ItemSpacing; contentsHeight = qMax( contentsHeight, int(Metrics::Header_ArrowSize) ); } // update contents size, add margins and return const QSize size( contentsSize.expandedTo( QSize( contentsWidth, contentsHeight ) ) ); return expandSize( size, Metrics::Header_MarginWidth ); } //______________________________________________________________ QSize Style::itemViewItemSizeFromContents( const QStyleOption* option, const QSize& contentsSize, const QWidget* widget ) const { // call base class QSize size( ParentStyleClass::sizeFromContents( CT_ItemViewItem, option, contentsSize, widget ) ); // add margins return expandSize( size, Metrics::ItemView_ItemMarginWidth ); } //___________________________________________________________________________________ bool Style::drawFramePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); #if QT_VERSION >= 0x050000 const bool isInputWidget( ( widget && widget->testAttribute( Qt::WA_Hover ) ) || ( isQtQuickControl( option, widget ) && option->styleObject->property( "elementType" ).toString() == QStringLiteral( "edit") ) ); #else const bool isInputWidget( widget && widget->testAttribute( Qt::WA_Hover ) ); #endif const bool mouseOver( enabled && isInputWidget && ( state & State_MouseOver ) ); const bool hasFocus( enabled && isInputWidget && ( state & State_HasFocus ) ); // assume focus takes precedence over hover _animations->inputWidgetEngine().updateState( widget, AnimationFocus, hasFocus ); _animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus ); if( state & State_Sunken ) { // retrieve animation mode and opacity const AnimationMode mode( _animations->inputWidgetEngine().frameAnimationMode( widget ) ); const qreal opacity( _animations->inputWidgetEngine().frameOpacity( widget ) ); if( _frameShadowFactory->isRegistered( widget ) ) { _frameShadowFactory->updateShadowsGeometry( widget, rect ); _frameShadowFactory->updateState( widget, hasFocus, mouseOver, opacity, mode ); } else { StyleOptions options; if( hasFocus ) options |= Focus; if( mouseOver ) options |= Hover; _helper->renderHole( painter, palette.color( QPalette::Window ), rect, options, opacity, mode, TileSet::Ring ); } } else if( state & State_Raised ) { const QRect local( rect ); renderSlab( painter, rect, palette.color( QPalette::Window ), NoFill ); } return true; } //___________________________________________________________________________________ bool Style::drawFrameLineEditPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // make sure there is enough room to render frame if( rect.height() < 2*Metrics::LineEdit_FrameWidth + option->fontMetrics.height() ) { const QColor background( palette.color( QPalette::Base ) ); painter->setPen( Qt::NoPen ); painter->setBrush( background ); painter->drawRect( rect ); return true; } else { // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( enabled && ( state & State_HasFocus ) ); // assume focus takes precedence over hover _animations->inputWidgetEngine().updateState( widget, AnimationFocus, hasFocus ); _animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus ); // retrieve animation mode and opacity const AnimationMode mode( _animations->inputWidgetEngine().frameAnimationMode( widget ) ); const qreal opacity( _animations->inputWidgetEngine().frameOpacity( widget ) ); // fill painter->setPen( Qt::NoPen ); painter->setBrush( palette.color( QPalette::Base ) ); _helper->fillHole( *painter, rect ); // render hole StyleOptions options; if( hasFocus ) options |= Focus; if( mouseOver ) options |= Hover; _helper->renderHole( painter, palette.color( QPalette::Window ), rect, options, opacity, mode, TileSet::Ring ); } return true; } //___________________________________________________________________________________ bool Style::drawFrameFocusRectPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { if( !widget ) return true; // no focus indicator on buttons, since it is rendered elsewhere if( qobject_cast< const QAbstractButton*>( widget ) ) { return true; } const State& state( option->state ); const QRect rect( option->rect.adjusted( 0, 0, 0, 1 ) ); const QPalette& palette( option->palette ); if( rect.width() < 10 ) return true; const QColor outlineColor( state & State_Selected ? palette.color( QPalette::HighlightedText ):palette.color( QPalette::Highlight ) ); painter->setRenderHint( QPainter::Antialiasing, false ); painter->setPen( outlineColor ); painter->drawLine( rect.bottomLeft(), rect.bottomRight() ); return true; } //___________________________________________________________________________________ bool Style::drawFrameMenuPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // only draw frame for ( expanded ) toolbars // do nothing for other cases if( qobject_cast( widget ) ) { _helper->renderWindowBackground( painter, option->rect, widget, option->palette ); _helper->drawFloatFrame( painter, option->rect, option->palette.window().color(), true ); } else if( isQtQuickControl( option, widget ) ) { // QtQuick Control case painter->fillRect( option->rect, option->palette.window() ); _helper->drawFloatFrame( painter, option->rect, option->palette.window().color(), true ); } return true; } //______________________________________________________________ bool Style::drawFrameGroupBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionFrame *frameOption( qstyleoption_cast( option ) ); if( !frameOption ) return true; // no frame for flat groupboxes QStyleOptionFrameV2 frameOption2( *frameOption ); if( frameOption2.features & QStyleOptionFrameV2::Flat ) return true; // normal frame const QPalette& palette( option->palette ); const QRect& rect( option->rect ); const QColor base( _helper->backgroundColor( palette.color( QPalette::Window ), widget, rect.center() ) ); painter->save(); painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( Qt::NoPen ); QLinearGradient innerGradient( 0, rect.top()-rect.height()+12, 0, rect.bottom()+rect.height()-19 ); QColor light( _helper->calcLightColor( base ) ); light.setAlphaF( 0.4 ); innerGradient.setColorAt( 0, light ); light.setAlphaF( 0 ); innerGradient.setColorAt( 1, light ); painter->setBrush( innerGradient ); painter->setClipRect( rect.adjusted( 0, 0, 0, -19 ) ); _helper->fillSlab( *painter, rect ); painter->setClipping( false ); _helper->slope( base, 0 ).render( rect, painter ); painter->restore(); return true; } //___________________________________________________________________________________ bool Style::drawFrameTabWidgetPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const { // cast option and check const QStyleOptionTabWidgetFrame* tabOption( qstyleoption_cast( option ) ); if( !tabOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); const bool reverseLayout( option->direction == Qt::RightToLeft ); /* no frame is drawn when tabbar is empty. this is consistent with the tabWidgetTabContents subelementRect */ if( tabOption->tabBarSize.isEmpty() ) return true; // get tabbar dimensions const int width( tabOption->tabBarSize.width() ); const int height( tabOption->tabBarSize.height() ); // left corner widget const int leftWidth( tabOption->leftCornerWidgetSize.width() ); const int rightWidth( tabOption->rightCornerWidgetSize.width() ); // list of slabs to be drawn SlabRect::List slabs; QRect baseSlabRect( rect ); // render the three free sides switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: { // main slab slabs << SlabRect( baseSlabRect, ( TileSet::Ring & ~TileSet::Top ) ); // top if( reverseLayout ) { // left side QRect slabRect( baseSlabRect ); slabRect.setRight( qMax( slabRect.right() - width - leftWidth, slabRect.left() + rightWidth ) ); slabRect.setHeight( 1 ); slabs << SlabRect( slabRect, TileSet::TopLeft ).adjusted( TileSet::DefaultSize ); // right side if( rightWidth > 0 ) { QRect slabRect( baseSlabRect ); slabRect.setLeft( slabRect.right() - rightWidth ); slabRect.setHeight( 1 ); slabs << SlabRect( slabRect, TileSet::TopRight ).adjusted( TileSet::DefaultSize ); } } else { // left side if( leftWidth > 0 ) { QRect slabRect( baseSlabRect ); slabRect.setRight( baseSlabRect.left() + leftWidth ); slabRect.setHeight( 1 ); slabs << SlabRect( slabRect, TileSet::TopLeft ).adjusted( TileSet::DefaultSize ); } // right side QRect slabRect( baseSlabRect ); slabRect.setLeft( qMin( slabRect.left() + width + leftWidth + 1, slabRect.right() - rightWidth ) ); slabRect.setHeight( 1 ); slabs << SlabRect( slabRect, TileSet::TopRight ).adjusted( TileSet::DefaultSize ); } break; } case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: { slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Bottom ); if( reverseLayout ) { // left side QRect slabRect( baseSlabRect ); slabRect.setRight( qMax( slabRect.right() -width - leftWidth, slabRect.left() + rightWidth ) ); slabRect.setTop( slabRect.bottom() ); slabs << SlabRect( slabRect, TileSet::BottomLeft ).adjusted( TileSet::DefaultSize ); // right side if( rightWidth > 0 ) { QRect slabRect( baseSlabRect ); slabRect.setLeft( slabRect.right() - rightWidth - TileSet::DefaultSize ); slabRect.setTop( slabRect.bottom() ); slabs << SlabRect( slabRect, TileSet::BottomRight ).adjusted( TileSet::DefaultSize ); } } else { // left side if( leftWidth > 0 ) { QRect slabRect( baseSlabRect ); slabRect.setRight( baseSlabRect.left() + leftWidth ); slabRect.setTop( slabRect.bottom() ); slabs << SlabRect( slabRect, TileSet::BottomLeft ).adjusted( TileSet::DefaultSize ); } // right side QRect slabRect( baseSlabRect ); slabRect.setLeft( qMin( slabRect.left() + width + leftWidth + 1, slabRect.right() - rightWidth ) ); slabRect.setTop( slabRect.bottom() ); slabs << SlabRect( slabRect, TileSet::BottomRight ).adjusted( TileSet::DefaultSize ); } break; } case QTabBar::RoundedWest: case QTabBar::TriangularWest: { slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Left ); // bottom side QRect slabRect( baseSlabRect ); slabRect.setTop( qMin( slabRect.top() + height, slabRect.bottom() ) ); slabRect.setWidth( 1 ); slabs << SlabRect( slabRect, TileSet::BottomLeft ).adjusted( TileSet::DefaultSize ); break; } case QTabBar::RoundedEast: case QTabBar::TriangularEast: { slabs << SlabRect( baseSlabRect, TileSet::Ring & ~TileSet::Right ); // bottom side QRect slabRect( baseSlabRect ); slabRect.setTop( qMin( slabRect.top() + height, slabRect.bottom() ) ); slabRect.setLeft( slabRect.right() ); slabs << SlabRect( slabRect, TileSet::BottomRight ).adjusted( TileSet::DefaultSize ); break; } break; default: break; } // render registered slabs foreach( const SlabRect& slab, slabs ) { renderSlab( painter, slab, palette.color( QPalette::Window ), NoFill ); } return true; } //___________________________________________________________________________________ bool Style::drawFrameTabBarBasePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const { // tabbar frame used either for 'separate' tabbar, or in 'document mode' // cast option and check const QStyleOptionTabBarBase* tabOption( qstyleoption_cast( option ) ); if( !tabOption ) return true; if( tabOption->tabBarRect.isValid() ) { // if tabBar rect is valid, all the frame is handled in tabBarTabShapeControl // nothing to be done here. // on the other hand, invalid tabBarRect corresponds to buttons in tabbars ( e.g. corner buttons ), // and the appropriate piece of frame needs to be drawn return true; } // store palette and rect const QPalette& palette( option->palette ); const QRect& rect( option->rect ); if( !rect.isValid() ) return true; QRect frameRect( rect ); SlabRect slab; switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: { frameRect = insideMargin( frameRect, -8, 0 ); frameRect.translate( 0, 4 ); slab = SlabRect( frameRect, TileSet::Top ); break; } case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: { frameRect = insideMargin( frameRect, -8, 0 ); frameRect.translate( 0, -4 ); slab = SlabRect( frameRect, TileSet::Bottom ); break; } default: return true; } // render registered slabs renderSlab( painter, slab, palette.color( QPalette::Window ), NoFill ); return true; } //___________________________________________________________________________________ bool Style::drawFrameWindowPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // render _helper->drawFloatFrame( painter, rect, palette.window().color(), false ); return true; } //___________________________________________________________________________________ bool Style::drawIndicatorArrowPrimitive( ArrowOrientation orientation, const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // store rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); bool mouseOver( enabled && ( state & State_MouseOver ) ); bool hasFocus( enabled && ( state & State_HasFocus ) ); // detect special buttons const bool inTabBar( widget && qobject_cast( widget->parentWidget() ) ); const bool inToolButton( qstyleoption_cast( option ) ); // color QColor color; if( inTabBar ) { // for tabbar arrows one uses animations to get the arrow color // get animation state /* there is no need to update the engine since this was already done when rendering the frame */ const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); StyleOptions styleOptions; if( mouseOver ) styleOptions |= Hover; if( hasFocus ) styleOptions |= Focus; color = _helper->arrowColor( palette, styleOptions, opacity, mode ); } else if( mouseOver && !inToolButton ) { color = _helper->hoverColor( palette ); } else if( inToolButton ) { const bool flat( state & State_AutoRaise ); // cast option const QStyleOptionToolButton* toolButtonOption( static_cast( option ) ); const bool hasPopupMenu( toolButtonOption->subControls & SC_ToolButtonMenu ); if( flat && hasPopupMenu ) { // for menu arrows in flat toolbutton one uses animations to get the arrow color // handle arrow over animation const bool arrowHover( mouseOver && ( toolButtonOption->activeSubControls & SC_ToolButtonMenu ) ); _animations->toolButtonEngine().updateState( widget, AnimationHover, arrowHover ); const bool animated( _animations->toolButtonEngine().isAnimated( widget, AnimationHover ) ); const qreal opacity( _animations->toolButtonEngine().opacity( widget, AnimationHover ) ); StyleOptions styleOptions; if( arrowHover ) styleOptions |= Hover; color = _helper->arrowColor( palette, styleOptions, opacity, animated ? AnimationHover:AnimationNone ); } else { color = palette.color( flat ? QPalette::WindowText : QPalette::ButtonText ); } } else color = palette.color( QPalette::WindowText ); // get arrow polygon const QPolygonF arrow = genericArrow( orientation, ArrowNormal ); const qreal penThickness = 1.6; const qreal offset( qMin( penThickness, qreal( 1 ) ) ); painter->translate( QRectF( rect ).center() ); painter->setRenderHint( QPainter::Antialiasing ); painter->translate( 0,offset ); const QColor background = palette.color( QPalette::Window ); painter->setPen( QPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->translate( 0,-offset ); painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); return true; } //___________________________________________________________________________________ bool Style::drawIndicatorHeaderArrowPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { const QStyleOptionHeader *headerOption = qstyleoption_cast( option ); const State& state( option->state ); // arrow orientation ArrowOrientation orientation( ArrowNone ); if( state & State_UpArrow || ( headerOption && headerOption->sortIndicator==QStyleOptionHeader::SortUp ) ) orientation = ArrowUp; else if( state & State_DownArrow || ( headerOption && headerOption->sortIndicator==QStyleOptionHeader::SortDown ) ) orientation = ArrowDown; if( orientation == ArrowNone ) return true; // invert arrows if requested by (hidden) options if( StyleConfigData::viewInvertSortIndicator() ) orientation = (orientation == ArrowUp) ? ArrowDown:ArrowUp; // flags, rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); _animations->headerViewEngine().updateState( widget, rect.topLeft(), mouseOver ); const bool animated( enabled && _animations->headerViewEngine().isAnimated( widget, rect.topLeft() ) ); // define gradient and polygon for drawing arrow const QPolygonF arrow = genericArrow( orientation, ArrowNormal ); QColor color = palette.color( QPalette::WindowText ); const QColor background = palette.color( QPalette::Window ); const QColor highlight( _helper->hoverColor( palette ) ); const qreal penThickness = 1.6; const qreal offset( qMin( penThickness, qreal( 1 ) ) ); if( animated ) { const qreal opacity( _animations->headerViewEngine().opacity( widget, rect.topLeft() ) ); color = KColorUtils::mix( color, highlight, opacity ); } else if( mouseOver ) color = highlight; painter->translate( QRectF(rect).center() ); painter->translate( 0, 1 ); painter->setRenderHint( QPainter::Antialiasing ); painter->translate( 0,offset ); painter->setPen( QPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->translate( 0,-offset ); painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); return true; } //______________________________________________________________ bool Style::drawPanelButtonCommandPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( enabled && ( state & State_HasFocus ) && !( widget && widget->focusProxy() ) ); const bool sunken( state & ( State_On|State_Sunken ) ); StyleOptions styleOptions; if( sunken ) styleOptions |= Sunken; if( hasFocus ) styleOptions |= Focus; if( mouseOver ) styleOptions |= Hover; // update animation state _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver ); // store animation state AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); // decide if widget must be rendered flat. /* The decision is made depending on - whether the "flat" flag is set in the option - whether the widget is hight enough to render both icons and normal margins Note: in principle one should also check for the button text height */ const QStyleOptionButton* buttonOption( qstyleoption_cast< const QStyleOptionButton* >( option ) ); bool flat = ( buttonOption && ( buttonOption->features.testFlag( QStyleOptionButton::Flat ) || ( ( !buttonOption->icon.isNull() ) && sizeFromContents( CT_PushButton, option, buttonOption->iconSize, widget ).height() > rect.height() ) ) ); if( flat ) { if( !sunken ) { const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) ); if( glow.isValid() ) _helper->slitFocused( glow ).render( rect, painter ); } else { _helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions, opacity, mode, TileSet::Ring ); } } else { // match color to the window background QColor buttonColor( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) ); // merge button color with highlight in case of default button if( enabled && buttonOption && (buttonOption->features&QStyleOptionButton::DefaultButton) ) { const QColor tintColor( _helper->calcLightColor( buttonColor ) ); buttonColor = KColorUtils::mix( buttonColor, tintColor, 0.5 ); } // disable animation for sunken buttons if( sunken ) mode = AnimationNone; renderButtonSlab( painter, rect, buttonColor, styleOptions, opacity, mode, TileSet::Ring ); } return true; } //______________________________________________________________ bool Style::drawPanelButtonToolPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( enabled && ( state & State_HasFocus ) ); const bool autoRaised( state & State_AutoRaise ); const bool sunken( state & ( State_On|State_Sunken ) ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // toolbar animation const bool isInToolBar( widget && qobject_cast( widget->parent() ) ); const bool toolBarAnimated( isInToolBar && widget && ( _animations->toolBarEngine().isAnimated( widget->parentWidget() ) || _animations->toolBarEngine().isFollowMouseAnimated( widget->parentWidget() ) ) ); const QRect animatedRect( ( isInToolBar && widget ) ? _animations->toolBarEngine().animatedRect( widget->parentWidget() ):QRect() ); const QRect childRect( ( widget && widget->parentWidget() ) ? rect.translated( widget->mapToParent( QPoint( 0,0 ) ) ):QRect() ); const QRect currentRect( widget ? _animations->toolBarEngine().currentRect( widget->parentWidget() ):QRect() ); const bool current( isInToolBar && widget && widget->parentWidget() && currentRect.intersects( rect.translated( widget->mapToParent( QPoint( 0,0 ) ) ) ) ); const bool toolBarTimerActive( isInToolBar && widget && _animations->toolBarEngine().isTimerActive( widget->parentWidget() ) ); const qreal toolBarOpacity( ( isInToolBar && widget ) ? _animations->toolBarEngine().opacity( widget->parentWidget() ):0 ); // normal animation state // no need to update, this was already done in drawToolButtonComplexControl const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); // style options StyleOptions styleOptions; if( sunken ) styleOptions |= Sunken; if( hasFocus ) styleOptions |= Focus; if( mouseOver ) styleOptions |= Hover; // non autoraised tool buttons get same slab as regular buttons if( !autoRaised ) { TileSet::Tiles tiles( TileSet::Ring ); // adjust tiles and rect in case of menubutton const QToolButton* toolButton = qobject_cast( widget ); const bool hasPopupMenu( toolButton && toolButton->popupMode() == QToolButton::MenuButtonPopup ); if( hasPopupMenu ) { if( reverseLayout ) tiles &= ~TileSet::Left; else tiles &= ~TileSet::Right; } // match button color to window background const QColor buttonColor( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) ); // render slab renderButtonSlab( painter, rect, buttonColor, styleOptions, opacity, mode, tiles ); return true; } // normal ( auto-raised ) toolbuttons if( sunken ) { // fill hole qreal holeOpacity = 1; const qreal bias = 0.75; if( mode == AnimationHover ) holeOpacity = 1 - bias*opacity; else if( toolBarAnimated && enabled && animatedRect.isNull() && current ) holeOpacity = 1 - bias*toolBarOpacity; else if( enabled && (( toolBarTimerActive && current ) || mouseOver ) ) holeOpacity = 1 - bias; if( holeOpacity > 0 ) { QColor color( _helper->backgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, rect.center() ) ); color = _helper->alphaColor( color, holeOpacity ); painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( Qt::NoPen ); painter->setBrush( color ); painter->drawRoundedRect( insideMargin( rect, 1 ), 3.5, 3.5 ); } styleOptions |= HoleContrast; if( mode != AnimationNone ) { _helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions, opacity, mode, TileSet::Ring ); } else if( toolBarAnimated ) { if( enabled && animatedRect.isNull() && current ) { _helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions, toolBarOpacity, AnimationHover, TileSet::Ring ); } else { _helper->renderHole( painter, palette.color( QPalette::Window ), rect, HoleContrast ); } } else if( toolBarTimerActive && current ) { _helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions | Hover ); } else { _helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions ); } } else { const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) ); if( mode != AnimationNone ) _helper->slitFocused( glow ).render( rect, painter ); else if( toolBarAnimated ) { if( enabled && animatedRect.isNull() && current ) { QColor glow( _helper->alphaColor( _helper->hoverColor( palette ), toolBarOpacity ) ); _helper->slitFocused( glow ).render( rect, painter ); } } else if( hasFocus || mouseOver ) { _helper->slitFocused( glow ).render( rect, painter ); } else if( toolBarTimerActive && current ) { _helper->slitFocused( _helper->hoverColor( palette ) ).render( rect, painter ); } } return true; } //______________________________________________________________ bool Style::drawTabBarPanelButtonToolPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { const QPalette& palette( option->palette ); QRect rect( option->rect ); // adjust rect depending on shape const QTabBar* tabBar( static_cast( widget->parent() ) ); switch( tabBar->shape() ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: rect.adjust( 0, 0, 0, -6 ); break; case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: rect.adjust( 0, 6, 0, 0 ); break; case QTabBar::RoundedWest: case QTabBar::TriangularWest: rect.adjust( 0, 0, -6, 0 ); break; case QTabBar::RoundedEast: case QTabBar::TriangularEast: rect.adjust( 6, 0, 0, 0 ); break; default: break; } const QPalette local( widget->parentWidget() ? widget->parentWidget()->palette() : palette ); // check whether parent has autofill background flag const QWidget* parent = _helper->checkAutoFillBackground( widget ); if( parent && !qobject_cast( parent ) ) painter->fillRect( rect, parent->palette().color( parent->backgroundRole() ) ); else _helper->renderWindowBackground( painter, rect, widget, local ); return true; } //___________________________________________________________________________________ bool Style::drawPanelScrollAreaCornerPrimitive( const QStyleOption*, QPainter*, const QWidget* widget ) const { // disable painting of PE_PanelScrollAreaCorner // the default implementation fills the rect with the window background color // which does not work for windows that have gradients. // unfortunately, this does not work when scrollbars are children of QWebView, // in which case, false is returned, in order to fall back to the parent style implementation return !( widget && widget->inherits( "QWebView" ) ); } //___________________________________________________________________________________ bool Style::drawPanelMenuPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // do nothing if menu is embedded in another widget // this corresponds to having a transparent background if( widget && !widget->isWindow() ) return true; // cast option and check const QStyleOptionMenuItem* menuItemOption( qstyleoption_cast( option ) ); if( !( menuItemOption && widget ) ) return true; // copy rect and get color const QRect& rect = menuItemOption->rect; const QColor color = menuItemOption->palette.color( widget->window()->backgroundRole() ); const bool hasAlpha( _helper->hasAlphaChannel( widget ) ); if( hasAlpha ) { painter->setCompositionMode( QPainter::CompositionMode_Source ); _helper->roundCorner( color ).render( rect, painter ); painter->setCompositionMode( QPainter::CompositionMode_SourceOver ); painter->setClipPath( _helper->roundedPath( insideMargin( rect, 1 ) ), Qt::IntersectClip ); } _helper->renderMenuBackground( painter, rect, widget, menuItemOption->palette ); if( hasAlpha ) painter->setClipping( false ); _helper->drawFloatFrame( painter, rect, color, !hasAlpha ); return true; } //___________________________________________________________________________________ bool Style::drawPanelTipLabelPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // force registration of widget if( widget && widget->window() ) { _shadowHelper->registerWidget( widget->window(), true ); } const QRect& rect( option->rect ); const QColor color( option->palette.brush( QPalette::ToolTipBase ).color() ); QColor topColor( _helper->backgroundTopColor( color ) ); QColor bottomColor( _helper->backgroundBottomColor( color ) ); // make tooltip semi transparents when possible // alpha is copied from "kdebase/apps/dolphin/tooltips/filemetadatatooltip.cpp" const bool hasAlpha( _helper->hasAlphaChannel( widget ) ); if( hasAlpha && StyleConfigData::toolTipTransparent() ) { if( widget && widget->window() ) { _blurHelper->registerWidget( widget->window() ); } topColor.setAlpha( 220 ); bottomColor.setAlpha( 220 ); } QLinearGradient gradient( 0, rect.top(), 0, rect.bottom() ); gradient.setColorAt( 0, topColor ); gradient.setColorAt( 1, bottomColor ); // contrast pixmap QLinearGradient gradient2( 0, rect.top(), 0, rect.bottom() ); gradient2.setColorAt( 0.5, _helper->calcLightColor( bottomColor ) ); gradient2.setColorAt( 0.9, bottomColor ); painter->save(); if( hasAlpha ) { painter->setRenderHint( QPainter::Antialiasing ); QRectF local( rect ); local.adjust( 0.5, 0.5, -0.5, -0.5 ); painter->setPen( Qt::NoPen ); painter->setBrush( gradient ); painter->drawRoundedRect( local, 4, 4 ); painter->setBrush( Qt::NoBrush ); painter->setPen( QPen( gradient2, 1.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawRoundedRect( local, 3.5, 3.5 ); } else { painter->setPen( Qt::NoPen ); painter->setBrush( gradient ); painter->drawRect( rect ); painter->setBrush( Qt::NoBrush ); painter->setPen( QPen( gradient2, 1.1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawRect( rect ); } painter->restore(); return true; } //___________________________________________________________________________________ bool Style::drawPanelItemViewItemPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionViewItemV4 *viewItemOption = qstyleoption_cast( option ); if( !viewItemOption ) return false; // try cast widget const QAbstractItemView *view = qobject_cast( widget ); // store palette and rect const QPalette& palette( option->palette ); QRect rect( option->rect ); // store flags const State& state( option->state ); const bool mouseOver( ( state & State_MouseOver ) && (!view || view->selectionMode() != QAbstractItemView::NoSelection) ); const bool selected( state & State_Selected ); const bool enabled( state & State_Enabled ); const bool active( state & State_Active ); const bool hasCustomBackground( viewItemOption->backgroundBrush.style() != Qt::NoBrush && !selected ); const bool hasSolidBackground( !hasCustomBackground || viewItemOption->backgroundBrush.style() == Qt::SolidPattern ); if( !mouseOver && !selected && !hasCustomBackground && !( viewItemOption->features & QStyleOptionViewItemV2::Alternate ) ) { return true; } QPalette::ColorGroup colorGroup; if( enabled ) colorGroup = active ? QPalette::Normal : QPalette::Inactive; else colorGroup = QPalette::Disabled; QColor color; if( hasCustomBackground && hasSolidBackground ) color = viewItemOption->backgroundBrush.color(); else color = palette.color( colorGroup, QPalette::Highlight ); if( mouseOver && !hasCustomBackground ) { if( !selected ) color.setAlphaF( 0.2 ); else color = color.lighter( 110 ); } if( viewItemOption && ( viewItemOption->features & QStyleOptionViewItemV2::Alternate ) ) { painter->fillRect( option->rect, palette.brush( colorGroup, QPalette::AlternateBase ) ); } if( !mouseOver && !selected && !hasCustomBackground ) { return true; } if( hasCustomBackground && !hasSolidBackground ) { const QPointF oldBrushOrigin = painter->brushOrigin(); painter->setBrushOrigin( viewItemOption->rect.topLeft() ); painter->setBrush( viewItemOption->backgroundBrush ); painter->setPen( Qt::NoPen ); painter->drawRect( viewItemOption->rect ); painter->setBrushOrigin( oldBrushOrigin ); } else { // get selection tileset TileSet tileSet( _helper->selection( color, rect.height(), hasCustomBackground ) ); bool roundedLeft = false; bool roundedRight = false; if( viewItemOption ) { roundedLeft = ( viewItemOption->viewItemPosition == QStyleOptionViewItemV4::Beginning ); roundedRight = ( viewItemOption->viewItemPosition == QStyleOptionViewItemV4::End ); if( viewItemOption->viewItemPosition == QStyleOptionViewItemV4::OnlyOne || viewItemOption->viewItemPosition == QStyleOptionViewItemV4::Invalid || ( view && view->selectionBehavior() != QAbstractItemView::SelectRows ) ) { roundedLeft = true; roundedRight = true; } } const bool reverseLayout( option->direction == Qt::RightToLeft ); // define tiles TileSet::Tiles tiles( TileSet::Center ); if( !reverseLayout ? roundedLeft : roundedRight ) tiles |= TileSet::Left; if( !reverseLayout ? roundedRight : roundedLeft ) tiles |= TileSet::Right; // adjust rect and render rect = tileSet.adjust( rect, tiles ); if( rect.isValid() ) tileSet.render( rect, painter, tiles ); } return true; } //___________________________________________________________________________________ bool Style::drawIndicatorMenuCheckMarkPrimitive( const QStyleOption *option, QPainter *painter, const QWidget * ) const { const QRect& rect( option->rect ); const State& state( option->state ); const QPalette& palette( option->palette ); const bool enabled( state & State_Enabled ); StyleOptions styleOptions( NoFill ); if( !enabled ) styleOptions |= Disabled; renderCheckBox( painter, rect, palette, styleOptions, CheckOn ); return true; } //___________________________________________________________________________________ bool Style::drawIndicatorCheckBoxPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // get rect const QRect& rect( option->rect ); const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( enabled && ( state & State_HasFocus ) ); StyleOptions styleOptions; if( !enabled ) styleOptions |= Disabled; if( mouseOver ) styleOptions |= Hover; if( hasFocus ) styleOptions |= Focus; // get checkbox state CheckBoxState checkBoxState; if( state & State_NoChange ) checkBoxState = CheckTriState; else if( state & State_Sunken ) checkBoxState = CheckSunken; else if( state & State_On ) checkBoxState = CheckOn; else checkBoxState = CheckOff; // match button color to window background QPalette palette( option->palette ); palette.setColor( QPalette::Button, _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) ); // animation state: mouseOver has precedence over focus _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus&&!mouseOver ); const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); renderCheckBox( painter, rect, palette, styleOptions, checkBoxState, opacity, mode ); return true; } //___________________________________________________________________________________ bool Style::drawIndicatorRadioButtonPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // copy rect const QRect& rect( option->rect ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( state & State_HasFocus ); StyleOptions styleOptions; if( !enabled ) styleOptions |= Disabled; if( mouseOver ) styleOptions |= Hover; if( hasFocus ) styleOptions |= Focus; CheckBoxState checkBoxState; if( state & State_Sunken ) checkBoxState = CheckSunken; else if( state & State_On ) checkBoxState = CheckOn; else checkBoxState = CheckOff; // match button color to window background QPalette palette( option->palette ); palette.setColor( QPalette::Button, _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) ); // animation state: mouseOver has precedence over focus _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus&&!mouseOver ); const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); renderRadioButton( painter, rect, palette, styleOptions, checkBoxState, opacity, mode ); return true; } //___________________________________________________________________________________ bool Style::drawIndicatorButtonDropDownPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionToolButton* toolButtonOption( qstyleoption_cast( option ) ); if( !toolButtonOption ) return true; // copy palette and rect const QPalette& palette( option->palette ); const QRect& rect( option->rect ); // store state const State& state( option->state ); const bool autoRaise( state & State_AutoRaise ); // do nothing for autoraise buttons if( autoRaise || !(toolButtonOption->subControls & SC_ToolButtonMenu) ) return true; // store state const bool enabled( state & State_Enabled ); const bool hasFocus( enabled && ( state & State_HasFocus ) ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool sunken( enabled && ( state & State_Sunken ) ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // match button color to window background const QColor highlight( _helper->hoverColor( palette ) ); const QColor background( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) ); StyleOptions styleOptions; if( hasFocus ) styleOptions |= Focus; if( mouseOver ) styleOptions |= Hover; // update animation state // mouse over takes precedence over focus _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver ); const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); // paint frame TileSet::Tiles tiles( TileSet::Ring ); if( state & ( State_On|State_Sunken ) ) styleOptions |= Sunken; if( reverseLayout ) tiles &= ~TileSet::Right; else tiles &= ~TileSet::Left; painter->setClipRect( rect, Qt::IntersectClip ); renderButtonSlab( painter, rect, background, styleOptions, opacity, mode, tiles ); // draw separating vertical line const QColor color( palette.color( QPalette::Button ) ); const QColor light =_helper->alphaColor( _helper->calcLightColor( color ), 0.6 ); QColor dark = _helper->calcDarkColor( color ); dark.setAlpha( 200 ); const int top( rect.top()+ (sunken ? 3:2) ); const int bottom( rect.bottom()-4 ); painter->setPen( QPen( light,1 ) ); if( reverseLayout ) { painter->drawLine( rect.right()+1, top+1, rect.right()+1, bottom ); painter->drawLine( rect.right()-1, top+2, rect.right()-1, bottom ); painter->setPen( dark ); painter->drawLine( rect.right(), top, rect.right(), bottom ); } else { painter->drawLine( rect.left()-1, top+1, rect.left()-1, bottom-1 ); painter->drawLine( rect.left()+1, top+1, rect.left()+1, bottom-1 ); painter->setPen( dark ); painter->drawLine( rect.left(), top, rect.left(), bottom ); } return true; } //___________________________________________________________________________________ bool Style::drawIndicatorTabClosePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const { if( _tabCloseIcon.isNull() ) { // load the icon on-demand: in the constructor, KDE is not yet ready to find it! _tabCloseIcon = QIcon::fromTheme( QStringLiteral( "dialog-close" ) ); if( _tabCloseIcon.isNull() ) return false; } const int size( pixelMetric(QStyle::PM_SmallIconSize) ); QIcon::Mode mode; if( option->state & State_Enabled ) { if( option->state & State_Raised ) mode = QIcon::Active; else mode = QIcon::Normal; } else mode = QIcon::Disabled; if( !(option->state & State_Raised) && !(option->state & State_Sunken) && !(option->state & QStyle::State_Selected)) mode = QIcon::Disabled; QIcon::State state = option->state & State_Sunken ? QIcon::On:QIcon::Off; QPixmap pixmap( _tabCloseIcon.pixmap(size, mode, state) ); drawItemPixmap( painter, option->rect, Qt::AlignCenter, pixmap ); return true; } //___________________________________________________________________________________ bool Style::drawIndicatorTabTearPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { const QStyleOptionTab* tabOption( qstyleoption_cast( option ) ); if( !tabOption ) return true; const QRect& rect( option->rect ); const QPalette& palette( option->palette ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // in fact with current version of Qt ( 4.6.0 ) the cast fails and document mode is always false // this will hopefully be fixed in later versions const QStyleOptionTabV3* tabOptionV3( qstyleoption_cast( option ) ); bool documentMode( tabOptionV3 ? tabOptionV3->documentMode : false ); const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast( widget->parentWidget() ) : nullptr; documentMode |= ( tabWidget ? tabWidget->documentMode() : true ); QRect gradientRect( rect ); switch( tabOption->shape ) { case QTabBar::TriangularNorth: case QTabBar::RoundedNorth: gradientRect.adjust( 0, 0, 0, -5 ); break; case QTabBar::TriangularSouth: case QTabBar::RoundedSouth: gradientRect.adjust( 0, 5, 0, 0 ); break; case QTabBar::TriangularWest: case QTabBar::RoundedWest: gradientRect.adjust( 0, 0, -5, 0 ); break; case QTabBar::TriangularEast: case QTabBar::RoundedEast: gradientRect.adjust( 5, 0, 0, 0 ); break; default: return true; } // fade tabbar QPixmap pixmap( gradientRect.size() ); { pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); const bool verticalTabs( isVerticalTab( tabOption ) ); int width = 0; int height = 0; if( verticalTabs ) height = gradientRect.height(); else width = gradientRect.width(); QLinearGradient grad; if( reverseLayout && !verticalTabs ) grad = QLinearGradient( 0, 0, width, height ); else grad = QLinearGradient( width, height, 0, 0 ); grad.setColorAt( 0, Qt::transparent ); grad.setColorAt( 0.6, Qt::black ); if( widget ) { _helper->renderWindowBackground( &painter, pixmap.rect(), widget, palette ); } painter.setCompositionMode( QPainter::CompositionMode_DestinationAtop ); painter.fillRect( pixmap.rect(), QBrush( grad ) ); painter.end(); } // draw pixmap painter->drawPixmap( gradientRect.topLeft() + QPoint( 0,-1 ), pixmap ); return true; } //___________________________________________________________________________________ bool Style::drawIndicatorToolBarHandlePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const { // do nothing if disabled from options if( !StyleConfigData::toolBarDrawItemSeparator() ) { return true; } // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool horizontal( state & State_Horizontal ); int counter( 1 ); if( horizontal ) { const int center( rect.left()+ rect.width()/2 ); for( int j = rect.top()+2; j <= rect.bottom()-3; j+=3, ++counter ) { if( counter%2 == 0 ) _helper->renderDot( painter, QPoint( center+1, j ), palette.color( QPalette::Window ) ); else _helper->renderDot( painter, QPoint( center-2, j ), palette.color( QPalette::Window ) ); } } else { const int center( rect.top()+ rect.height()/2 ); for( int j = rect.left()+2; j <= rect.right()-3; j+=3, ++counter ) { if( counter%2 == 0 ) _helper->renderDot( painter, QPoint( j, center+1 ), palette.color( QPalette::Window ) ); else _helper->renderDot( painter, QPoint( j, center-2 ), palette.color( QPalette::Window ) ); } } return true; } //___________________________________________________________________________________ bool Style::drawIndicatorToolBarSeparatorPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { /* do nothing if disabled from options also need to check if widget is a combobox, because of Qt hack using 'toolbar' separator primitive for rendering separators in comboboxes */ if( !( StyleConfigData::toolBarDrawItemSeparator() || qobject_cast( widget ) ) ) { return true; } // store rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool separatorIsVertical( state & State_Horizontal ); // define color and render const QColor color( palette.color( QPalette::Window ) ); if( separatorIsVertical ) _helper->drawSeparator( painter, rect, color, Qt::Vertical ); else _helper->drawSeparator( painter, rect, color, Qt::Horizontal ); return true; } //___________________________________________________________________________________ bool Style::drawIndicatorBranchPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // state const State& state( option->state ); const bool reverseLayout( option->direction == Qt::RightToLeft ); //draw expander int expanderAdjust = 0; if( state & State_Children ) { int sizeLimit = qMin( rect.width(), rect.height() ); const bool expanderOpen( state & State_Open ); // make sure size limit is odd expanderAdjust = sizeLimit/2 + 1; // flags const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); // color const QColor expanderColor( mouseOver ? _helper->hoverColor( palette ):palette.color( QPalette::Text ) ); // get arrow size from option ArrowSize size = ArrowSmall; qreal penThickness( 1.2 ); switch( StyleConfigData::viewTriangularExpanderSize() ) { case StyleConfigData::TE_TINY: size = ArrowTiny; break; default: case StyleConfigData::TE_SMALL: size = ArrowSmall; break; case StyleConfigData::TE_NORMAL: penThickness = 1.6; size = ArrowNormal; break; } // get arrows polygon QPolygonF arrow; if( expanderOpen ) arrow = genericArrow( ArrowDown, size ); else arrow = genericArrow( reverseLayout ? ArrowLeft:ArrowRight, size ); // render painter->save(); painter->translate( QRectF( rect ).center() ); painter->setPen( QPen( expanderColor, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->setRenderHint( QPainter::Antialiasing ); painter->drawPolyline( arrow ); painter->restore(); } // tree branches if( !StyleConfigData::viewDrawTreeBranchLines() ) return true; const QPoint center( rect.center() ); const QColor lineColor( KColorUtils::mix( palette.color( QPalette::Text ), palette.color( QPalette::Window ), 0.8 ) ); painter->setRenderHint( QPainter::Antialiasing, false ); painter->setPen( lineColor ); if( state & ( State_Item | State_Children | State_Sibling ) ) { const QLine line( QPoint( center.x(), rect.top() ), QPoint( center.x(), center.y() - expanderAdjust ) ); painter->drawLine( line ); } //The right/left ( depending on dir ) line gets drawn if we have an item if( state & State_Item ) { const QLine line = reverseLayout ? QLine( QPoint( rect.left(), center.y() ), QPoint( center.x() - expanderAdjust, center.y() ) ): QLine( QPoint( center.x() + expanderAdjust, center.y() ), QPoint( rect.right(), center.y() ) ); painter->drawLine( line ); } //The bottom if we have a sibling if( state & State_Sibling ) { const QLine line( QPoint( center.x(), center.y() + expanderAdjust ), QPoint( center.x(), rect.bottom() ) ); painter->drawLine( line ); } return true; } //___________________________________________________________________________________ bool Style::drawWidgetPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // check widget and attributes if( !widget || !widget->testAttribute( Qt::WA_StyledBackground ) || widget->testAttribute( Qt::WA_NoSystemBackground ) ) return false; if( !( ( widget->windowFlags() & Qt::WindowType_Mask ) & ( Qt::Window|Qt::Dialog ) ) ) return false; if( !widget->isWindow() ) return false; // normal "window" background const QPalette& palette( option->palette ); // do not render background if palette brush has a texture (pixmap or image) const QBrush brush( palette.brush( widget->backgroundRole() ) ); if( !( brush.texture().isNull() && brush.textureImage().isNull() ) ) { return false; } _helper->renderWindowBackground( painter, option->rect, widget, palette ); return true; } //___________________________________________________________________________________ bool Style::drawPushButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionButton* buttonOption( qstyleoption_cast( option ) ); if( !buttonOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool sunken( ( state & State_On ) || ( state & State_Sunken ) ); const bool mouseOver( enabled && (option->state & State_MouseOver) ); const bool flat( buttonOption->features & QStyleOptionButton::Flat ); // content const bool hasIcon( !buttonOption->icon.isNull() ); const bool hasText( !buttonOption->text.isEmpty() ); // contents QRect contentsRect( rect ); // color role const QPalette::ColorRole textRole( flat ? QPalette::WindowText:QPalette::ButtonText ); // menu arrow if( buttonOption->features & QStyleOptionButton::HasMenu ) { // define rect QRect arrowRect( contentsRect ); arrowRect.setLeft( contentsRect.right() - Metrics::MenuButton_IndicatorWidth + 1 ); arrowRect = centerRect( arrowRect, Metrics::MenuButton_IndicatorWidth, Metrics::MenuButton_IndicatorWidth ); contentsRect.setRight( arrowRect.left() - Metrics::Button_ItemSpacing - 1 ); contentsRect.adjust( Metrics::Button_MarginWidth, 0, 0, 0 ); arrowRect = visualRect( option, arrowRect ); // arrow const qreal penThickness = 1.6; QPolygonF arrow = genericArrow( ArrowDown, ArrowNormal ); const QColor color = palette.color( flat ? QPalette::WindowText:QPalette::ButtonText ); const QColor background = palette.color( flat ? QPalette::Window:QPalette::Button ); painter->save(); painter->translate( QRectF( arrowRect ).center() ); painter->setRenderHint( QPainter::Antialiasing ); const qreal offset( qMin( penThickness, qreal( 1 ) ) ); painter->translate( 0,offset ); painter->setPen( QPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->translate( 0,-offset ); painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->restore(); } else contentsRect = insideMargin( contentsRect, Metrics::Button_MarginWidth, 0 ); // icon size QSize iconSize( buttonOption->iconSize ); if( !iconSize.isValid() ) { const int metric( pixelMetric( PM_SmallIconSize, option, widget ) ); iconSize = QSize( metric, metric ); } // text size const int textFlags( _mnemonics->textFlags() | Qt::AlignCenter ); const QSize textSize( option->fontMetrics.size( textFlags, buttonOption->text ) ); // adjust text and icon rect based on options QRect iconRect; QRect textRect; if( hasText && !hasIcon ) textRect = contentsRect; else if( hasIcon && !hasText ) iconRect = contentsRect; else { const int contentsWidth( iconSize.width() + textSize.width() + Metrics::Button_ItemSpacing ); iconRect = QRect( QPoint( contentsRect.left() + (contentsRect.width() - contentsWidth )/2, contentsRect.top() + (contentsRect.height() - iconSize.height())/2 ), iconSize ); textRect = QRect( QPoint( iconRect.right() + Metrics::ToolButton_ItemSpacing + 1, contentsRect.top() + (contentsRect.height() - textSize.height())/2 ), textSize ); } // handle right to left if( iconRect.isValid() ) iconRect = visualRect( option, iconRect ); if( textRect.isValid() ) textRect = visualRect( option, textRect ); // make sure there is enough room for icon if( iconRect.isValid() ) iconRect = centerRect( iconRect, iconSize ); // render icon if( hasIcon && iconRect.isValid() ) { // icon state and mode const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off ); QIcon::Mode iconMode; if( !enabled ) iconMode = QIcon::Disabled; else if( mouseOver && flat ) iconMode = QIcon::Active; else iconMode = QIcon::Normal; const QPixmap pixmap = buttonOption->icon.pixmap( iconSize, iconMode, iconState ); drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); } // render text if( hasText && textRect.isValid() ) { drawItemText( painter, textRect, textFlags, palette, enabled, buttonOption->text, textRole ); } return true; } //___________________________________________________________________________________ bool Style::drawToolButtonLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionToolButton* toolButtonOption( qstyleoption_cast(option) ); // copy rect and palette const QRect& rect = option->rect; const QPalette& palette = option->palette; // state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool sunken( ( state & State_On ) || ( state & State_Sunken ) ); const bool mouseOver( enabled && (option->state & State_MouseOver) ); const bool flat( state & State_AutoRaise ); const bool hasArrow( toolButtonOption->features & QStyleOptionToolButton::Arrow ); const bool hasIcon( !( hasArrow || toolButtonOption->icon.isNull() ) ); const bool hasText( !toolButtonOption->text.isEmpty() ); // icon size const QSize iconSize( toolButtonOption->iconSize ); // text size int textFlags( _mnemonics->textFlags() ); const QSize textSize( option->fontMetrics.size( textFlags, toolButtonOption->text ) ); // adjust text and icon rect based on options QRect iconRect; QRect textRect; if( hasText && ( !(hasArrow||hasIcon) || toolButtonOption->toolButtonStyle == Qt::ToolButtonTextOnly ) ) { // text only textRect = rect; textFlags |= Qt::AlignCenter; } else if( (hasArrow||hasIcon) && (!hasText || toolButtonOption->toolButtonStyle == Qt::ToolButtonIconOnly ) ) { // icon only iconRect = rect; } else if( toolButtonOption->toolButtonStyle == Qt::ToolButtonTextUnderIcon ) { const int contentsHeight( iconSize.height() + textSize.height() + Metrics::ToolButton_ItemSpacing ); iconRect = QRect( QPoint( rect.left() + (rect.width() - iconSize.width())/2, rect.top() + (rect.height() - contentsHeight)/2 ), iconSize ); textRect = QRect( QPoint( rect.left() + (rect.width() - textSize.width())/2, iconRect.bottom() + Metrics::ToolButton_ItemSpacing + 1 ), textSize ); textFlags |= Qt::AlignCenter; } else { const bool leftAlign( widget && widget->property( PropertyNames::toolButtonAlignment ).toInt() == Qt::AlignLeft ); if( leftAlign ) { const int marginWidth( Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth + 1 ); iconRect = QRect( QPoint( rect.left() + marginWidth, rect.top() + (rect.height() - iconSize.height())/2 ), iconSize ); } else { const int contentsWidth( iconSize.width() + textSize.width() + Metrics::ToolButton_ItemSpacing ); iconRect = QRect( QPoint( rect.left() + (rect.width() - contentsWidth )/2, rect.top() + (rect.height() - iconSize.height())/2 ), iconSize ); } textRect = QRect( QPoint( iconRect.right() + Metrics::ToolButton_ItemSpacing + 1, rect.top() + (rect.height() - textSize.height())/2 ), textSize ); // handle right to left layouts iconRect = visualRect( option, iconRect ); textRect = visualRect( option, textRect ); textFlags |= Qt::AlignLeft | Qt::AlignVCenter; } // make sure there is enough room for icon if( iconRect.isValid() ) iconRect = centerRect( iconRect, iconSize ); // render arrow or icon if( hasArrow && iconRect.isValid() ) { QStyleOptionToolButton copy( *toolButtonOption ); copy.rect = iconRect; switch( toolButtonOption->arrowType ) { case Qt::LeftArrow: drawPrimitive( PE_IndicatorArrowLeft, ©, painter, widget ); break; case Qt::RightArrow: drawPrimitive( PE_IndicatorArrowRight, ©, painter, widget ); break; case Qt::UpArrow: drawPrimitive( PE_IndicatorArrowUp, ©, painter, widget ); break; case Qt::DownArrow: drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget ); break; default: break; } } else if( hasIcon && iconRect.isValid() ) { // icon state and mode const QIcon::State iconState( sunken ? QIcon::On : QIcon::Off ); QIcon::Mode iconMode; if( !enabled ) iconMode = QIcon::Disabled; else if( mouseOver && flat ) iconMode = QIcon::Active; else iconMode = QIcon::Normal; const QPixmap pixmap = toolButtonOption->icon.pixmap( iconSize, iconMode, iconState ); drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); } // render text if( hasText && textRect.isValid() ) { const QPalette::ColorRole textRole( flat ? QPalette::WindowText: QPalette::ButtonText ); painter->setFont(toolButtonOption->font); drawItemText( painter, textRect, textFlags, palette, enabled, toolButtonOption->text, textRole ); } return true; } //___________________________________________________________________________________ bool Style::drawMenuBarItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast( option ); if( !menuItemOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool selected( enabled && (state & State_Selected) ); const bool sunken( state & State_Sunken ); const bool useStrongFocus = StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG; if( enabled ) { const bool active( state & State_Selected ); const bool animated( _animations->menuBarEngine().isAnimated( widget, rect.topLeft() ) ); const qreal opacity( _animations->menuBarEngine().opacity( widget, rect.topLeft() ) ); const QRect currentRect( _animations->menuBarEngine().currentRect( widget, rect.topLeft() ) ); const QRect animatedRect( _animations->menuBarEngine().animatedRect( widget ) ); const bool intersected( animatedRect.intersects( rect ) ); const bool current( currentRect.contains( rect.topLeft() ) ); const bool timerIsActive( _animations->menuBarEngine().isTimerActive( widget ) ); // do nothing in case of empty intersection between animated rect and current if( ( intersected || !animated || animatedRect.isNull() ) && ( active || animated || timerIsActive ) ) { QColor color( _helper->calcMidColor( palette.color( QPalette::Window ) ) ); if( StyleConfigData::menuHighlightMode() != StyleConfigData::MM_DARK ) { if( state & State_Sunken ) { if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) color = palette.color( QPalette::Highlight ); else color = KColorUtils::mix( color, KColorUtils::tint( color, palette.color( QPalette::Highlight ), 0.6 ) ); } else { if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) color = KColorUtils::tint( color, _helper->hoverColor( palette ) ); else color = KColorUtils::mix( color, KColorUtils::tint( color, _helper->hoverColor( palette ) ) ); } } else color = _helper->backgroundColor( color, widget, rect.center() ); // drawing if( animated && intersected ) { _helper->holeFlat( color, 0 ).render( insideMargin( animatedRect, 1 ), painter, TileSet::Full ); } else if( timerIsActive && current ) { _helper->holeFlat( color, 0 ).render( insideMargin( rect, 1 ), painter, TileSet::Full ); } else if( animated && current ) { color.setAlphaF( opacity ); _helper->holeFlat( color, 0 ).render( insideMargin( rect, 1 ), painter, TileSet::Full ); } else if( active ) { _helper->holeFlat( color, 0 ).render( insideMargin( rect, 1 ), painter, TileSet::Full ); } } } /* check if item as an icon, in which case only the icon should be rendered consistently with comment in QMenuBarPrivate::calcActionRects */ if( !menuItemOption->icon.isNull() ) { // icon size is forced to SmallIconSize const auto iconSize = pixelMetric(QStyle::PM_SmallIconSize, nullptr, widget); const auto iconRect = centerRect( rect, iconSize, iconSize ); // decide icon mode and state QIcon::Mode iconMode; QIcon::State iconState; if( !enabled ) { iconMode = QIcon::Disabled; iconState = QIcon::Off; } else { if( useStrongFocus && sunken ) iconMode = QIcon::Selected; else if( selected ) iconMode = QIcon::Active; else iconMode = QIcon::Normal; iconState = sunken ? QIcon::On : QIcon::Off; } const auto pixmap = menuItemOption->icon.pixmap( iconSize, iconMode, iconState ); drawItemPixmap( painter, iconRect, Qt::AlignCenter, pixmap ); } else { // text role QPalette::ColorRole role( QPalette::WindowText ); if( useStrongFocus && sunken && enabled ) { role = QPalette::HighlightedText; } // text flags const int textFlags( Qt::AlignCenter|_mnemonics->textFlags() ); drawItemText( painter, rect, textFlags, palette, enabled, menuItemOption->text, role ); } return true; } //___________________________________________________________________________________ bool Style::drawMenuItemControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast( option ); if( !menuItemOption ) return true; if( menuItemOption->menuItemType == QStyleOptionMenuItem::EmptyArea ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // render background renderMenuItemBackground( option, painter, widget ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool selected( enabled && (state & State_Selected) ); const bool sunken( enabled && (state & (State_On|State_Sunken) ) ); const bool hasFocus( enabled && ( state & State_HasFocus ) ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // Active indicator if( selected ) { // check if there is a 'sliding' animation in progress, in which case, do nothing const QRect animatedRect( _animations->menuEngine().animatedRect( widget ) ); if( animatedRect.isNull() ) { const bool animated( _animations->menuEngine().isAnimated( widget, Current ) ); const QRect currentRect( _animations->menuEngine().currentRect( widget, Current ) ); const bool intersected( currentRect.contains( rect.topLeft() ) ); const QColor color( _helper->menuBackgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, rect.center() ) ); if( animated && intersected ) renderMenuItemRect( option, rect, color, palette, painter, _animations->menuEngine().opacity( widget, Current ) ); else renderMenuItemRect( option, rect, color, palette, painter ); } } // get rect available for contents QRect contentsRect( insideMargin( rect, Metrics::MenuItem_MarginWidth ) ); // deal with separators if( menuItemOption->menuItemType == QStyleOptionMenuItem::Separator ) { // normal separator if( menuItemOption->text.isEmpty() && menuItemOption->icon.isNull() ) { // in all other cases draw regular separator const QColor color( _helper->menuBackgroundColor( palette.color( QPalette::Window ), widget, rect.center() ) ); _helper->drawSeparator( painter, rect, color, Qt::Horizontal ); return true; } else { // separator can have a title and an icon // in that case they are rendered as sunken flat toolbuttons QStyleOptionToolButton toolButtonOption( separatorMenuItemOption( menuItemOption, widget ) ); toolButtonOption.state = State_On|State_Sunken|State_Enabled; drawComplexControl( CC_ToolButton, &toolButtonOption, painter, widget ); return true; } } // define relevant rectangles // checkbox QRect checkBoxRect; if( menuItemOption->menuHasCheckableItems ) { checkBoxRect = QRect( contentsRect.left(), contentsRect.top() + (contentsRect.height()-Metrics::CheckBox_Size)/2 - 1, Metrics::CheckBox_Size, Metrics::CheckBox_Size ); contentsRect.setLeft( checkBoxRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); } // render checkbox indicator const CheckBoxState checkBoxState( menuItemOption->checked ? CheckOn:CheckOff ); if( menuItemOption->checkType == QStyleOptionMenuItem::NonExclusive ) { checkBoxRect = visualRect( option, checkBoxRect ); StyleOptions styleOptions; styleOptions |= Sunken; if( !enabled ) styleOptions |= Disabled; if( mouseOver ) styleOptions |= Hover; if( hasFocus ) styleOptions |= Focus; QPalette localPalette( palette ); localPalette.setColor( QPalette::Window, _helper->menuBackgroundColor( palette.color( QPalette::Window ), widget, rect.topLeft() ) ); renderCheckBox( painter, checkBoxRect, localPalette, styleOptions, checkBoxState ); } else if( menuItemOption->checkType == QStyleOptionMenuItem::Exclusive ) { checkBoxRect = visualRect( option, checkBoxRect ); StyleOptions styleOptions; if( !enabled ) styleOptions |= Disabled; if( mouseOver ) styleOptions |= Hover; if( hasFocus ) styleOptions |= Focus; QPalette localPalette( palette ); localPalette.setColor( QPalette::Window, _helper->menuBackgroundColor( palette.color( QPalette::Window ), widget, rect.topLeft() ) ); renderRadioButton( painter, checkBoxRect, localPalette, styleOptions, checkBoxState ); } // icon const int iconWidth( isQtQuickControl( option, widget ) ? qMax( pixelMetric(PM_SmallIconSize, option, widget ), menuItemOption->maxIconWidth ) : menuItemOption->maxIconWidth ); QRect iconRect( contentsRect.left(), contentsRect.top() + (contentsRect.height()-iconWidth)/2, iconWidth, iconWidth ); contentsRect.setLeft( iconRect.right() + Metrics::MenuItem_ItemSpacing + 1 ); if( !menuItemOption->icon.isNull() ) { const QSize iconSize( pixelMetric( PM_SmallIconSize, option, widget ), pixelMetric( PM_SmallIconSize, option, widget ) ); iconRect = centerRect( iconRect, iconSize ); iconRect = visualRect( option, iconRect ); // icon mode QIcon::Mode mode; if( (StyleConfigData::menuHighlightMode() != StyleConfigData::MM_DARK) && selected ) mode = QIcon::Selected; else if( selected ) mode = QIcon::Active; else if( enabled ) mode = QIcon::Normal; else mode = QIcon::Disabled; // icon state const QIcon::State iconState( sunken ? QIcon::On:QIcon::Off ); const QPixmap icon = menuItemOption->icon.pixmap( iconRect.size(), mode, iconState ); painter->drawPixmap( iconRect, icon ); } // text role const QPalette::ColorRole textRole( ( selected && StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) ? QPalette::HighlightedText: QPalette::WindowText ); QRect arrowRect( contentsRect.right() - Metrics::MenuButton_IndicatorWidth + 1, contentsRect.top() + (contentsRect.height()-Metrics::MenuButton_IndicatorWidth)/2, Metrics::MenuButton_IndicatorWidth, Metrics::MenuButton_IndicatorWidth ); contentsRect.setRight( arrowRect.left() - Metrics::MenuItem_ItemSpacing - 1 ); // arrow if( menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu ) { const qreal penThickness = 1.6; const QColor color = palette.color( textRole ); const QColor background = palette.color( QPalette::Window ); // get arrow shape QPolygonF arrow = genericArrow( option->direction == Qt::LeftToRight ? ArrowRight : ArrowLeft, ArrowNormal ); painter->save(); painter->translate( QRectF( arrowRect ).center() ); painter->setRenderHint( QPainter::Antialiasing ); // white outline const qreal offset( qMin( penThickness, qreal( 1 ) ) ); painter->translate( 0,offset ); painter->setPen( QPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->translate( 0,-offset ); painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->restore(); } // text QRect textRect = contentsRect; if( !menuItemOption->text.isEmpty() ) { // adjust textRect QString text = menuItemOption->text; textRect = centerRect( textRect, textRect.width(), option->fontMetrics.size( _mnemonics->textFlags(), text ).height() ); textRect = visualRect( option, textRect ); // set font painter->setFont( menuItemOption->font ); // locate accelerator and render const int tabPosition( text.indexOf( QLatin1Char( '\t' ) ) ); if( tabPosition >= 0 ) { QString accelerator( text.mid( tabPosition + 1 ) ); text = text.left( tabPosition ); drawItemText( painter, textRect, Qt::AlignRight | Qt::AlignVCenter | _mnemonics->textFlags(), palette, enabled, accelerator, textRole ); } // render text const int textFlags( Qt::AlignVCenter | (reverseLayout ? Qt::AlignRight : Qt::AlignLeft ) | _mnemonics->textFlags() ); drawItemText( painter, textRect, textFlags, palette, enabled, text, textRole ); } return true; } //___________________________________________________________________________________ bool Style::drawProgressBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { const QStyleOptionProgressBar* progressBarOption( qstyleoption_cast( option ) ); if( !progressBarOption ) return true; QStyleOptionProgressBarV2 progressBarOption2 = *progressBarOption; progressBarOption2.rect = subElementRect( SE_ProgressBarGroove, progressBarOption, widget ); drawControl( CE_ProgressBarGroove, &progressBarOption2, painter, widget ); // enable busy animations #if QT_VERSION >= 0x050000 const QObject* styleObject( widget ? widget:progressBarOption->styleObject ); #else const QObject* styleObject( widget ); #endif if( styleObject && _animations->busyIndicatorEngine().enabled() ) { #if QT_VERSION >= 0x050000 // register QML object if defined if( !widget && progressBarOption->styleObject ) { _animations->busyIndicatorEngine().registerWidget( progressBarOption->styleObject ); } #endif _animations->busyIndicatorEngine().setAnimated( styleObject, progressBarOption->maximum == 0 && progressBarOption->minimum == 0 ); } if( _animations->busyIndicatorEngine().isAnimated( styleObject ) ) { progressBarOption2.progress = _animations->busyIndicatorEngine().value(); } // render contents progressBarOption2.rect = subElementRect( SE_ProgressBarContents, progressBarOption, widget ); drawControl( CE_ProgressBarContents, &progressBarOption2, painter, widget ); // render text const bool textVisible( progressBarOption->textVisible ); const bool busy( progressBarOption->minimum == 0 && progressBarOption->maximum == 0 ); if( textVisible && !busy ) { progressBarOption2.rect = subElementRect( SE_ProgressBarLabel, progressBarOption, widget ); drawControl( CE_ProgressBarLabel, &progressBarOption2, painter, widget ); } return true; } //___________________________________________________________________________________ bool Style::drawProgressBarContentsControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const { // cast option and check const QStyleOptionProgressBar* progressBarOption = qstyleoption_cast( option ); if( !progressBarOption ) return true; // get orientation const QStyleOptionProgressBarV2* progressBarOption2 = qstyleoption_cast( option ); const bool horizontal( !progressBarOption2 || progressBarOption2->orientation == Qt::Horizontal ); // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // make sure rect is large enough if( rect.isValid() ) { // calculate dimension int dimension( 20 ); if( progressBarOption2 ) dimension = qMax( 5, horizontal ? rect.height() : rect.width() ); _helper->progressBarIndicator( palette, dimension ).render( rect, painter, TileSet::Full ); } return true; } //___________________________________________________________________________________ bool Style::drawProgressBarGrooveControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const { const QStyleOptionProgressBarV2 *progressBarOption = qstyleoption_cast( option ); const Qt::Orientation orientation( progressBarOption? progressBarOption->orientation : Qt::Horizontal ); renderScrollBarHole( painter, option->rect, option->palette.color( QPalette::Window ), orientation ); return true; } //___________________________________________________________________________________ bool Style::drawProgressBarLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionProgressBar* progressBarOption = qstyleoption_cast( option ); if( !progressBarOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool reverseLayout = ( option->direction == Qt::RightToLeft ); // get orientation const QStyleOptionProgressBarV2* progressBarOption2 = qstyleoption_cast( option ); const bool horizontal = !progressBarOption2 || progressBarOption2->orientation == Qt::Horizontal; // check inverted appearance const bool inverted( progressBarOption2 ? progressBarOption2->invertedAppearance : false ); // rotate label for vertical layout QTransform transform; if( !horizontal ) { if( reverseLayout ) transform.rotate( -90 ); else transform.rotate( 90 ); } painter->setTransform( transform ); const QRect progressRect( transform.inverted().mapRect( subElementRect( SE_ProgressBarContents, progressBarOption, widget ) ) ); QRect textRect( transform.inverted().mapRect( rect ) ); Qt::Alignment hAlign( ( progressBarOption->textAlignment == Qt::AlignLeft ) ? Qt::AlignHCenter : progressBarOption->textAlignment ); /* Figure out the geometry of the indicator. This is copied from drawProgressBarContentsControl */ if( progressRect.isValid() ) { // first pass ( normal ) QRect textClipRect( textRect ); if( horizontal ) { if( (reverseLayout && !inverted) || (inverted && !reverseLayout) ) textClipRect.setRight( progressRect.left() ); else textClipRect.setLeft( progressRect.right() + 1 ); } else if( (reverseLayout && !inverted) || (inverted && !reverseLayout) ) textClipRect.setLeft( progressRect.right() + 1 ); else textClipRect.setRight( progressRect.left() ); painter->setClipRect( textClipRect ); drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, progressBarOption->text, QPalette::WindowText ); // second pass ( highlighted ) painter->setClipRect( progressRect ); drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, progressBarOption->text, QPalette::HighlightedText ); } else { drawItemText( painter, textRect, Qt::AlignVCenter | hAlign, palette, enabled, progressBarOption->text, QPalette::WindowText ); } return true; } //___________________________________________________________________________________ bool Style::drawScrollBarSliderControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionSlider *sliderOption = qstyleoption_cast( option ); if( !sliderOption ) return true; // store rect and palette QRect rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const Qt::Orientation orientation( (state & State_Horizontal) ? Qt::Horizontal : Qt::Vertical ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); // update animations _animations->scrollBarEngine().updateState( widget, enabled && ( sliderOption->activeSubControls & SC_ScrollBarSlider ) ); const bool animated( enabled && _animations->scrollBarEngine().isAnimated( widget, SC_ScrollBarSlider ) ); if( orientation == Qt::Horizontal ) rect = insideMargin( rect, 0, 1 ); else rect = insideMargin( rect, 1, 0 ); // render if( animated ) renderScrollBarHandle( painter, rect, palette, orientation, mouseOver, _animations->scrollBarEngine().opacity( widget, SC_ScrollBarSlider ) ); else renderScrollBarHandle( painter, rect, palette, orientation, mouseOver ); return true; } //___________________________________________________________________________________ bool Style::drawScrollBarAddLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // do nothing if no buttons are defined if( _addLineButtons == NoButton ) return true; // cast option and check const QStyleOptionSlider* sliderOption( qstyleoption_cast( option ) ); if( !sliderOption ) return true; const State& state( option->state ); const bool horizontal( state & State_Horizontal ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // colors const QPalette& palette( option->palette ); const QColor background( palette.color( QPalette::Window ) ); // adjust rect, based on number of buttons to be drawn const QRect rect( scrollBarInternalSubControlRect( sliderOption, SC_ScrollBarAddLine ) ); QColor color; QStyleOptionSlider copy( *sliderOption ); if( _addLineButtons == DoubleButton ) { if( horizontal ) { //Draw the arrows const QSize halfSize( rect.width()/2, rect.height() ); const QRect leftSubButton( rect.topLeft(), halfSize ); const QRect rightSubButton( leftSubButton.topRight() + QPoint( 1, 0 ), halfSize ); copy.rect = leftSubButton; color = scrollBarArrowColor( ©, reverseLayout ? SC_ScrollBarAddLine:SC_ScrollBarSubLine, widget ); renderScrollBarArrow( painter, leftSubButton, color, background, ArrowLeft ); copy.rect = rightSubButton; color = scrollBarArrowColor( ©, reverseLayout ? SC_ScrollBarSubLine:SC_ScrollBarAddLine, widget ); renderScrollBarArrow( painter, rightSubButton, color, background, ArrowRight ); } else { const QSize halfSize( rect.width(), rect.height()/2 ); const QRect topSubButton( rect.topLeft(), halfSize ); const QRect botSubButton( topSubButton.bottomLeft() + QPoint( 0, 1 ), halfSize ); copy.rect = topSubButton; color = scrollBarArrowColor( ©, SC_ScrollBarSubLine, widget ); renderScrollBarArrow( painter, topSubButton, color, background, ArrowUp ); copy.rect = botSubButton; color = scrollBarArrowColor( ©, SC_ScrollBarAddLine, widget ); renderScrollBarArrow( painter, botSubButton, color, background, ArrowDown ); } } else if( _addLineButtons == SingleButton ) { copy.rect = rect; color = scrollBarArrowColor( ©, SC_ScrollBarAddLine, widget ); if( horizontal ) renderScrollBarArrow( painter, rect, color, background, reverseLayout ? ArrowLeft : ArrowRight ); else renderScrollBarArrow( painter, rect, color, background, ArrowDown ); } return true; } //___________________________________________________________________________________ bool Style::drawScrollBarSubLineControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // do nothing if no buttons are set if( _subLineButtons == NoButton ) return true; // cast option and check const QStyleOptionSlider* sliderOption( qstyleoption_cast( option ) ); if( !sliderOption ) return true; const State& state( option->state ); const bool horizontal( state & State_Horizontal ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // colors const QPalette& palette( option->palette ); const QColor background( palette.color( QPalette::Window ) ); // adjust rect, based on number of buttons to be drawn QRect rect( scrollBarInternalSubControlRect( sliderOption, SC_ScrollBarSubLine ) ); QColor color; QStyleOptionSlider copy( *sliderOption ); if( _subLineButtons == DoubleButton ) { if( horizontal ) { //Draw the arrows const QSize halfSize( rect.width()/2, rect.height() ); const QRect leftSubButton( rect.topLeft(), halfSize ); const QRect rightSubButton( leftSubButton.topRight() + QPoint( 1, 0 ), halfSize ); copy.rect = leftSubButton; color = scrollBarArrowColor( ©, reverseLayout ? SC_ScrollBarAddLine:SC_ScrollBarSubLine, widget ); renderScrollBarArrow( painter, leftSubButton, color, background, ArrowLeft ); copy.rect = rightSubButton; color = scrollBarArrowColor( ©, reverseLayout ? SC_ScrollBarSubLine:SC_ScrollBarAddLine, widget ); renderScrollBarArrow( painter, rightSubButton, color, background, ArrowRight ); } else { const QSize halfSize( rect.width(), rect.height()/2 ); const QRect topSubButton( rect.topLeft(), halfSize ); const QRect botSubButton( topSubButton.bottomLeft() + QPoint( 0, 1 ), halfSize ); copy.rect = topSubButton; color = scrollBarArrowColor( ©, SC_ScrollBarSubLine, widget ); renderScrollBarArrow( painter, topSubButton, color, background, ArrowUp ); copy.rect = botSubButton; color = scrollBarArrowColor( ©, SC_ScrollBarAddLine, widget ); renderScrollBarArrow( painter, botSubButton, color, background, ArrowDown ); } } else if( _subLineButtons == SingleButton ) { copy.rect = rect; color = scrollBarArrowColor( ©, SC_ScrollBarSubLine, widget ); if( horizontal ) renderScrollBarArrow( painter, rect, color, background, reverseLayout ? ArrowRight : ArrowLeft ); else renderScrollBarArrow( painter, rect, color, background, ArrowUp ); } return true; } //___________________________________________________________________________________ bool Style::drawShapedFrameControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionFrameV3* frameOption = qstyleoption_cast( option ); if( !frameOption ) return false; switch( frameOption->frameShape ) { case QFrame::Box: { if( option->state & State_Sunken ) return true; else break; } case QFrame::HLine: { const QColor color( _helper->backgroundColor( option->palette.color( QPalette::Window ), widget, option->rect.center() ) ); _helper->drawSeparator( painter, option->rect, color, Qt::Horizontal ); return true; } case QFrame::VLine: { const QColor color( _helper->backgroundColor( option->palette.color( QPalette::Window ), widget, option->rect.center() ) ); _helper->drawSeparator( painter, option->rect, color, Qt::Vertical ); return true; } case QFrame::StyledPanel: { if( isQtQuickControl( option, widget ) ) { // ComboBox popup frame drawFrameMenuPrimitive( option, painter, widget ); return true; } else break; } default: break; } return false; } //___________________________________________________________________________________ bool Style::drawRubberBandControl( const QStyleOption* option, QPainter* painter, const QWidget* ) const { const QPalette& palette( option->palette ); const QRect rect( option->rect ); QColor color = palette.color( QPalette::Highlight ); painter->setPen( KColorUtils::mix( color, palette.color( QPalette::Active, QPalette::WindowText ) ) ); color.setAlpha( 50 ); painter->setBrush( color ); painter->setClipRegion( rect ); painter->drawRect( rect.adjusted( 0, 0, -1, -1 ) ); return true; } //___________________________________________________________________________________ bool Style::drawHeaderSectionControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionHeader* headerOption( qstyleoption_cast( option ) ); if( !headerOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const bool horizontal( headerOption->orientation == Qt::Horizontal ); const bool reverseLayout( option->direction == Qt::RightToLeft ); const bool isFirst( horizontal && ( headerOption->position == QStyleOptionHeader::Beginning ) ); const bool isCorner( widget && widget->inherits( "QTableCornerButton" ) ); // corner header lines if( isCorner ) { if( widget ) _helper->renderWindowBackground( painter, rect, widget, palette ); else painter->fillRect( rect, palette.color( QPalette::Window ) ); if( reverseLayout ) renderHeaderLines( rect, palette, painter, TileSet::BottomLeft ); else renderHeaderLines( rect, palette, painter, TileSet::BottomRight ); } else renderHeaderBackground( rect, palette, painter, widget, horizontal, reverseLayout ); // dots const QColor color( palette.color( QPalette::Window ) ); if( horizontal ) { if( headerOption->section != 0 || isFirst ) { const int center( rect.center().y() ); const int pos( reverseLayout ? rect.left()+1 : rect.right()-1 ); _helper->renderDot( painter, QPoint( pos, center-3 ), color ); _helper->renderDot( painter, QPoint( pos, center ), color ); _helper->renderDot( painter, QPoint( pos, center+3 ), color ); } } else { const int center( rect.center().x() ); const int pos( rect.bottom()-1 ); _helper->renderDot( painter, QPoint( center-3, pos ), color ); _helper->renderDot( painter, QPoint( center, pos ), color ); _helper->renderDot( painter, QPoint( center+3, pos ), color ); } return true; } //___________________________________________________________________________________ bool Style::drawHeaderEmptyAreaControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // use the same background as in drawHeaderPrimitive QPalette palette( option->palette ); - if( widget && _animations->widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) ) - { palette = _helper->disabledPalette( palette, _animations->widgetEnabilityEngine().opacity( widget, AnimationEnable ) ); } + if( widget && _animations->widgetEnableStateEngine().isAnimated( widget, AnimationEnable ) ) + { palette = _helper->disabledPalette( palette, _animations->widgetEnableStateEngine().opacity( widget, AnimationEnable ) ); } const bool horizontal( option->state & QStyle::State_Horizontal ); const bool reverseLayout( option->direction == Qt::RightToLeft ); renderHeaderBackground( option->rect, palette, painter, widget, horizontal, reverseLayout ); return true; } //___________________________________________________________________________________ bool Style::drawTabBarTabLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // call parent style method ParentStyleClass::drawControl( CE_TabBarTabLabel, option, painter, widget ); // store rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // check focus const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool selected( state & State_Selected ); const bool hasFocus( enabled && selected && (state & State_HasFocus) ); // update mouse over animation state _animations->tabBarEngine().updateState( widget, rect.topLeft(), AnimationFocus, hasFocus ); const bool animated( enabled && selected && _animations->tabBarEngine().isAnimated( widget, rect.topLeft(), AnimationFocus ) ); const qreal opacity( _animations->tabBarEngine().opacity( widget, rect.topLeft(), AnimationFocus ) ); if( !( hasFocus || animated ) ) return true; // code is copied from QCommonStyle, but adds focus // cast option and check const QStyleOptionTab *tabOption( qstyleoption_cast(option) ); if( !tabOption || tabOption->text.isEmpty() ) return true; // tab option rect const bool verticalTabs( isVerticalTab( tabOption ) ); const int textFlags( Qt::AlignCenter | _mnemonics->textFlags() ); // text rect QRect textRect( subElementRect(SE_TabBarTabText, option, widget) ); if( verticalTabs ) { // properly rotate painter painter->save(); int newX, newY, newRot; if( tabOption->shape == QTabBar::RoundedEast || tabOption->shape == QTabBar::TriangularEast) { newX = rect.width() + rect.x(); newY = rect.y(); newRot = 90; } else { newX = rect.x(); newY = rect.y() + rect.height(); newRot = -90; } QTransform transform; transform.translate( newX, newY ); transform.rotate(newRot); painter->setTransform( transform, true ); } // adjust text rect based on font metrics textRect = option->fontMetrics.boundingRect( textRect, textFlags, tabOption->text ); // focus color QColor focusColor; if( animated ) focusColor = _helper->alphaColor( _helper->focusColor( palette ), opacity ); else if( hasFocus ) focusColor = _helper->focusColor( palette ); // render focus line if( focusColor.isValid() ) { painter->save(); painter->setRenderHint( QPainter::Antialiasing, false ); painter->setBrush( Qt::NoBrush ); painter->setPen( focusColor ); painter->translate( 0, 2 ); painter->drawLine( textRect.bottomLeft(), textRect.bottomRight() ); painter->restore(); } if( verticalTabs ) painter->restore(); return true; } //___________________________________________________________________________________ bool Style::drawTabBarTabShapeControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // check if tabwidget is selected and redirect const State& state( option->state ); const bool selected( state & State_Selected ); if( selected ) return drawTabBarTabShapeControl_selected( option, painter, widget ); else return drawTabBarTabShapeControl_unselected( option, painter, widget ); } //___________________________________________________________________________________ bool Style::drawTabBarTabShapeControl_selected( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionTab* tabOption( qstyleoption_cast( option ) ); if( !tabOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // tab position and state const QStyleOptionTab::TabPosition& position = tabOption->position; bool isFirst( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::Beginning ); bool isLast( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::End ); // document mode const QStyleOptionTabV3 *tabOptionV3 = qstyleoption_cast( option ); bool documentMode = tabOptionV3 ? tabOptionV3->documentMode : false; const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast( widget->parentWidget() ) : nullptr; documentMode |= ( tabWidget ? tabWidget->documentMode() : true ); // this is needed to complete the base frame when there are widgets in tabbar const QTabBar* tabBar( qobject_cast( widget ) ); const QRect tabBarRect( tabBar ? tabBar->rect():QRect() ); // check if tab is being dragged const bool isDragged( painter->device() != tabBar ); // hover and animation state /* all are disabled when tabBar is locked ( drag in progress ) */ const bool tabBarLocked( _tabBarData->locks( tabBar ) ); const bool mouseOver( enabled && !tabBarLocked && ( state & State_MouseOver ) ); // animation state _animations->tabBarEngine().updateState( widget, rect.topLeft(), AnimationHover, mouseOver ); // handle base frame painting, for tabbars in which tab is being dragged _tabBarData->drawTabBarBaseControl( tabOption, painter, widget ); if( tabBar && isDragged ) _tabBarData->lock( tabBar ); else if( _tabBarData->locks( tabBar ) ) _tabBarData->release(); // corner widgets const bool verticalTabs( isVerticalTab( tabOption ) ); const bool hasLeftCornerWidget( (tabOption->cornerWidgets & QStyleOptionTab::LeftCornerWidget) && !verticalTabs ); // true if widget is aligned to the frame const bool isFrameAligned( !documentMode && isFirst && !hasLeftCornerWidget && !isDragged ); // swap state based on reverse layout, so that they become layout independent if( reverseLayout && !verticalTabs ) qSwap( isFirst, isLast ); // part of the tab in which the text is drawn QRect tabRect( insideMargin( rect, -1 ) ); SlabRect tabSlab( insideMargin( rect, -1 ), TileSet::Ring ); // connection to the frame SlabRect::List slabs; switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: { tabSlab.tiles &= ~TileSet::Bottom; tabSlab.rect.adjust( 0, 0, 0, 2 ); if( isDragged ) break; // left side if( isFrameAligned && !reverseLayout ) { QRect frameRect( rect ); frameRect.setLeft( frameRect.left() - 1 ); frameRect.setRight( tabRect.left() ); frameRect.setTop( tabRect.bottom() - 4 ); slabs << SlabRect( frameRect, TileSet::Left ).adjusted( TileSet::DefaultSize ); } else { QRect frameRect( rect ); frameRect.setRight( tabRect.left() + 3 ); frameRect.setTop( rect.bottom() - TileSet::DefaultSize + 1 ); slabs << SlabRect( frameRect, TileSet::Top ).adjusted( TileSet::DefaultSize ); } // right side if( isFrameAligned && reverseLayout ) { QRect frameRect( rect ); frameRect.setLeft( tabRect.right() ); frameRect.setRight( frameRect.right() + 1 ); frameRect.setTop( tabRect.bottom() - 4 ); slabs << SlabRect( frameRect, TileSet::Right ).adjusted( TileSet::DefaultSize ); } else { QRect frameRect( rect ); frameRect.setLeft( tabRect.right() - 3 ); frameRect.setTop( rect.bottom() - TileSet::DefaultSize + 1 ); slabs << SlabRect( frameRect, TileSet::Top ).adjusted( TileSet::DefaultSize ); } // extra base, to extend below inactive tabs and buttons if( tabBar ) { QRect frameRect( rect ); frameRect.setTop( rect.bottom() - Metrics::TabBar_BaseOverlap + 1 ); if( rect.left() > tabBarRect.left() ) { frameRect.setLeft( tabBarRect.left() - Metrics::TabBar_BaseOverlap ); frameRect.setRight( rect.left() + Metrics::TabBar_BaseOverlap - 1 ); if( documentMode || reverseLayout ) slabs << SlabRect( frameRect, TileSet::Top ); else slabs << SlabRect( frameRect, TileSet::TopLeft ); } if( rect.right() < tabBarRect.right() ) { frameRect.setLeft( rect.right() - Metrics::TabBar_BaseOverlap + 1 ); frameRect.setRight( tabBarRect.right() + Metrics::TabBar_BaseOverlap ); if( documentMode || !reverseLayout ) slabs << SlabRect( frameRect, TileSet::Top ); else slabs << SlabRect( frameRect, TileSet::TopRight ); } } break; } case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: { tabSlab.tiles &= ~TileSet::Top; tabSlab.rect.adjust( 0, -2, 0, 0 ); if( isDragged ) break; // left side if( isFrameAligned && !reverseLayout ) { QRect frameRect( rect ); frameRect.setLeft( frameRect.left() - 1 ); frameRect.setRight( tabRect.left() ); frameRect.setBottom( tabRect.top() + 4 ); slabs << SlabRect( frameRect, TileSet::Left ).adjusted( TileSet::DefaultSize ); } else { QRect frameRect( rect ); frameRect.setRight( tabRect.left() + 3 ); frameRect.setBottom( rect.top() + TileSet::DefaultSize - 1 ); slabs << SlabRect( frameRect, TileSet::Bottom ).adjusted( TileSet::DefaultSize ); } // right side if( isFrameAligned && reverseLayout ) { QRect frameRect( rect ); frameRect.setLeft( tabRect.right() ); frameRect.setRight( frameRect.right() + 1 ); frameRect.setBottom( tabRect.top() + 4 ); slabs << SlabRect( frameRect, TileSet::Right ).adjusted( TileSet::DefaultSize ); } else { QRect frameRect( rect ); frameRect.setLeft( tabRect.right() - 3 ); frameRect.setBottom( rect.top() + TileSet::DefaultSize - 1 ); slabs << SlabRect( frameRect, TileSet::Bottom ).adjusted( TileSet::DefaultSize ); } // extra base, to extend below tabbar buttons if( tabBar ) { QRect frameRect( rect ); frameRect.setBottom( rect.top() + Metrics::TabBar_BaseOverlap - 1 ); if( rect.left() > tabBarRect.left() ) { frameRect.setLeft( tabBarRect.left() - Metrics::TabBar_BaseOverlap ); frameRect.setRight( rect.left() + Metrics::TabBar_BaseOverlap - 1 ); if( documentMode || reverseLayout ) slabs << SlabRect( frameRect, TileSet::Bottom ); else slabs << SlabRect( frameRect, TileSet::BottomLeft ); } if( rect.right() < tabBarRect.right() ) { frameRect.setLeft( rect.right() - Metrics::TabBar_BaseOverlap + 1 ); frameRect.setRight( tabBarRect.right() + Metrics::TabBar_BaseOverlap ); if( documentMode || !reverseLayout ) slabs << SlabRect( frameRect, TileSet::Bottom ); else slabs << SlabRect( frameRect, TileSet::BottomRight ); } } break; } case QTabBar::RoundedWest: case QTabBar::TriangularWest: { tabSlab.tiles &= ~TileSet::Right; tabSlab.rect.adjust( 0, 0, 2, 0 ); if( isDragged ) break; // top side if( isFrameAligned ) { QRect frameRect( rect ); frameRect.setLeft( tabRect.right() - 4 ); frameRect.setTop( frameRect.top() - 1 ); frameRect.setBottom( tabRect.top() ); slabs << SlabRect( frameRect, TileSet::Top ).adjusted( TileSet::DefaultSize ); } else { QRect frameRect( rect ); frameRect.setLeft( rect.right() - TileSet::DefaultSize + 1 ); frameRect.setBottom( tabRect.top() + 3 ); slabs << SlabRect( frameRect, TileSet::Left ).adjusted( TileSet::DefaultSize ); } // bottom side QRect frameRect( rect ); frameRect.setLeft( rect.right() - TileSet::DefaultSize + 1 ); frameRect.setTop( tabRect.bottom() - 3 ); slabs << SlabRect( frameRect, TileSet::Left ).adjusted( TileSet::DefaultSize ); // extra base, to extend below tabbar buttons if( tabBar ) { QRect frameRect( rect ); frameRect.setLeft( rect.right() - Metrics::TabBar_BaseOverlap + 1 ); if( rect.top() > tabBarRect.top() ) { frameRect.setTop( tabBarRect.top() - Metrics::TabBar_BaseOverlap ); frameRect.setBottom( rect.top() + Metrics::TabBar_BaseOverlap - 1 ); if( documentMode ) slabs << SlabRect( frameRect, TileSet::Left ); else slabs << SlabRect( frameRect, TileSet::TopLeft ); } if( rect.bottom() < tabBarRect.bottom() ) { frameRect.setTop( rect.bottom() - Metrics::TabBar_BaseOverlap + 1 ); frameRect.setBottom( tabBarRect.bottom() + Metrics::TabBar_BaseOverlap - 1 ); slabs << SlabRect( frameRect, TileSet::Left ); } } break; } case QTabBar::RoundedEast: case QTabBar::TriangularEast: { tabSlab.tiles &= ~TileSet::Left; tabSlab.rect.adjust( -2, 0, 0, 0 ); if( isDragged ) break; // top side if( isFrameAligned ) { QRect frameRect( rect ); frameRect.setRight( tabRect.left() + 4 ); frameRect.setTop( frameRect.top() - 1 ); frameRect.setBottom( tabRect.top() ); slabs << SlabRect( frameRect, TileSet::Top ).adjusted( TileSet::DefaultSize ); } else { QRect frameRect( rect ); frameRect.setRight( rect.left() + TileSet::DefaultSize - 1 ); frameRect.setBottom( tabRect.top() + 3 ); slabs << SlabRect( frameRect, TileSet::Right ).adjusted( TileSet::DefaultSize ); } // bottom side QRect frameRect( rect ); frameRect.setRight( rect.left() + TileSet::DefaultSize - 1 ); frameRect.setTop( tabRect.bottom() - 3 ); slabs << SlabRect( frameRect, TileSet::Right ).adjusted( TileSet::DefaultSize ); // extra base, to extend below tabbar buttons if( tabBar ) { QRect frameRect( rect ); frameRect.setRight( rect.left() + Metrics::TabBar_BaseOverlap - 1 ); if( rect.top() > tabBarRect.top() ) { frameRect.setTop( tabBarRect.top() - Metrics::TabBar_BaseOverlap ); frameRect.setBottom( rect.top() + Metrics::TabBar_BaseOverlap - 1 ); if( documentMode ) slabs << SlabRect( frameRect, TileSet::Right ); else slabs << SlabRect( frameRect, TileSet::TopRight ); } if( rect.bottom() < tabBarRect.bottom() ) { frameRect.setTop( rect.bottom() - Metrics::TabBar_BaseOverlap + 1 ); frameRect.setBottom( tabBarRect.bottom() + Metrics::TabBar_BaseOverlap - 1 ); slabs << SlabRect( frameRect, TileSet::Right ); } } break; } default: break; } // store default color const QColor color( palette.color( QPalette::Window ) ); // render connections to frame // extra care must be taken care of so that no slab // extends beyond tabWidget frame, if any const QRect tabWidgetRect( tabWidget ? tabWidget->rect().translated( -widget->geometry().topLeft() ) : QRect() ); foreach( SlabRect slab, slabs ) // krazy:exclude=foreach { adjustSlabRect( slab, tabWidgetRect, documentMode, verticalTabs ); renderSlab( painter, slab, color, NoFill ); } // adjust clip rect and render tab if( tabBar ) { painter->save(); painter->setClipRegion( tabBarClipRegion( tabBar ) ); } // fill tab if( isDragged ) fillTabBackground( painter, tabRect, color, widget ); // slab options renderSlab( painter, tabSlab, color, NoFill ); fillTab( painter, tabRect, color, tabOption->shape ); // restore clip region if( tabBar ) painter->restore(); return true; } //___________________________________________________________________________________ bool Style::drawTabBarTabShapeControl_unselected( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionTab* tabOption( qstyleoption_cast( option ) ); if( !tabOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // tab position and flags const QStyleOptionTab::TabPosition& position = tabOption->position; bool isFirst( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::Beginning ); bool isLast( position == QStyleOptionTab::OnlyOneTab || position == QStyleOptionTab::End ); bool isLeftOfSelected( tabOption->selectedPosition == QStyleOptionTab::NextIsSelected ); bool isRightOfSelected( tabOption->selectedPosition == QStyleOptionTab::PreviousIsSelected ); // document mode const QStyleOptionTabV3 *tabOptV3 = qstyleoption_cast( option ); bool documentMode = tabOptV3 ? tabOptV3->documentMode : false; const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast( widget->parentWidget() ) : nullptr; documentMode |= ( tabWidget ? tabWidget->documentMode() : true ); // this is needed to complete the base frame when there are widgets in tabbar const QTabBar* tabBar( qobject_cast( widget ) ); const QRect tabBarRect( tabBar ? tabBar->rect():QRect() ); // hover and animation flags /* all are disabled when tabBar is locked ( drag in progress ) */ const bool tabBarLocked( _tabBarData->locks( tabBar ) ); const bool mouseOver( enabled && !tabBarLocked && ( state & State_MouseOver ) ); // animation state _animations->tabBarEngine().updateState( widget, rect.topLeft(), AnimationHover, mouseOver ); const bool animated( enabled && !tabBarLocked && _animations->tabBarEngine().isAnimated( widget, rect.topLeft(), AnimationHover ) ); // corner widgets const bool verticalTabs( isVerticalTab( tabOption ) ); const bool hasLeftCornerWidget( ( tabOption->cornerWidgets & QStyleOptionTab::LeftCornerWidget ) && !verticalTabs ); // true if widget is aligned to the frame /* need to check for 'isRightOfSelected' because for some reason the isFirst flag is set when active tab is being moved */ const bool isFrameAligned( !documentMode && isFirst && !hasLeftCornerWidget && !isRightOfSelected ); isFirst &= !isRightOfSelected; isLast &= !isLeftOfSelected; // swap flags based on reverse layout, so that they become layout independent if( reverseLayout && !verticalTabs ) { qSwap( isFirst, isLast ); qSwap( isLeftOfSelected, isRightOfSelected ); } const qreal radius = 4; // part of the tab in which the text is drawn QRect tabRect( rect ); QPainterPath path; // highlighted slab (if any) SlabRect highlightSlab; switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: { tabRect.adjust( 0, 3, 1, -4 ); // adjust sides when slab is adjacent to selected slab if( isLeftOfSelected ) tabRect.adjust( 0, 0, 2, 0 ); else if( isRightOfSelected ) tabRect.adjust( -2, 0, 0, 0 ); if( isFirst ) { tabRect.adjust( 1, 0, 0, 0 ); if( isFrameAligned ) path.moveTo( tabRect.bottomLeft() + QPoint( 0, 2 ) ); else path.moveTo( tabRect.bottomLeft() ); path.lineTo( tabRect.topLeft() + QPointF( 0, radius ) ); path.quadTo( tabRect.topLeft(), tabRect.topLeft() + QPoint( radius, 0 ) ); path.lineTo( tabRect.topRight() ); path.lineTo( tabRect.bottomRight() ); } else if( isLast ) { tabRect.adjust( 0, 0, -2, 0 ); path.moveTo( tabRect.bottomLeft() ); path.lineTo( tabRect.topLeft() ); path.lineTo( tabRect.topRight() - QPointF( radius, 0 ) ); path.quadTo( tabRect.topRight(), tabRect.topRight() + QPointF( 0, radius ) ); if( isFrameAligned ) path.lineTo( tabRect.bottomRight() + QPointF( 0, 2 ) ); else path.lineTo( tabRect.bottomRight() ); } else { path.moveTo( tabRect.bottomLeft() ); path.lineTo( tabRect.topLeft() ); path.lineTo( tabRect.topRight() ); path.lineTo( tabRect.bottomRight() ); } // highlight QRect highlightRect( tabRect.left(), tabRect.bottom() - Metrics::TabBar_BaseOverlap + Metrics::TabBar_TabOffset, tabRect.width(), 1 ); if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( -2, 0, 0, 0 ), TileSet::TopLeft ); else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, 0, 2, 0 ), TileSet::TopRight ); else highlightSlab = SlabRect( highlightRect, TileSet::Top ); break; } case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: { tabRect.adjust( 0, 4, 1, -3 ); // adjust sides when slab is adjacent to selected slab if( isLeftOfSelected ) tabRect.adjust( 0, 0, 2, 0 ); else if( isRightOfSelected ) tabRect.adjust( -2, 0, 0, 0 ); if( isFirst ) { tabRect.adjust( 1, 0, 0, 0 ); if( isFrameAligned ) path.moveTo( tabRect.topLeft() - QPoint( 0, 2 ) ); else path.moveTo( tabRect.topLeft() ); path.lineTo( tabRect.bottomLeft() - QPointF( 0, radius ) ); path.quadTo( tabRect.bottomLeft(), tabRect.bottomLeft() + QPoint( radius, 0 ) ); path.lineTo( tabRect.bottomRight() ); path.lineTo( tabRect.topRight() ); } else if( isLast ) { tabRect.adjust( 0, 0, -2, 0 ); path.moveTo( tabRect.topLeft() ); path.lineTo( tabRect.bottomLeft() ); path.lineTo( tabRect.bottomRight() - QPointF( radius, 0 ) ); path.quadTo( tabRect.bottomRight(), tabRect.bottomRight() - QPointF( 0, radius ) ); if( isFrameAligned ) path.lineTo( tabRect.topRight() - QPointF( 0, 2 ) ); else path.lineTo( tabRect.topRight() ); } else { path.moveTo( tabRect.topLeft() ); path.lineTo( tabRect.bottomLeft() ); path.lineTo( tabRect.bottomRight() ); path.lineTo( tabRect.topRight() ); } // highlight QRect highlightRect( tabRect.left(), tabRect.top() - Metrics::TabBar_BaseOverlap + Metrics::TabBar_TabOffset, tabRect.width(), TileSet::DefaultSize ); if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( -2, 0, 0, 0 ), TileSet::BottomLeft ); else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, 0, 2, 0 ), TileSet::BottomRight ); else highlightSlab = SlabRect( highlightRect, TileSet::Bottom ); break; } case QTabBar::RoundedWest: case QTabBar::TriangularWest: { tabRect.adjust( 3, 0, -4, 1 ); // adjust sides when slab is adjacent to selected slab if( isLeftOfSelected ) tabRect.adjust( 0, 0, 0, 2 ); else if( isRightOfSelected ) tabRect.adjust( 0, -2, 0, 0 ); if( isFirst ) { tabRect.adjust( 0, 1, 0, 0 ); if( isFrameAligned ) path.moveTo( tabRect.topRight() + QPoint( 2, 0 ) ); else path.moveTo( tabRect.topRight() ); path.lineTo( tabRect.topLeft() + QPointF( radius, 0 ) ); path.quadTo( tabRect.topLeft(), tabRect.topLeft() + QPoint( 0, radius ) ); path.lineTo( tabRect.bottomLeft() ); path.lineTo( tabRect.bottomRight() ); } else if( isLast ) { tabRect.adjust( 0, 0, 0, -1 ); path.moveTo( tabRect.topRight() ); path.lineTo( tabRect.topLeft() ); path.lineTo( tabRect.bottomLeft() - QPointF( 0, radius ) ); path.quadTo( tabRect.bottomLeft(), tabRect.bottomLeft() + QPointF( radius, 0 ) ); path.lineTo( tabRect.bottomRight() ); } else { path.moveTo( tabRect.topRight() ); path.lineTo( tabRect.topLeft() ); path.lineTo( tabRect.bottomLeft() ); path.lineTo( tabRect.bottomRight() ); } // highlight QRect highlightRect( tabRect.right() - Metrics::TabBar_BaseOverlap + Metrics::TabBar_TabOffset, tabRect.top(), 1, tabRect.height() ); if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( 0, -2, 0, 0 ), TileSet::TopLeft ); else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, 0, 0, 2 ), TileSet::BottomLeft ); else highlightSlab = SlabRect( highlightRect, TileSet::Left ); break; } case QTabBar::RoundedEast: case QTabBar::TriangularEast: { tabRect.adjust( 4, 0, -3, 1 ); // adjust sides when slab is adjacent to selected slab if( isLeftOfSelected ) tabRect.adjust( 0, 0, 0, 2 ); else if( isRightOfSelected ) tabRect.adjust( 0, -2, 0, 0 ); if( isFirst ) { tabRect.adjust( 0, 1, 0, 0 ); if( isFrameAligned ) path.moveTo( tabRect.topLeft() - QPoint( 2, 0 ) ); else path.moveTo( tabRect.topLeft() ); path.lineTo( tabRect.topRight() - QPointF( radius, 0 ) ); path.quadTo( tabRect.topRight(), tabRect.topRight() + QPoint( 0, radius ) ); path.lineTo( tabRect.bottomRight() ); path.lineTo( tabRect.bottomLeft() ); } else if( isLast ) { tabRect.adjust( 0, 0, 0, -1 ); path.moveTo( tabRect.topLeft() ); path.lineTo( tabRect.topRight() ); path.lineTo( tabRect.bottomRight() - QPointF( 0, radius ) ); path.quadTo( tabRect.bottomRight(), tabRect.bottomRight() - QPointF( radius, 0 ) ); path.lineTo( tabRect.bottomLeft() ); } else { path.moveTo( tabRect.topLeft() ); path.lineTo( tabRect.topRight() ); path.lineTo( tabRect.bottomRight() ); path.lineTo( tabRect.bottomLeft() ); } // highlight QRect highlightRect( tabRect.left() - Metrics::TabBar_BaseOverlap + Metrics::TabBar_TabOffset, tabRect.top(), TileSet::DefaultSize, tabRect.height() ); if( isFrameAligned && isFirst ) highlightSlab = SlabRect( highlightRect.adjusted( 0, -2, 0, 0 ), TileSet::TopRight ); else if( isFrameAligned && isLast ) highlightSlab = SlabRect( highlightRect.adjusted( 0, 0, 0, 2 ), TileSet::BottomRight ); else highlightSlab = SlabRect( highlightRect, TileSet::Right ); break; } default: break; } const QColor color( palette.color( QPalette::Window ) ); // adjust clip rect and render tab if( tabBar ) { painter->save(); painter->setClipRegion( tabBarClipRegion( tabBar ) ); } // fill tab const QColor backgroundColor = _helper->backgroundColor( color, widget, rect.center() ); const QColor midColor = _helper->alphaColor( _helper->calcDarkColor( backgroundColor ), 0.4 ); const QColor darkColor = _helper->alphaColor( _helper->calcDarkColor( backgroundColor ), 0.6 ); painter->save(); painter->translate( 0.5, 0.5 ); painter->setRenderHints( QPainter::Antialiasing ); painter->setPen( darkColor ); painter->setBrush( midColor ); painter->drawPath( path ); painter->restore(); // restore clip region if( tabBar ) painter->restore(); // handle base frame painting, for tabbars in which tab is being dragged _tabBarData->drawTabBarBaseControl( tabOption, painter, widget ); // hovered highlight if( ( animated || mouseOver ) && highlightSlab.isValid() ) { highlightSlab.adjust( TileSet::DefaultSize ); const QRect tabWidgetRect( tabWidget ? tabWidget->rect().translated( -widget->geometry().topLeft() ) : QRect() ); adjustSlabRect( highlightSlab, tabWidgetRect, documentMode, verticalTabs ); const qreal opacity( _animations->tabBarEngine().opacity( widget, rect.topLeft(), AnimationHover ) ); const StyleOptions hoverTabOpts( NoFill | Hover ); // pass an invalid color to have only the glow painted if( animated ) renderSlab( painter, highlightSlab, QColor(), hoverTabOpts, opacity, AnimationHover ); else renderSlab( painter, highlightSlab, QColor(), hoverTabOpts ); } return true; } //___________________________________________________________________________________ bool Style::drawToolBoxTabLabelControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionToolBox* toolBoxOption( qstyleoption_cast( option ) ); if( !toolBoxOption ) return true; // copy palette const QPalette& palette( option->palette ); const State& state( option->state ); const bool enabled( state & State_Enabled ); // text alignment const int textFlags( _mnemonics->textFlags() | Qt::AlignCenter ); // contents rect const QRect rect( subElementRect( SE_ToolBoxTabContents, option, widget ) ); // store icon size const int iconSize( pixelMetric( QStyle::PM_SmallIconSize, option, widget ) ); // find contents size and rect QRect contentsRect( rect ); QSize contentsSize; if( !toolBoxOption->text.isEmpty() ) { contentsSize = option->fontMetrics.size( _mnemonics->textFlags(), toolBoxOption->text ); if( !toolBoxOption->icon.isNull() ) contentsSize.rwidth() += Metrics::ToolBox_TabItemSpacing; } // icon size if( !toolBoxOption->icon.isNull() ) { contentsSize.setHeight( qMax( contentsSize.height(), iconSize ) ); contentsSize.rwidth() += iconSize; } // adjust contents rect contentsRect = centerRect( contentsRect, contentsSize ); // render icon if( !toolBoxOption->icon.isNull() ) { // icon rect QRect iconRect; if( toolBoxOption->text.isEmpty() ) iconRect = centerRect( contentsRect, iconSize, iconSize ); else { iconRect = contentsRect; iconRect.setWidth( iconSize ); iconRect = centerRect( iconRect, iconSize, iconSize ); contentsRect.setLeft( iconRect.right() + Metrics::ToolBox_TabItemSpacing + 1 ); } iconRect = visualRect( option, iconRect ); const QIcon::Mode mode( enabled ? QIcon::Normal : QIcon::Disabled ); const QPixmap pixmap( toolBoxOption->icon.pixmap( iconSize, mode ) ); drawItemPixmap( painter, iconRect, textFlags, pixmap ); } // render text if( !toolBoxOption->text.isEmpty() ) { contentsRect = visualRect( option, contentsRect ); drawItemText( painter, contentsRect, textFlags, palette, enabled, toolBoxOption->text, QPalette::WindowText ); } return true; } //___________________________________________________________________________________ bool Style::drawToolBoxTabShapeControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // copy state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool selected( state & State_Selected ); const bool mouseOver( enabled && !selected && ( state & State_MouseOver ) ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // cast option and check const QStyleOptionToolBoxV2 *v2 = qstyleoption_cast( option ); if( v2 && v2->position == QStyleOptionToolBoxV2::Beginning && selected ) return true; /* the proper widget ( the toolbox tab ) is not passed as argument by Qt. What is passed is the toolbox directly. To implement animations properly, the painter->device() is used instead */ bool animated( false ); qreal opacity( AnimationData::OpacityInvalid ); if( enabled ) { // try retrieve button from painter device. if( QPaintDevice* device = painter->device() ) { _animations->toolBoxEngine().updateState( device, mouseOver ); animated = _animations->toolBoxEngine().isAnimated( device ); opacity = _animations->toolBoxEngine().opacity( device ); } } // save colors for shadow /* important: option returns a wrong color. We use the widget's palette when widget is set */ const QColor color( widget ? widget->palette().color( widget->backgroundRole() ) : palette.color( QPalette::Window ) ); const QColor dark( _helper->calcDarkColor( color ) ); QList colors; colors.append( _helper->calcLightColor( color ) ); if( mouseOver || animated ) { QColor highlight = _helper->hoverColor( palette ); if( animated ) { colors.append( KColorUtils::mix( dark, highlight, opacity ) ); colors.append( _helper->alphaColor( highlight, 0.2*opacity ) ); } else { colors.append( highlight ); colors.append( _helper->alphaColor( highlight, 0.2 ) ); } } else colors.append( dark ); // create path const qreal radius( 8 ); const qreal offset( radius * std::tan( M_PI/8 ) ); const QRectF rectf( rect ); QPainterPath path; if( reverseLayout ) { path.moveTo( rectf.right()-1, rectf.top() ); path.lineTo( rectf.left() + 50 + radius + offset, rectf.top() ); path.arcTo( QRectF( rectf.left() + 50 + radius + offset - 2*radius, rectf.top(), radius*2, radius*2 ), 90, 45 ); path.lineTo( rectf.left() + 50 - rectf.height() + 3 + offset/std::sqrt(2), rectf.bottom() - 3 - offset/std::sqrt(2) ); path.arcTo( QRectF( rectf.left() + 50 - rectf.height() + 3 + radius - offset - 2*radius, rectf.bottom() - 3 - 2*radius, 2*radius, 2*radius ), 315, -45 ); path.lineTo( rectf.left(), rectf.bottom() - 3 ); } else { path.moveTo( rectf.left(), rectf.top() ); path.lineTo( rectf.right()- 50 - radius - offset, rectf.top() ); path.arcTo( QRectF( rectf.right() - 50 - radius - offset, rectf.top(), radius*2, radius*2 ), 90, -45 ); path.lineTo( rectf.right() - 50 + rectf.height() - 3 - offset/std::sqrt(2), rectf.bottom() - 3 - offset/std::sqrt(2) ); path.arcTo( QRectF( rectf.right() - 50 + rectf.height() - 3 - radius + offset, rectf.bottom() - 3 - 2*radius, 2*radius, 2*radius ), 225, 45 ); path.lineTo( rectf.right() - 1, rectf.bottom() - 3 ); } // paint painter->setRenderHint( QPainter::Antialiasing, true ); painter->translate(0.5, 0.5 ); painter->translate( 0, 2 ); foreach( const QColor& color, colors ) { painter->setPen( color ); painter->drawPath( path ); painter->translate( 0,-1 ); } return true; } //___________________________________________________________________________________ bool Style::drawDockWidgetTitleControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionDockWidget* dockWidgetOption = qstyleoption_cast( option ); if( !dockWidgetOption ) return true; // copy palette const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool reverseLayout( option->direction == Qt::RightToLeft ); // cast to v2 to check vertical bar const QStyleOptionDockWidgetV2 *v2 = qstyleoption_cast( option ); const bool verticalTitleBar( v2 ? v2->verticalTitleBar : false ); const QRect buttonRect( subElementRect( dockWidgetOption->floatable ? SE_DockWidgetFloatButton : SE_DockWidgetCloseButton, option, widget ) ); // get rectangle and adjust to properly accounts for buttons QRect rect( insideMargin( dockWidgetOption->rect, Metrics::Frame_FrameWidth ) ); if( verticalTitleBar ) { if( buttonRect.isValid() ) rect.setTop( buttonRect.bottom()+1 ); } else if( reverseLayout ) { if( buttonRect.isValid() ) rect.setLeft( buttonRect.right()+1 ); rect.adjust( 0, 0, -4, 0 ); } else { if( buttonRect.isValid() ) rect.setRight( buttonRect.left()-1 ); rect.adjust( 4, 0, 0, 0 ); } QString title( dockWidgetOption->title ); int titleWidth = dockWidgetOption->fontMetrics.size( _mnemonics->textFlags(), title ).width(); int width = verticalTitleBar ? rect.height() : rect.width(); if( width < titleWidth ) title = dockWidgetOption->fontMetrics.elidedText( title, Qt::ElideRight, width, Qt::TextShowMnemonic ); if( verticalTitleBar ) { QSize s = rect.size(); s.transpose(); rect.setSize( s ); painter->save(); painter->translate( rect.left(), rect.top() + rect.width() ); painter->rotate( -90 ); painter->translate( - rect.left(), - rect.top() ); drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter | _mnemonics->textFlags(), palette, enabled, title, QPalette::WindowText ); painter->restore(); } else { drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter | _mnemonics->textFlags(), palette, enabled, title, QPalette::WindowText ); } return true; } //___________________________________________________________________________________ bool Style::drawToolBarControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // when timeLine is running draw border event if not hovered const bool toolBarAnimated( _animations->toolBarEngine().isFollowMouseAnimated( widget ) ); const QRect animatedRect( _animations->toolBarEngine().animatedRect( widget ) ); const bool toolBarIntersected( toolBarAnimated && animatedRect.intersects( rect ) ); if( toolBarIntersected ) { _helper->slitFocused( _helper->focusColor( palette ) ).render( animatedRect, painter ); } // draw nothing otherwise ( toolbars are transparent ) return true; } //______________________________________________________________ bool Style::drawToolButtonComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { // check autoRaise state const State& state( option->state ); const bool isInToolBar( widget && qobject_cast( widget->parent() ) ); // get rect and palette const QRect& rect( option->rect ); const QStyleOptionToolButton *toolButtonOption( qstyleoption_cast( option ) ); if( !toolButtonOption ) return true; const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( enabled && ( state & State_HasFocus ) ); const bool sunken( state & ( State_Sunken|State_On ) ); const bool autoRaise( state & State_AutoRaise ); if( isInToolBar ) { _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); } else { // mouseOver has precedence over focus _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus&&!mouseOver ); } // toolbar animation QWidget* parent( widget ? widget->parentWidget():0 ); const bool toolBarAnimated( isInToolBar && _animations->toolBarEngine().isAnimated( parent ) ); const QRect animatedRect( _animations->toolBarEngine().animatedRect( parent ) ); const QRect currentRect( _animations->toolBarEngine().currentRect( parent ) ); const bool current( isInToolBar && currentRect.intersects( rect.translated( widget->mapToParent( QPoint( 0,0 ) ) ) ) ); const bool toolBarTimerActive( isInToolBar && _animations->toolBarEngine().isTimerActive( widget->parentWidget() ) ); // normal toolbutton animation const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); // detect buttons in tabbar, for which special rendering is needed const bool inTabBar( widget && qobject_cast( widget->parentWidget() ) ); // local copy of option QStyleOptionToolButton copy( *toolButtonOption ); const bool hasPopupMenu( toolButtonOption->features & QStyleOptionToolButton::MenuButtonPopup ); const bool hasInlineIndicator( toolButtonOption->features&QStyleOptionToolButton::HasMenu && toolButtonOption->features&QStyleOptionToolButton::PopupDelay && !hasPopupMenu ); const QRect buttonRect( subControlRect( CC_ToolButton, option, SC_ToolButton, widget ) ); const QRect menuRect( subControlRect( CC_ToolButton, option, SC_ToolButtonMenu, widget ) ); // frame const bool drawFrame( (enabled && !( mouseOver || hasFocus || sunken ) && ((mode != AnimationNone) || ( ( ( toolBarAnimated && animatedRect.isNull() )||toolBarTimerActive ) && current )) ) || (toolButtonOption->subControls & SC_ToolButton) ); if( drawFrame ) { copy.rect = buttonRect; if( inTabBar ) drawTabBarPanelButtonToolPrimitive( ©, painter, widget ); else drawPrimitive( PE_PanelButtonTool, ©, painter, widget); } if( hasPopupMenu ) { copy.rect = menuRect; if( !autoRaise ) { drawPrimitive( PE_IndicatorButtonDropDown, ©, painter, widget ); copy.state &= ~(State_MouseOver|State_HasFocus); } drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget ); } else if( hasInlineIndicator ) { copy.rect = menuRect; copy.state &= ~(State_MouseOver|State_HasFocus); drawPrimitive( PE_IndicatorArrowDown, ©, painter, widget ); } // contents { // restore state copy.state = state; // define contents rect QRect contentsRect( buttonRect ); // detect dock widget title button /* for dockwidget title buttons, do not take out margins, so that icon do not get scaled down */ const bool isDockWidgetTitleButton( widget && widget->inherits( "QDockWidgetTitleButton" ) ); if( isDockWidgetTitleButton ) { // cast to abstract button // adjust state to have correct icon rendered const QAbstractButton* button( qobject_cast( widget ) ); if( button->isChecked() || button->isDown() ) copy.state |= State_On; } else if( !inTabBar && hasInlineIndicator ) { const int marginWidth( autoRaise ? Metrics::ToolButton_MarginWidth : Metrics::Button_MarginWidth + Metrics::Frame_FrameWidth ); contentsRect = insideMargin( contentsRect, marginWidth, 0 ); contentsRect.setRight( contentsRect.right() - Metrics::ToolButton_InlineIndicatorWidth ); contentsRect = visualRect( option, contentsRect ); } copy.rect = contentsRect; // render drawControl( CE_ToolButtonLabel, ©, painter, widget); } return true; } //______________________________________________________________ bool Style::drawComboBoxComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionComboBox* comboBoxOption( qstyleoption_cast( option ) ); if( !comboBoxOption ) return true; // rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( enabled && ( state & State_HasFocus ) ); const bool editable( comboBoxOption->editable ); const bool sunken( state & (State_On|State_Sunken) ); bool flat( !comboBoxOption->frame ); // style options StyleOptions styleOptions; if( mouseOver ) styleOptions |= Hover; if( hasFocus ) styleOptions |= Focus; if( sunken && !editable ) styleOptions |= Sunken; // frame if( comboBoxOption->subControls & SC_ComboBoxFrame ) { if( editable ) { // editable combobox. Make it look like a LineEdit // focus takes precedence over hover _animations->inputWidgetEngine().updateState( widget, AnimationFocus, hasFocus ); _animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver && !hasFocus ); // input area painter->setRenderHint( QPainter::Antialiasing ); flat |= ( rect.height() <= 2*Metrics::Frame_FrameWidth + Metrics::MenuButton_IndicatorWidth ); if( flat ) { const QColor background( palette.color( QPalette::Base ) ); painter->setPen( Qt::NoPen ); painter->setBrush( background ); painter->drawRect( rect ); } else { drawPrimitive( PE_FrameLineEdit, option, painter, widget ); } } else { // non editable combobox. Make it look like a PushButton // hover takes precedence over focus _animations->inputWidgetEngine().updateState( widget, AnimationHover, mouseOver ); _animations->inputWidgetEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver ); const AnimationMode mode( _animations->inputWidgetEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->inputWidgetEngine().buttonOpacity( widget ) ); // blend button color to the background const QColor buttonColor( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) ); const QRect slabRect( rect ); if( flat ) { if( !sunken ) { // hover rect const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) ); if( glow.isValid() ) _helper->slitFocused( glow ).render( rect, painter ); } else { styleOptions |= HoleContrast; _helper->renderHole( painter, palette.color( QPalette::Window ), rect, styleOptions, opacity, mode ); } } else { renderButtonSlab( painter, slabRect, buttonColor, styleOptions, opacity, mode, TileSet::Ring ); } } } if( comboBoxOption->subControls & SC_ComboBoxArrow ) { const QComboBox* comboBox = qobject_cast( widget ); const bool empty( comboBox && !comboBox->count() ); QColor color; QColor background; bool drawContrast( true ); if( comboBoxOption->editable ) { if( enabled && empty ) color = palette.color( QPalette::Disabled, QPalette::Text ); else { // check animation state const bool subControlHover( enabled && mouseOver && comboBoxOption->activeSubControls&SC_ComboBoxArrow ); _animations->comboBoxEngine().updateState( widget, AnimationHover, subControlHover ); const bool animated( enabled && _animations->comboBoxEngine().isAnimated( widget, AnimationHover ) ); const qreal opacity( _animations->comboBoxEngine().opacity( widget, AnimationHover ) ); if( animated ) { QColor highlight = _helper->hoverColor( palette ); color = KColorUtils::mix( palette.color( QPalette::Text ), highlight, opacity ); } else if( subControlHover ) { color = _helper->hoverColor( palette ); } else { color = palette.color( QPalette::Text ); } } background = palette.color( QPalette::Window ); if( enabled ) drawContrast = false; } else { // foreground color const QPalette::ColorRole role( flat ? QPalette::WindowText : QPalette::ButtonText ); if( enabled && empty ) color = palette.color( QPalette::Disabled, role ); else color = palette.color( role ); // background color background = palette.color( flat ? QPalette::Window : QPalette::Button ); } // draw the arrow QRect arrowRect = subControlRect( CC_ComboBox, option, SC_ComboBoxArrow, widget ); const QPolygonF arrow( genericArrow( ArrowDown, ArrowNormal ) ); const qreal penThickness = 1.6; painter->save(); painter->translate( QRectF( arrowRect ).center() ); painter->setRenderHint( QPainter::Antialiasing ); if( drawContrast ) { const qreal offset( qMin( penThickness, qreal( 1 ) ) ); painter->translate( 0,offset ); painter->setPen( QPen( _helper->calcLightColor( palette.color( QPalette::Window ) ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->translate( 0,-offset ); } painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->restore(); } return true; } //______________________________________________________________ bool Style::drawSpinBoxComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionSpinBox *spinBoxOption = qstyleoption_cast( option ); if( !spinBoxOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); if( spinBoxOption->subControls & SC_SpinBoxFrame ) { // detect flat spinboxes bool flat( !spinBoxOption->frame ); flat |= ( rect.height() <= 2*Metrics::Frame_FrameWidth + Metrics::MenuButton_IndicatorWidth ); if( flat ) { const QColor background( palette.color( QPalette::Base ) ); painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( Qt::NoPen ); painter->setBrush( background ); painter->drawRect( rect ); } else { drawPrimitive( PE_FrameLineEdit, option, painter, widget ); } } if( spinBoxOption->subControls & SC_SpinBoxUp ) renderSpinBoxArrow( painter, spinBoxOption, widget, SC_SpinBoxUp ); if( spinBoxOption->subControls & SC_SpinBoxDown ) renderSpinBoxArrow( painter, spinBoxOption, widget, SC_SpinBoxDown ); return true; } //______________________________________________________________ bool Style::drawSliderComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { // cast option and check const QStyleOptionSlider *sliderOption( qstyleoption_cast( option ) ); if( !sliderOption ) return true; // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // copy state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( state & State_HasFocus ); // direction const bool horizontal( sliderOption->orientation == Qt::Horizontal ); if( sliderOption->subControls & SC_SliderTickmarks ) { const bool upsideDown( sliderOption->upsideDown ); const int tickPosition( sliderOption->tickPosition ); const int available( pixelMetric( PM_SliderSpaceAvailable, option, widget ) ); int interval = sliderOption->tickInterval; if( interval < 1 ) interval = sliderOption->pageStep; if( interval >= 1 ) { const int fudge( pixelMetric( PM_SliderLength, option, widget ) / 2 ); int current( sliderOption->minimum ); // store tick lines const QRect grooveRect( subControlRect( CC_Slider, sliderOption, SC_SliderGroove, widget ) ); QList tickLines; if( horizontal ) { if( tickPosition & QSlider::TicksAbove ) tickLines.append( QLine( rect.left(), grooveRect.top() - Metrics::Slider_TickMarginWidth, rect.left(), grooveRect.top() - Metrics::Slider_TickMarginWidth - Metrics::Slider_TickLength ) ); if( tickPosition & QSlider::TicksBelow ) tickLines.append( QLine( rect.left(), grooveRect.bottom() + Metrics::Slider_TickMarginWidth, rect.left(), grooveRect.bottom() + Metrics::Slider_TickMarginWidth + Metrics::Slider_TickLength ) ); } else { if( tickPosition & QSlider::TicksAbove ) tickLines.append( QLine( grooveRect.left() - Metrics::Slider_TickMarginWidth, rect.top(), grooveRect.left() - Metrics::Slider_TickMarginWidth - Metrics::Slider_TickLength, rect.top() ) ); if( tickPosition & QSlider::TicksBelow ) tickLines.append( QLine( grooveRect.right() + Metrics::Slider_TickMarginWidth, rect.top(), grooveRect.right() + Metrics::Slider_TickMarginWidth + Metrics::Slider_TickLength, rect.top() ) ); } // colors QColor base( _helper->backgroundColor( palette.color( QPalette::Window ), widget, rect.center() ) ); base = _helper->calcDarkColor( base ); painter->setPen( base ); while( current <= sliderOption->maximum ) { // calculate positions and draw lines int position( sliderPositionFromValue( sliderOption->minimum, sliderOption->maximum, current, available ) + fudge ); foreach( const QLine& tickLine, tickLines ) { if( horizontal ) painter->drawLine( tickLine.translated( upsideDown ? (rect.width() - position) : position, 0 ) ); else painter->drawLine( tickLine.translated( 0, upsideDown ? (rect.height() - position):position ) ); } // go to next position current += interval; } } } // groove if( sliderOption->subControls & SC_SliderGroove ) { // get rect QRect grooveRect( subControlRect( CC_Slider, sliderOption, SC_SliderGroove, widget ) ); // render _helper->scrollHole( palette.color( QPalette::Window ), sliderOption->orientation, true ).render( grooveRect, painter, TileSet::Full ); } // handle if( sliderOption->subControls & SC_SliderHandle ) { // get rect and center QRect handleRect( subControlRect( CC_Slider, sliderOption, SC_SliderHandle, widget ) ); // handle state const bool handleActive( sliderOption->activeSubControls & SC_SliderHandle ); const bool sunken( state & (State_On|State_Sunken) ); StyleOptions styleOptions; if( hasFocus ) styleOptions |= Focus; if( handleActive && mouseOver ) styleOptions |= Hover; // animation state _animations->widgetStateEngine().updateState( widget, AnimationHover, handleActive && mouseOver ); _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus ); const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); // define colors const QColor color( _helper->backgroundColor( palette.color( QPalette::Button ), widget, handleRect.center() ) ); const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) ); // render painter->drawPixmap( handleRect.topLeft(), _helper->sliderSlab( color, glow, sunken, 0 ) ); } return true; } //______________________________________________________________ bool Style::drawDialComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { const State& state( option->state ); const bool enabled = state & State_Enabled; const bool mouseOver( enabled && ( state & State_MouseOver ) ); const bool hasFocus( enabled && ( state & State_HasFocus ) ); const bool sunken( state & ( State_On|State_Sunken ) ); StyleOptions styleOptions; if( sunken ) styleOptions |= Sunken; if( hasFocus ) styleOptions |= Focus; if( mouseOver ) styleOptions |= Hover; // mouseOver has precedence over focus _animations->widgetStateEngine().updateState( widget, AnimationHover, mouseOver ); _animations->widgetStateEngine().updateState( widget, AnimationFocus, hasFocus && !mouseOver ); const AnimationMode mode( _animations->widgetStateEngine().buttonAnimationMode( widget ) ); const qreal opacity( _animations->widgetStateEngine().buttonOpacity( widget ) ); const QRect rect( option->rect ); const QPalette &palette( option->palette ); const QColor buttonColor( _helper->backgroundColor( palette.color( QPalette::Button ), widget, rect.center() ) ); renderDialSlab( painter, rect, buttonColor, option, styleOptions, opacity, mode ); return true; } //______________________________________________________________ bool Style::drawScrollBarComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { // render full groove directly, rather than using the addPage and subPage control element methods if( option->subControls & SC_ScrollBarGroove ) { // retrieve groove rectangle QRect grooveRect( subControlRect( CC_ScrollBar, option, SC_ScrollBarGroove, widget ) ); const QPalette& palette( option->palette ); const QColor color( palette.color( QPalette::Window ) ); const State& state( option->state ); const bool horizontal( state & State_Horizontal ); if( horizontal ) grooveRect = centerRect( grooveRect, grooveRect.width(), StyleConfigData::scrollBarWidth() ); else grooveRect = centerRect( grooveRect, StyleConfigData::scrollBarWidth(), grooveRect.height() ); // render renderScrollBarHole( painter, grooveRect, color, Qt::Horizontal ); } // call base class primitive ParentStyleClass::drawComplexControl( CC_ScrollBar, option, painter, widget ); return true; } //______________________________________________________________ bool Style::drawTitleBarComplexControl( const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget ) const { const QStyleOptionTitleBar *titleBarOption( qstyleoption_cast( option ) ); if( !titleBarOption ) return true; const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool active( enabled && ( titleBarOption->titleBarState & Qt::WindowActive ) ); // draw title text { QRect textRect = subControlRect( CC_TitleBar, titleBarOption, SC_TitleBarLabel, widget ); // enable state transition - _animations->widgetEnabilityEngine().updateState( widget, AnimationEnable, active ); + _animations->widgetEnableStateEngine().updateState( widget, AnimationEnable, active ); // make sure palette has the correct color group QPalette palette( option->palette ); - if( _animations->widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) ) - { palette = _helper->disabledPalette( palette, _animations->widgetEnabilityEngine().opacity( widget, AnimationEnable ) ); } + if( _animations->widgetEnableStateEngine().isAnimated( widget, AnimationEnable ) ) + { palette = _helper->disabledPalette( palette, _animations->widgetEnableStateEngine().opacity( widget, AnimationEnable ) ); } palette.setCurrentColorGroup( active ? QPalette::Active: QPalette::Disabled ); ParentStyleClass::drawItemText( painter, textRect, Qt::AlignCenter, palette, active, titleBarOption->text, QPalette::WindowText ); } // menu button if( ( titleBarOption->subControls & SC_TitleBarSysMenu ) && ( titleBarOption->titleBarFlags & Qt::WindowSystemMenuHint ) && !titleBarOption->icon.isNull() ) { QRect iconRect = subControlRect( CC_TitleBar, titleBarOption, SC_TitleBarSysMenu, widget ); const int iconWidth( pixelMetric( PM_SmallIconSize, option, widget ) ); const QSize iconSize( iconWidth, iconWidth ); iconRect = centerRect( iconRect, iconSize ); const QPixmap pixmap = titleBarOption->icon.pixmap( iconSize, QIcon::Normal, QIcon::On ); painter->drawPixmap( iconRect, pixmap ); } if( ( titleBarOption->subControls & SC_TitleBarMinButton ) && ( titleBarOption->titleBarFlags & Qt::WindowMinimizeButtonHint ) ) { renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarMinButton ); } if( ( titleBarOption->subControls & SC_TitleBarMaxButton ) && ( titleBarOption->titleBarFlags & Qt::WindowMaximizeButtonHint ) ) { renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarMaxButton ); } if( ( titleBarOption->subControls & SC_TitleBarCloseButton ) ) { renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarCloseButton ); } if( ( titleBarOption->subControls & SC_TitleBarNormalButton ) && ( ( ( titleBarOption->titleBarFlags & Qt::WindowMinimizeButtonHint ) && ( titleBarOption->titleBarState & Qt::WindowMinimized ) ) || ( ( titleBarOption->titleBarFlags & Qt::WindowMaximizeButtonHint ) && ( titleBarOption->titleBarState & Qt::WindowMaximized ) ) ) ) { renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarNormalButton ); } if( titleBarOption->subControls & SC_TitleBarShadeButton ) { renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarShadeButton ); } if( titleBarOption->subControls & SC_TitleBarUnshadeButton ) { renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarUnshadeButton ); } if( ( titleBarOption->subControls & SC_TitleBarContextHelpButton ) && ( titleBarOption->titleBarFlags & Qt::WindowContextHelpButtonHint ) ) { renderTitleBarButton( painter, titleBarOption, widget, SC_TitleBarContextHelpButton ); } return true; } //_________________________________________________________________________________ void Style::renderDialSlab( QPainter *painter, const QRect& constRect, const QColor &color, const QStyleOption *option, StyleOptions styleOptions, qreal opacity, AnimationMode mode ) const { // cast option and check const QStyleOptionSlider* sliderOption( qstyleoption_cast( option ) ); if( !sliderOption ) return; // copy palette const QPalette& palette( option->palette ); // adjust rect to be square, and centered const int dimension( qMin( constRect.width(), constRect.height() ) ); const QRect rect( centerRect( constRect, dimension, dimension ) ); // calculate glow color const QColor glow( _helper->buttonGlowColor( palette, styleOptions, opacity, mode ) ); // get main slab QPixmap pixmap( _helper->dialSlab( color, glow, 0, dimension ) ); { const QColor light( _helper->calcLightColor( color ) ); const QColor shadow( _helper->calcShadowColor( color ) ); QPainter painter( &pixmap ); painter.setPen( Qt::NoPen ); painter.setRenderHints( QPainter::Antialiasing ); // indicator const qreal angle( dialAngle( sliderOption, sliderOption->sliderPosition ) ); QPointF center( pixmap.rect().center()/_helper->devicePixelRatio( pixmap ) ); const int sliderWidth( dimension/6 ); const qreal radius( 0.5*( dimension - 2*sliderWidth ) ); center += QPointF( radius*cos( angle ), -radius*sin( angle ) ); QRectF sliderRect( 0, 0, sliderWidth, sliderWidth ); sliderRect.moveCenter( center ); // outline circle const qreal offset( 0.3 ); painter.setBrush( light ); painter.setPen( Qt::NoPen ); painter.drawEllipse( sliderRect.translated( 0, offset ) ); // mask painter.setPen( Qt::NoPen ); painter.save(); painter.setCompositionMode( QPainter::CompositionMode_DestinationOut ); painter.setBrush( QBrush( Qt::black ) ); painter.drawEllipse( sliderRect ); painter.restore(); // shadow painter.translate( sliderRect.topLeft() ); _helper->drawInverseShadow( painter, shadow.darker( 200 ), 0, sliderRect.width(), 0 ); // glow if( glow.isValid() ) _helper->drawInverseGlow( painter, glow, 0, sliderRect.width(), sliderRect.width() ); painter.end(); } painter->drawPixmap( rect.topLeft(), pixmap ); return; } //____________________________________________________________________________________ void Style::renderButtonSlab( QPainter *painter, QRect rect, const QColor &color, StyleOptions options, qreal opacity, AnimationMode mode, TileSet::Tiles tiles ) const { // check rect if( !rect.isValid() ) return; // edges // for slabs, hover takes precedence over focus ( other way around for holes ) // but in any case if the button is sunken we don't show focus nor hover TileSet tileSet; if( options & Sunken ) { tileSet = _helper->slabSunken( color ); } else { QColor glow = _helper->buttonGlowColor( QPalette::Active, options, opacity, mode ); tileSet = _helper->slab( color, glow, 0 ); } // adjust rect to account for missing tiles if( tileSet.isValid() ) rect = tileSet.adjust( rect, tiles ); // fill if( !( options & NoFill ) ) _helper->fillButtonSlab( *painter, rect, color, options&Sunken ); // render slab if( tileSet.isValid() ) tileSet.render( rect, painter, tiles ); } //____________________________________________________________________________________ void Style::renderSlab( QPainter *painter, QRect rect, const QColor &color, StyleOptions options, qreal opacity, AnimationMode mode, TileSet::Tiles tiles ) const { // check rect if( !rect.isValid() ) return; // fill if( !( options & NoFill ) ) { painter->save(); painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( Qt::NoPen ); if( _helper->calcShadowColor( color ).value() > color.value() && ( options & Sunken ) ) { QLinearGradient innerGradient( 0, rect.top(), 0, rect.bottom() + rect.height() ); innerGradient.setColorAt( 0, color ); innerGradient.setColorAt( 1, _helper->calcLightColor( color ) ); painter->setBrush( innerGradient ); } else { QLinearGradient innerGradient( 0, rect.top() - rect.height(), 0, rect.bottom() ); innerGradient.setColorAt( 0, _helper->calcLightColor( color ) ); innerGradient.setColorAt( 1, color ); painter->setBrush( innerGradient ); } _helper->fillSlab( *painter, rect ); painter->restore(); } // edges // for slabs, hover takes precedence over focus ( other way around for holes ) // but in any case if the button is sunken we don't show focus nor hover TileSet tileSet; if( ( options & Sunken ) && color.isValid() ) { tileSet = _helper->slabSunken( color ); } else { // calculate proper glow color based on current settings and opacity const QColor glow( _helper->buttonGlowColor( QPalette::Active, options, opacity, mode ) ); if( color.isValid() || glow.isValid() ) tileSet = _helper->slab( color, glow , 0 ); else return; } // render tileset if( tileSet.isValid() ) tileSet.render( rect, painter, tiles ); } //______________________________________________________________________________________________________________________________ void Style::fillTabBackground( QPainter* painter, const QRect& rect, const QColor &color, const QWidget* widget ) const { // filling const QRect fillRect( insideMargin( rect, Metrics::TabBar_TabOffset ) ); if( widget ) _helper->renderWindowBackground( painter, fillRect, widget, color ); else painter->fillRect( fillRect, color ); } //______________________________________________________________________________________________________________________________ void Style::fillTab( QPainter* painter, const QRect &rect, const QColor &color, QTabBar::Shape shape ) const { const QColor dark( _helper->calcDarkColor( color ) ); const QColor shadow( _helper->calcShadowColor( color ) ); const QColor light( _helper->calcLightColor( color ) ); const QRect fillRect( insideMargin( rect, Metrics::TabBar_TabOffset ) ); QLinearGradient gradient; switch( shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: gradient = QLinearGradient( fillRect.topLeft(), fillRect.bottomLeft() ); break; case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: gradient = QLinearGradient( fillRect.bottomLeft(), fillRect.topLeft() ); break; case QTabBar::RoundedEast: case QTabBar::TriangularEast: gradient = QLinearGradient( fillRect.topRight(), fillRect.topLeft() ); break; case QTabBar::RoundedWest: case QTabBar::TriangularWest: gradient = QLinearGradient( fillRect.topLeft(), fillRect.topRight() ); break; default: return; } gradient.setColorAt( 0, _helper->alphaColor( light, 0.5 ) ); gradient.setColorAt( 0.1, _helper->alphaColor( light, 0.5 ) ); gradient.setColorAt( 0.25, _helper->alphaColor( light, 0.3 ) ); gradient.setColorAt( 0.5, _helper->alphaColor( light, 0.2 ) ); gradient.setColorAt( 0.75, _helper->alphaColor( light, 0.1 ) ); gradient.setColorAt( 0.9, Qt::transparent ); painter->setRenderHints( QPainter::Antialiasing ); painter->setPen( Qt::NoPen ); painter->setBrush( gradient ); painter->drawRoundedRect( fillRect, 2, 2 ); } //____________________________________________________________________________________________________ void Style::renderSpinBoxArrow( QPainter* painter, const QStyleOptionSpinBox* option, const QWidget* widget, const SubControl& subControl ) const { const QPalette& palette( option->palette ); const State& state( option->state ); // enable state bool enabled( state & State_Enabled ); // check steps enable step const bool atLimit( (subControl == SC_SpinBoxUp && !(option->stepEnabled & QAbstractSpinBox::StepUpEnabled )) || (subControl == SC_SpinBoxDown && !(option->stepEnabled & QAbstractSpinBox::StepDownEnabled ) ) ); // update enabled state accordingly enabled &= !atLimit; // update mouse-over effect const bool mouseOver( enabled && ( state & State_MouseOver ) ); // check animation state const bool subControlHover( enabled && mouseOver && ( option->activeSubControls & subControl ) ); _animations->spinBoxEngine().updateState( widget, subControl, subControlHover ); const bool animated( enabled && _animations->spinBoxEngine().isAnimated( widget, subControl ) ); const qreal opacity( _animations->spinBoxEngine().opacity( widget, subControl ) ); QColor color; if( animated ) { QColor highlight = _helper->hoverColor( palette ); color = KColorUtils::mix( palette.color( QPalette::Text ), highlight, opacity ); } else if( subControlHover ) { color = _helper->hoverColor( palette ); } else if( atLimit ) { color = palette.color( QPalette::Disabled, QPalette::Text ); } else { color = palette.color( QPalette::Text ); } const qreal penThickness = 1.6; const QColor background = palette.color( QPalette::Window ); const QPolygonF arrow( genericArrow( ( subControl == SC_SpinBoxUp ) ? ArrowUp:ArrowDown, ArrowNormal ) ); const QRect arrowRect( subControlRect( CC_SpinBox, option, subControl, widget ) ); painter->save(); painter->translate( QRectF( arrowRect ).center() ); painter->setRenderHint( QPainter::Antialiasing ); painter->setPen( QPen( _helper->decoColor( background, color ) , penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->restore(); return; } //___________________________________________________________________________________ void Style::renderSplitter( const QStyleOption* option, QPainter* painter, const QWidget* widget, bool horizontal ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool mouseOver( enabled && ( state & ( State_MouseOver|State_Sunken ) ) ); // get orientation const Qt::Orientation orientation( horizontal ? Qt::Horizontal : Qt::Vertical ); bool animated( false ); qreal opacity( AnimationData::OpacityInvalid ); if( enabled ) { if( qobject_cast( widget ) ) { _animations->dockSeparatorEngine().updateRect( widget, rect, orientation, mouseOver ); animated = _animations->dockSeparatorEngine().isAnimated( widget, rect, orientation ); opacity = animated ? _animations->dockSeparatorEngine().opacity( widget, orientation ) : AnimationData::OpacityInvalid; } else if( QPaintDevice* device = painter->device() ) { /* try update QSplitterHandle using painter device, because Qt passes QSplitter as the widget to the QStyle primitive. */ _animations->splitterEngine().updateState( device, mouseOver ); animated = _animations->splitterEngine().isAnimated( device ); opacity = _animations->splitterEngine().opacity( device ); } } // get base color const QColor color = palette.color( QPalette::Window ); if( horizontal ) { const int hCenter = rect.center().x(); const int h = rect.height(); if( animated || mouseOver ) { const QColor highlight = _helper->alphaColor( _helper->calcLightColor( color ),0.5*( animated ? opacity:1 ) ); const qreal fraction( rect.height() > 30 ? 10/rect.height():0.1 ); QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() ); gradient.setColorAt( 0, Qt::transparent ); gradient.setColorAt( fraction, highlight ); gradient.setColorAt( 1-fraction, highlight ); gradient.setColorAt( 1, Qt::transparent ); painter->fillRect( rect, gradient ); } const int ngroups( qMax( 1,h / 250 ) ); int center( ( h - ( ngroups-1 ) * 250 ) /2 + rect.top() ); for( int k = 0; k < ngroups; k++, center += 250 ) { _helper->renderDot( painter, QPoint( hCenter, center-3 ), color ); _helper->renderDot( painter, QPoint( hCenter, center ), color ); _helper->renderDot( painter, QPoint( hCenter, center+3 ), color ); } } else { const int vCenter( rect.center().y() ); const int w( rect.width() ); if( animated || mouseOver ) { const QColor highlight( _helper->alphaColor( _helper->calcLightColor( color ),0.5*( animated ? opacity:1 ) ) ); const qreal fraction( rect.width() > 30 ? 10 / rect.width():0.1 ); QLinearGradient gradient( rect.topLeft(), rect.topRight() ); gradient.setColorAt( 0, Qt::transparent ); gradient.setColorAt( fraction, highlight ); gradient.setColorAt( 1 - fraction, highlight ); gradient.setColorAt( 1, Qt::transparent ); painter->fillRect( rect, gradient ); } const int ngroups( qMax( 1, w / 250 ) ); int center = ( w - ( ngroups-1 ) * 250 ) /2 + rect.left(); for( int k = 0; k < ngroups; k++, center += 250 ) { _helper->renderDot( painter, QPoint( center-3, vCenter ), color ); _helper->renderDot( painter, QPoint( center, vCenter ), color ); _helper->renderDot( painter, QPoint( center+3, vCenter ), color ); } } } //____________________________________________________________________________________________________ void Style::renderTitleBarButton( QPainter* painter, const QStyleOptionTitleBar* option, const QWidget* widget, const SubControl& subControl ) const { // get relevant rect const QRect rect = subControlRect( CC_TitleBar, option, subControl, widget ); if( !rect.isValid() ) return; // copy palette QPalette palette = option->palette; // store state const State& state( option->state ); const bool enabled( state & State_Enabled ); const bool active( enabled && ( option->titleBarState & Qt::WindowActive ) ); // enable state transition - _animations->widgetEnabilityEngine().updateState( widget, AnimationEnable, active ); - if( _animations->widgetEnabilityEngine().isAnimated( widget, AnimationEnable ) ) - { palette = _helper->disabledPalette( palette, _animations->widgetEnabilityEngine().opacity( widget, AnimationEnable ) ); } + _animations->widgetEnableStateEngine().updateState( widget, AnimationEnable, active ); + if( _animations->widgetEnableStateEngine().isAnimated( widget, AnimationEnable ) ) + { palette = _helper->disabledPalette( palette, _animations->widgetEnableStateEngine().opacity( widget, AnimationEnable ) ); } const bool sunken( state & State_Sunken ); const bool mouseOver( ( !sunken ) && widget && rect.translated( widget->mapToGlobal( QPoint( 0,0 ) ) ).contains( QCursor::pos() ) ); _animations->mdiWindowEngine().updateState( widget, subControl, enabled && mouseOver ); const bool animated( enabled && _animations->mdiWindowEngine().isAnimated( widget, subControl ) ); const qreal opacity( _animations->mdiWindowEngine().opacity( widget, subControl ) ); // contrast color const QColor base =option->palette.color( QPalette::Active, QPalette::Window ); // icon color QColor color; if( animated ) { const QColor base( palette.color( active ? QPalette::Active : QPalette::Disabled, QPalette::WindowText ) ); const QColor glow( subControl == SC_TitleBarCloseButton ? _helper->negativeTextColor( palette ): _helper->hoverColor( palette ) ); color = KColorUtils::mix( base, glow, opacity ); } else if( mouseOver ) { color = ( subControl == SC_TitleBarCloseButton ) ? _helper->negativeTextColor( palette ): _helper->hoverColor( palette ); } else { color = palette.color( active ? QPalette::Active : QPalette::Disabled, QPalette::WindowText ); } // rendering renderTitleBarButton( painter, rect, base, color, subControl ); } //____________________________________________________________________________________________________ void Style::renderTitleBarButton( QPainter* painter, const QRect& rect, const QColor& base, const QColor& color, const SubControl& subControl ) const { painter->save(); painter->setRenderHints( QPainter::Antialiasing ); painter->setBrush( Qt::NoBrush ); painter->drawPixmap( rect, _helper->dockWidgetButton( base, true, rect.width() ) ); const qreal width( 1.1 ); // contrast painter->translate( 0, 0.5 ); painter->setPen( QPen( _helper->calcLightColor( base ), width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); renderTitleBarIcon( painter, rect, subControl ); // main icon painting painter->translate( 0,-1 ); painter->setPen( QPen( color, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); renderTitleBarIcon( painter, rect, subControl ); painter->restore(); } //____________________________________________________________________________________ void Style::renderTitleBarIcon( QPainter *painter, const QRect& rect, const SubControl& subControl ) const { painter->save(); painter->translate( rect.topLeft() ); painter->scale( qreal( rect.width() )/16, qreal( rect.height() )/16 ); switch( subControl ) { case SC_TitleBarContextHelpButton: { painter->drawArc( 6, 4, 3, 3, 135*16, -180*16 ); painter->drawArc( 8, 7, 3, 3, 135*16, 45*16 ); painter->drawPoint( 8, 11 ); break; } case SC_TitleBarMinButton: { painter->drawPolyline( QPolygon() << QPoint( 5, 7 ) << QPoint( 8, 10 ) << QPoint( 11, 7 ) ); break; } case SC_TitleBarNormalButton: { painter->drawPolygon( QPolygon() << QPoint( 8, 5 ) << QPoint( 11, 8 ) << QPoint( 8, 11 ) << QPoint( 5, 8 ) ); break; } case SC_TitleBarMaxButton: { painter->drawPolyline( QPolygon() << QPoint( 5, 9 ) << QPoint( 8, 6 ) << QPoint( 11, 9 ) ); break; } case SC_TitleBarCloseButton: { painter->drawLine( QPointF( 5.5, 5.5 ), QPointF( 10.5, 10.5 ) ); painter->drawLine( QPointF( 10.5, 5.5 ), QPointF( 5.5, 10.5 ) ); break; } case SC_TitleBarShadeButton: { painter->drawLine( QPoint( 5, 11 ), QPoint( 11, 11 ) ); painter->drawPolyline( QPolygon() << QPoint( 5, 5 ) << QPoint( 8, 8 ) << QPoint( 11, 5 ) ); break; } case SC_TitleBarUnshadeButton: { painter->drawPolyline( QPolygon() << QPoint( 5, 8 ) << QPoint( 8, 5 ) << QPoint( 11, 8 ) ); painter->drawLine( QPoint( 5, 11 ), QPoint( 11, 11 ) ); break; } default: break; } painter->restore(); } //__________________________________________________________________________ void Style::renderHeaderBackground( const QRect& rect, const QPalette& palette, QPainter* painter, const QWidget* widget, bool horizontal, bool reverse ) const { // use window background for the background if( widget ) _helper->renderWindowBackground( painter, rect, widget, palette ); else painter->fillRect( rect, palette.color( QPalette::Window ) ); if( horizontal ) renderHeaderLines( rect, palette, painter, TileSet::Bottom ); else if( reverse ) renderHeaderLines( rect, palette, painter, TileSet::Left ); else renderHeaderLines( rect, palette, painter, TileSet::Right ); } //__________________________________________________________________________ void Style::renderHeaderLines( const QRect& constRect, const QPalette& palette, QPainter* painter, TileSet::Tiles tiles ) const { // add horizontal lines const QColor color( palette.color( QPalette::Window ) ); const QColor dark( _helper->calcDarkColor( color ) ); const QColor light( _helper->calcLightColor( color ) ); painter->save(); QRect rect( constRect ); if( tiles & TileSet::Bottom ) { painter->setPen( dark ); if( tiles & TileSet::Left ) painter->drawPoint( rect.bottomLeft() ); else if( tiles& TileSet::Right ) painter->drawPoint( rect.bottomRight() ); else painter->drawLine( rect.bottomLeft(), rect.bottomRight() ); rect.adjust( 0, 0, 0, -1 ); painter->setPen( light ); if( tiles & TileSet::Left ) { painter->drawLine( rect.bottomLeft(), rect.bottomLeft()+QPoint( 1, 0 ) ); painter->drawLine( rect.bottomLeft()+ QPoint( 1, 0 ), rect.bottomLeft()+QPoint( 1, 1 ) ); } else if( tiles & TileSet::Right ) { painter->drawLine( rect.bottomRight(), rect.bottomRight() - QPoint( 1, 0 ) ); painter->drawLine( rect.bottomRight() - QPoint( 1, 0 ), rect.bottomRight() - QPoint( 1, -1 ) ); } else { painter->drawLine( rect.bottomLeft(), rect.bottomRight() ); } } else if( tiles & TileSet::Left ) { painter->setPen( dark ); painter->drawLine( rect.topLeft(), rect.bottomLeft() ); rect.adjust( 1, 0, 0, 0 ); painter->setPen( light ); painter->drawLine( rect.topLeft(), rect.bottomLeft() ); } else if( tiles & TileSet::Right ) { painter->setPen( dark ); painter->drawLine( rect.topRight(), rect.bottomRight() ); rect.adjust( 0, 0, -1, 0 ); painter->setPen( light ); painter->drawLine( rect.topRight(), rect.bottomRight() ); } painter->restore(); return; } //__________________________________________________________________________ void Style::renderMenuItemBackground( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { const QRect& rect( option->rect ); const QPalette& palette( option->palette ); const QRect animatedRect( _animations->menuEngine().animatedRect( widget ) ); if( !animatedRect.isNull() ) { if( animatedRect.intersects( rect ) ) { const QColor color( _helper->menuBackgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, animatedRect.center() ) ); renderMenuItemRect( option, animatedRect, color, palette, painter ); } } else if( _animations->menuEngine().isTimerActive( widget ) ) { const QRect previousRect( _animations->menuEngine().currentRect( widget, Previous ) ); if( previousRect.intersects( rect ) ) { const QColor color( _helper->menuBackgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, previousRect.center() ) ); renderMenuItemRect( option, previousRect, color, palette, painter ); } } else if( _animations->menuEngine().isAnimated( widget, Previous ) ) { QRect previousRect( _animations->menuEngine().currentRect( widget, Previous ) ); if( previousRect.intersects( rect ) ) { const qreal opacity( _animations->menuEngine().opacity( widget, Previous ) ); const QColor color( _helper->menuBackgroundColor( _helper->calcMidColor( palette.color( QPalette::Window ) ), widget, previousRect.center() ) ); renderMenuItemRect( option, previousRect, color, palette, painter, opacity ); } } return; } //__________________________________________________________________________ void Style::renderMenuItemRect( const QStyleOption* option, const QRect& rect, const QColor& base, const QPalette& palette, QPainter* painter, qreal opacity ) const { if( opacity == 0 ) return; // get relevant color // TODO: this is inconsistent with MenuBar color. // this should change to properly account for 'sunken' state QColor color( base ); if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_STRONG ) { color = palette.color( QPalette::Highlight ); } else if( StyleConfigData::menuHighlightMode() == StyleConfigData::MM_SUBTLE ) { color = KColorUtils::mix( color, KColorUtils::tint( color, palette.color( QPalette::Highlight ), 0.6 ) ); } // special painting for items with submenus const QStyleOptionMenuItem* menuItemOption = qstyleoption_cast( option ); if( menuItemOption && menuItemOption->menuItemType == QStyleOptionMenuItem::SubMenu ) { QPixmap pixmap( rect.size() ); { pixmap.fill( Qt::transparent ); QPainter painter( &pixmap ); const QRect pixmapRect( pixmap.rect() ); painter.setRenderHint( QPainter::Antialiasing ); painter.setPen( Qt::NoPen ); painter.setBrush( color ); _helper->fillHole( painter, pixmapRect ); _helper->holeFlat( color, 0 ).render( pixmapRect.adjusted( 1, 2, -2, -1 ), &painter ); QRect maskRect( visualRect( option->direction, pixmapRect, QRect( pixmapRect.width()-40, 0, 40, pixmapRect.height() ) ) ); QLinearGradient gradient( visualPos( option->direction, maskRect, QPoint( maskRect.left(), 0 ) ), visualPos( option->direction, maskRect, QPoint( maskRect.right()-4, 0 ) ) ); gradient.setColorAt( 0, Qt::black ); gradient.setColorAt( 1, Qt::transparent ); painter.setBrush( gradient ); painter.setCompositionMode( QPainter::CompositionMode_DestinationIn ); painter.drawRect( maskRect ); if( opacity >= 0 && opacity < 1 ) { painter.setCompositionMode( QPainter::CompositionMode_DestinationIn ); painter.fillRect( pixmapRect, _helper->alphaColor( Qt::black, opacity ) ); } painter.end(); } painter->drawPixmap( visualRect( option, rect ), pixmap ); } else { if( opacity >= 0 && opacity < 1 ) { color.setAlphaF( opacity ); } _helper->holeFlat( color, 0 ).render( rect.adjusted( 1, 2, -2, -1 ), painter, TileSet::Full ); } } //________________________________________________________________________ void Style::renderCheckBox( QPainter *painter, const QRect &constRect, const QPalette &palette, StyleOptions options, CheckBoxState state, qreal opacity, AnimationMode mode ) const { const int size( qMin( constRect.width(), constRect.height() ) ); const QRect rect( centerRect( constRect, size, size ) ); if( !( options & NoFill ) ) { if( options & Sunken ) _helper->holeFlat( palette.color( QPalette::Window ), 0, false ).render( insideMargin( rect, 1 ), painter, TileSet::Full ); else renderSlab( painter, rect, palette.color( QPalette::Button ), options, opacity, mode, TileSet::Ring ); } if( state == CheckOff ) return; // check mark qreal penThickness( 2 ); const QColor color( palette.color( ( options&Sunken ) ? QPalette::WindowText:QPalette::ButtonText ) ); const QColor background( palette.color( ( options&Sunken ) ? QPalette::Window:QPalette::Button ) ); QPen pen( _helper->decoColor( background, color ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ); QPen contrastPen( _helper->calcLightColor( background ), penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ); if( state == CheckTriState ) { QVector dashes; dashes << 1 << 2; penThickness = 1.3; pen.setWidthF( penThickness ); contrastPen.setWidthF( penThickness ); pen.setDashPattern( dashes ); contrastPen.setDashPattern( dashes ); } else if( state == CheckSunken ) { pen.setColor( _helper->alphaColor( pen.color(), 0.3 ) ); contrastPen.setColor( _helper->alphaColor( contrastPen.color(), 0.3 ) ); } painter->save(); painter->translate( QRectF( rect ).center() ); if( !( options&Sunken ) ) painter->translate( 0, -1 ); painter->setRenderHint( QPainter::Antialiasing ); QPolygonF checkMark; checkMark << QPointF( 5, -2 ) << QPointF( -1, 5 ) << QPointF( -4, 2 ); const qreal offset( qMin( penThickness, qreal( 1 ) ) ); painter->setPen( contrastPen ); painter->translate( 0, offset ); painter->drawPolyline( checkMark ); painter->setPen( pen ); painter->translate( 0, -offset ); painter->drawPolyline( checkMark ); painter->restore(); return; } //___________________________________________________________________ void Style::renderRadioButton( QPainter* painter, const QRect& constRect, const QPalette& palette, StyleOptions options, CheckBoxState state, qreal opacity, AnimationMode mode ) const { // get pixmap const QColor color( palette.color( QPalette::Button ) ); const QColor glow( _helper->buttonGlowColor( palette, options, opacity, mode ) ); QPixmap pixmap( _helper->roundSlab( color, glow, 0 ) ); // center rect const QRect rect( centerRect( constRect, pixmap.size()/_helper->devicePixelRatio( pixmap ) ) ); // render painter->drawPixmap( rect.topLeft(), pixmap ); // draw the radio mark if( state != CheckOff ) { const qreal radius( 2.6 ); const qreal dx( 0.5*rect.width() - radius ); const qreal dy( 0.5*rect.height() - radius ); const QRectF symbolRect( QRectF( rect ).adjusted( dx, dy, -dx, -dy ) ); painter->save(); painter->setRenderHints( QPainter::Antialiasing ); painter->setPen( Qt::NoPen ); const QColor background( palette.color( QPalette::Button ) ); const QColor color( palette.color( QPalette::ButtonText ) ); // contrast if( state == CheckOn ) painter->setBrush( _helper->calcLightColor( background ) ); else painter->setBrush( _helper->alphaColor( _helper->calcLightColor( background ), 0.3 ) ); painter->translate( 0, radius/2 ); painter->drawEllipse( symbolRect ); // symbol if( state == CheckOn ) painter->setBrush( _helper->decoColor( background, color ) ); else painter->setBrush( _helper->alphaColor( _helper->decoColor( background, color ), 0.3 ) ); painter->translate( 0, -radius/2 ); painter->drawEllipse( symbolRect ); painter->restore(); } return; } //______________________________________________________________________________ void Style::renderScrollBarHole( QPainter *painter, const QRect &rect, const QColor &color, const Qt::Orientation& orientation, const TileSet::Tiles& tiles ) const { if( !rect.isValid() ) return; // one need to make smaller shadow // notably on the size when rect height is too high const bool smallShadow( orientation == Qt::Horizontal ? rect.height() < 10 : rect.width() < 10 ); _helper->scrollHole( color, orientation, smallShadow ).render( rect, painter, tiles ); } //______________________________________________________________________________ void Style::renderScrollBarHandle( QPainter* painter, const QRect& constRect, const QPalette& palette, const Qt::Orientation& orientation, const bool& hover, const qreal& opacity ) const { if( !constRect.isValid() ) return; // define rect and check QRect rect( insideMargin( constRect, 3 ) ); painter->save(); painter->setRenderHints( QPainter::Antialiasing ); const QColor color( palette.color( QPalette::Button ) ); // draw the slider const qreal radius = 3.5; // glow / shadow QColor glow; const QColor shadow( _helper->alphaColor( _helper->calcShadowColor( color ), 0.4 ) ); const QColor hovered( _helper->hoverColor( palette ) ); if( opacity >= 0 ) glow = KColorUtils::mix( shadow, hovered, opacity ); else if( hover ) glow = hovered; else glow = shadow; _helper->scrollHandle( color, glow ).render( constRect, painter, TileSet::Full ); // contents const QColor mid( _helper->calcMidColor( color ) ); QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() ); gradient.setColorAt(0, color ); gradient.setColorAt(1, mid ); painter->setPen( Qt::NoPen ); painter->setBrush( gradient ); painter->drawRoundedRect( insideMargin( rect, 1 ), radius - 2, radius - 2 ); // bevel pattern const QColor light( _helper->calcLightColor( color ) ); const bool horizontal( orientation == Qt::Horizontal ); QLinearGradient patternGradient( 0, 0, horizontal ? 30:0, horizontal? 0:30 ); patternGradient.setSpread( QGradient::ReflectSpread ); patternGradient.setColorAt( 0, Qt::transparent ); patternGradient.setColorAt( 1, _helper->alphaColor( light, 0.1 ) ); QRect bevelRect( rect ); if( horizontal ) bevelRect = insideMargin( bevelRect, 0, 3 ); else bevelRect = insideMargin( bevelRect, 3, 0 ); if( bevelRect.isValid() ) { painter->setBrush( patternGradient ); painter->drawRect( bevelRect ); } painter->restore(); return; } //______________________________________________________________________________ void Style::renderScrollBarArrow( QPainter* painter, const QRect& rect, const QColor& color, const QColor& background, ArrowOrientation orientation ) const { const qreal penThickness = 1.6; QPolygonF arrow( genericArrow( orientation, ArrowNormal ) ); const QColor contrast( _helper->calcLightColor( background ) ); const QColor base( _helper->decoColor( background, color ) ); painter->save(); painter->translate( QRectF(rect).center() ); painter->setRenderHint( QPainter::Antialiasing ); const qreal offset( qMin( penThickness, qreal( 1 ) ) ); painter->translate( 0,offset ); painter->setPen( QPen( contrast, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->translate( 0,-offset ); painter->setPen( QPen( base, penThickness, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) ); painter->drawPolyline( arrow ); painter->restore(); return; } //______________________________________________________________________________ QColor Style::scrollBarArrowColor( const QStyleOptionSlider* option, const SubControl& control, const QWidget* widget ) const { // copy rect and palette const QRect& rect( option->rect ); const QPalette& palette( option->palette ); // color QColor color( palette.color( QPalette::WindowText ) ); // check enabled state const bool enabled( option->state & State_Enabled ); if( !enabled ) return color; if( ( control == SC_ScrollBarSubLine && option->sliderValue == option->minimum ) || ( control == SC_ScrollBarAddLine && option->sliderValue == option->maximum ) ) { // manually disable arrow, to indicate that scrollbar is at limit return palette.color( QPalette::Disabled, QPalette::WindowText ); } const bool mouseOver( _animations->scrollBarEngine().isHovered( widget, control ) ); const bool animated( _animations->scrollBarEngine().isAnimated( widget, control ) ); const qreal opacity( _animations->scrollBarEngine().opacity( widget, control ) ); // retrieve mouse position from engine QPoint position( mouseOver ? _animations->scrollBarEngine().position( widget ) : QPoint( -1, -1 ) ); if( mouseOver && rect.contains( position ) ) { // need to update the arrow controlRect on fly because there is no // way to get it from the styles directly, outside of repaint events _animations->scrollBarEngine().setSubControlRect( widget, control, rect ); } if( rect.intersects( _animations->scrollBarEngine().subControlRect( widget, control ) ) ) { QColor highlight = _helper->hoverColor( palette ); if( animated ) { color = KColorUtils::mix( color, highlight, opacity ); } else if( mouseOver ) { color = highlight; } } return color; } //______________________________________________________________________________ qreal Style::dialAngle( const QStyleOptionSlider* sliderOption, int value ) const { // calculate angle at which handle needs to be drawn qreal angle( 0 ); if( sliderOption->maximum == sliderOption->minimum ) angle = M_PI / 2; else { qreal fraction( qreal( value - sliderOption->minimum )/qreal( sliderOption->maximum - sliderOption->minimum ) ); if( !sliderOption->upsideDown ) fraction = 1 - fraction; if( sliderOption->dialWrapping ) angle = 1.5*M_PI - fraction*2*M_PI; else angle = ( M_PI*8 - fraction*10*M_PI )/6; } return angle; } //______________________________________________________________ void Style::polishScrollArea( QAbstractScrollArea* scrollArea ) const { if( !scrollArea ) return; // HACK: add exception for KPIM transactionItemView, which is an overlay widget // and must have filled background. This is a temporary workaround until a more // robust solution is found. if( scrollArea->inherits( "KPIM::TransactionItemView" ) ) { // also need to make the scrollarea background plain ( using autofill background ) // so that optional vertical scrollbar background is not transparent either. // TODO: possibly add an event filter to use the "normal" window background // instead of something flat. scrollArea->setAutoFillBackground( true ); return; } // check frame style and background role if( !(scrollArea->frameShape() == QFrame::NoFrame || scrollArea->backgroundRole() == QPalette::Window ) ) { return; } // get viewport and check background role QWidget* viewport( scrollArea->viewport() ); if( !( viewport && viewport->backgroundRole() == QPalette::Window ) ) return; // change viewport autoFill background. // do the same for children if the background role is QPalette::Window viewport->setAutoFillBackground( false ); QList children( viewport->findChildren() ); foreach( QWidget* child, children ) { if( child->parent() == viewport && child->backgroundRole() == QPalette::Window ) { child->setAutoFillBackground( false ); } } } //_______________________________________________________________ QRegion Style::tabBarClipRegion( const QTabBar* tabBar ) const { // need to mask-out arrow buttons, if visible. QRegion mask( tabBar->rect() ); foreach( const QObject* child, tabBar->children() ) { const QToolButton* toolButton( qobject_cast( child ) ); if( toolButton && toolButton->isVisible() ) mask -= toolButton->geometry(); } return mask; } //____________________________________________________________________________________ QPolygonF Style::genericArrow( ArrowOrientation orientation, ArrowSize size ) const { QPolygonF arrow; switch( orientation ) { case ArrowUp: { if( size == ArrowTiny ) arrow << QPointF( -2.25, 1.125 ) << QPointF( 0, -1.125 ) << QPointF( 2.25, 1.125 ); else if( size == ArrowSmall ) arrow << QPointF( -2.5, 1.5 ) << QPointF( 0, -1.5 ) << QPointF( 2.5, 1.5 ); else arrow << QPointF( -3.5, 2 ) << QPointF( 0, -2 ) << QPointF( 3.5, 2 ); break; } case ArrowDown: { if( size == ArrowTiny ) arrow << QPointF( -2.25, -1.125 ) << QPointF( 0, 1.125 ) << QPointF( 2.25, -1.125 ); else if( size == ArrowSmall ) arrow << QPointF( -2.5, -1.5 ) << QPointF( 0, 1.5 ) << QPointF( 2.5, -1.5 ); else arrow << QPointF( -3.5, -2 ) << QPointF( 0, 2 ) << QPointF( 3.5, -2 ); break; } case ArrowLeft: { if( size == ArrowTiny ) arrow << QPointF( 1.125, -2.25 ) << QPointF( -1.125, 0 ) << QPointF( 1.125, 2.25 ); else if( size == ArrowSmall ) arrow << QPointF( 1.5, -2.5 ) << QPointF( -1.5, 0 ) << QPointF( 1.5, 2.5 ); else arrow << QPointF( 2, -3.5 ) << QPointF( -2, 0 ) << QPointF( 2, 3.5 ); break; } case ArrowRight: { if( size == ArrowTiny ) arrow << QPointF( -1.125, -2.25 ) << QPointF( 1.125, 0 ) << QPointF( -1.125, 2.25 ); else if( size == ArrowSmall ) arrow << QPointF( -1.5, -2.5 ) << QPointF( 1.5, 0 ) << QPointF( -1.5, 2.5 ); else arrow << QPointF( -2, -3.5 ) << QPointF( 2, 0 ) << QPointF( -2, 3.5 ); break; } default: break; } return arrow; } //____________________________________________________________________________________ QStyleOptionToolButton Style::separatorMenuItemOption( const QStyleOptionMenuItem* menuItemOption, const QWidget* widget ) const { // separator can have a title and an icon // in that case they are rendered as sunken flat toolbuttons QStyleOptionToolButton toolButtonOption; toolButtonOption.initFrom( widget ); toolButtonOption.rect = menuItemOption->rect; toolButtonOption.features = QStyleOptionToolButton::None; toolButtonOption.state = State_On|State_Sunken|State_Enabled; toolButtonOption.subControls = SC_ToolButton; toolButtonOption.icon = menuItemOption->icon; const int iconWidth( pixelMetric( PM_SmallIconSize, menuItemOption, widget ) ); toolButtonOption.iconSize = QSize( iconWidth, iconWidth ); toolButtonOption.text = menuItemOption->text; toolButtonOption.toolButtonStyle = Qt::ToolButtonTextBesideIcon; return toolButtonOption; } //____________________________________________________________________ bool Style::isQtQuickControl( const QStyleOption* option, const QWidget* widget ) const { #if QT_VERSION >= 0x050000 const bool is = (widget == nullptr) && option && option->styleObject && option->styleObject->inherits( "QQuickItem" ); if ( is ) _windowManager->registerQuickItem( static_cast( option->styleObject ) ); return is; #else Q_UNUSED( widget ); Q_UNUSED( option ); return false; #endif } //_____________________________________________________________ Style::SlabRect::SlabRect(void): tiles( TileSet::Ring ) {} //_____________________________________________________________ Style::SlabRect::SlabRect( const QRect& rect, int tiles ): rect( rect ), tiles( TileSet::Tiles(tiles) ) {} //_____________________________________________________________ bool Style::SlabRect::isValid( void ) const { return rect.isValid() && tiles; } //_____________________________________________________________ void Style::SlabRect::adjust( int tileSize ) { if( !( tiles & TileSet::Left ) ) rect.adjust( -tileSize, 0, 0, 0 ); if( !( tiles & TileSet::Right ) ) rect.adjust( 0, 0, tileSize, 0 ); if( !( tiles & TileSet::Top ) ) rect.adjust( 0, -tileSize, 0, 0 ); if( !( tiles & TileSet::Bottom ) ) rect.adjust( 0, 0, 0, tileSize ); } //_____________________________________________________________ Style::SlabRect Style::SlabRect::adjusted( int tileSize ) const { SlabRect copy( *this ); copy.adjust( tileSize ); return copy; } } namespace OxygenPrivate { //_________________________________________________________________________________________________________ void TabBarData::drawTabBarBaseControl( const QStyleOptionTab* tabOption, QPainter* painter, const QWidget* widget ) { // check parent if( !_style ) return; // make sure widget is locked if( !locks( widget ) ) return; // make sure dirty flag is set if( !_dirty ) return; // cast to TabBar and check const QTabBar* tabBar( qobject_cast( widget ) ); if( !tabBar ) return; // get reverseLayout flag const bool reverseLayout( tabOption->direction == Qt::RightToLeft ); // get documentMode flag const QStyleOptionTabV3 *tabOptionV3 = qstyleoption_cast( tabOption ); bool documentMode = tabOptionV3 ? tabOptionV3->documentMode : false; const QTabWidget *tabWidget = ( widget && widget->parentWidget() ) ? qobject_cast( widget->parentWidget() ) : nullptr; documentMode |= ( tabWidget ? tabWidget->documentMode() : true ); const QRect tabBarRect( tabBar->rect() ); // define slab Oxygen::Style::SlabRect slab; // switch on tab shape switch( tabOption->shape ) { case QTabBar::RoundedNorth: case QTabBar::TriangularNorth: { Oxygen::TileSet::Tiles tiles( Oxygen::TileSet::Top ); QRect frameRect; frameRect.setLeft( tabBarRect.left() - Oxygen::TileSet::DefaultSize ); frameRect.setRight( tabBarRect.right() + Oxygen::TileSet::DefaultSize ); frameRect.setTop( tabBarRect.bottom() - Oxygen::TileSet::DefaultSize + 1 ); frameRect.setHeight( 4 ); if( !( documentMode || reverseLayout ) ) tiles |= Oxygen::TileSet::Left; if( !documentMode && reverseLayout ) tiles |= Oxygen::TileSet::Right; slab = Oxygen::Style::SlabRect( frameRect, tiles ); break; } case QTabBar::RoundedSouth: case QTabBar::TriangularSouth: { Oxygen::TileSet::Tiles tiles( Oxygen::TileSet::Bottom ); QRect frameRect; frameRect.setLeft( tabBarRect.left() - Oxygen::TileSet::DefaultSize ); frameRect.setRight( tabBarRect.right() + Oxygen::TileSet::DefaultSize ); frameRect.setBottom( tabBarRect.top() + Oxygen::TileSet::DefaultSize - 1 ); frameRect.setTop( frameRect.bottom() - 4 ); if( !( documentMode || reverseLayout ) ) tiles |= Oxygen::TileSet::Left; if( !documentMode && reverseLayout ) tiles |= Oxygen::TileSet::Right; slab = Oxygen::Style::SlabRect( frameRect, tiles ); break; } case QTabBar::RoundedWest: case QTabBar::TriangularWest: { Oxygen::TileSet::Tiles tiles( Oxygen::TileSet::Left ); QRect frameRect; frameRect.setTop( tabBarRect.top() - Oxygen::TileSet::DefaultSize ); frameRect.setBottom( tabBarRect.bottom() + Oxygen::TileSet::DefaultSize ); frameRect.setLeft( tabBarRect.right() - Oxygen::TileSet::DefaultSize + 1 ); frameRect.setWidth( 4 ); if( !( documentMode || reverseLayout ) ) tiles |= Oxygen::TileSet::Top; if( !documentMode && reverseLayout ) tiles |= Oxygen::TileSet::Bottom; slab = Oxygen::Style::SlabRect( frameRect, tiles ); break; } case QTabBar::RoundedEast: case QTabBar::TriangularEast: { Oxygen::TileSet::Tiles tiles( Oxygen::TileSet::Right ); QRect frameRect; frameRect.setTop( tabBarRect.top() - Oxygen::TileSet::DefaultSize ); frameRect.setBottom( tabBarRect.bottom() + Oxygen::TileSet::DefaultSize ); frameRect.setRight( tabBarRect.left() + Oxygen::TileSet::DefaultSize - 1 ); frameRect.setLeft( frameRect.right() - 4 ); if( !( documentMode || reverseLayout ) ) tiles |= Oxygen::TileSet::Top; if( !documentMode && reverseLayout ) tiles |= Oxygen::TileSet::Bottom; slab = Oxygen::Style::SlabRect( frameRect, tiles ); break; } default: break; } const bool verticalTabs( _style.data()->isVerticalTab( tabOption ) ); const QRect tabWidgetRect( tabWidget ? tabWidget->rect().translated( -widget->geometry().topLeft() ) : QRect() ); const QPalette& palette( tabOption->palette ); const QColor color( palette.color( QPalette::Window ) ); _style.data()->adjustSlabRect( slab, tabWidgetRect, documentMode, verticalTabs ); _style.data()->renderSlab( painter, slab, color, Oxygen::NoFill ); setDirty( false ); return; } } diff --git a/kstyle/oxygenstyle.h b/kstyle/oxygenstyle.h index 382328f2..d6738ea1 100644 --- a/kstyle/oxygenstyle.h +++ b/kstyle/oxygenstyle.h @@ -1,771 +1,773 @@ #ifndef oxygenstyle_h #define oxygenstyle_h ////////////////////////////////////////////////////////////////////////////// // oxygenstyle.h // Oxygen widget style for KDE 4 // ------------------- // // Copyright (C) 2009-2010 Hugo Pereira Da Costa // Copyright (C) 2008 Long Huynh Huu // Copyright (C) 2007-2008 Casper Boemann // Copyright (C) 2007 Matthew Woehlke // Copyright (C) 2003-2005 Sandro Giessl // // based on the KDE style "dotNET": // Copyright (C) 2001-2002, Chris Lee // Carsten Pfeiffer // Karol Szwed // Drawing routines completely reimplemented from KDE3 HighColor, which was // originally based on some stuff from the KDE2 HighColor. // // based on drawing routines of the style "Keramik": // Copyright (c) 2002 Malte Starostik // (c) 2002,2003 Maksim Orlovich // based on the KDE3 HighColor Style // Copyright (C) 2001-2002 Karol Szwed // (C) 2001-2002 Fredrik H�glund // Drawing routines adapted from the KDE2 HCStyle, // Copyright (C) 2000 Daniel M. Duley // (C) 2000 Dirk Mueller // (C) 2001 Martijn Klingens // Progressbar code based on KStyle, // Copyright (C) 2001-2002 Karol Szwed // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Library General Public // License version 2 as published by the Free Software Foundation. // // This library 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 // Library General Public License for more details. // // You should have received a copy of the GNU Library General Public License // along with this library; see the file COPYING.LIB. If not, write to // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. ////////////////////////////////////////////////////////////////////////////// #include "oxygen.h" #include "oxygentileset.h" #include "config-liboxygen.h" #if OXYGEN_USE_KDE4 #include "kstylekde4compat.h" #else #include #endif #include #include #include #include #include #include #include #include #include #include #if QT_VERSION >= 0x050000 #include #endif namespace OxygenPrivate { class TabBarData; } namespace Oxygen { class Animations; class FrameShadowFactory; class MdiWindowShadowFactory; class Mnemonics; class ShadowHelper; class SplitterFactory; class StyleHelper; class Transitions; class TopLevelManager; class WindowManager; class WidgetExplorer; class BlurHelper; //* convenience typedef for base class #if OXYGEN_USE_KDE4 using ParentStyleClass = KStyleKDE4Compat; #else using ParentStyleClass = KStyle; #endif //* base class for oxygen style /** it is responsible to draw all the primitives to be displayed on screen, on request from Qt paint engine */ class Style: public ParentStyleClass { Q_OBJECT /* this tells kde applications that custom style elements are supported, using the kstyle mechanism */ Q_CLASSINFO ("X-KDE-CustomElements", "true") public: //* constructor explicit Style( void ); //* destructor - virtual ~Style( void ); + ~Style( void ) override; //* needed to avoid warnings at compilation time using ParentStyleClass::polish; using ParentStyleClass::unpolish; //* widget polishing - void polish( QWidget* ) ; + void polish( QWidget* ) override; //* widget unpolishing - void unpolish( QWidget* ) ; + void unpolish( QWidget* ) override; //* pixel metrics - int pixelMetric(PixelMetric, const QStyleOption* = nullptr, const QWidget* = nullptr) const ; + int pixelMetric(PixelMetric, const QStyleOption* = nullptr, const QWidget* = nullptr) const override; //* style hints - int styleHint(StyleHint, const QStyleOption* = nullptr, const QWidget* = nullptr, QStyleHintReturn* = nullptr) const ; + int styleHint(StyleHint, const QStyleOption* = nullptr, const QWidget* = nullptr, QStyleHintReturn* = nullptr) const override; //* returns rect corresponding to one widget's subelement - QRect subElementRect( SubElement, const QStyleOption*, const QWidget* ) const ; + QRect subElementRect( SubElement, const QStyleOption*, const QWidget* ) const override; //* returns rect corresponding to one widget's subcontrol - QRect subControlRect( ComplexControl, const QStyleOptionComplex*, SubControl, const QWidget* ) const ; + QRect subControlRect( ComplexControl, const QStyleOptionComplex*, SubControl, const QWidget* ) const override; //* returns size matching contents - QSize sizeFromContents( ContentsType, const QStyleOption*, const QSize&, const QWidget* ) const ; + QSize sizeFromContents( ContentsType, const QStyleOption*, const QSize&, const QWidget* ) const override; //* returns which subcontrol given QPoint corresponds to - SubControl hitTestComplexControl( ComplexControl, const QStyleOptionComplex*, const QPoint&, const QWidget* ) const ; + SubControl hitTestComplexControl( ComplexControl, const QStyleOptionComplex*, const QPoint&, const QWidget* ) const override; //* primitives - void drawPrimitive( PrimitiveElement, const QStyleOption*, QPainter*, const QWidget* ) const ; + void drawPrimitive( PrimitiveElement, const QStyleOption*, QPainter*, const QWidget* ) const override; //* controls - void drawControl( ControlElement, const QStyleOption*, QPainter*, const QWidget* ) const ; + void drawControl( ControlElement, const QStyleOption*, QPainter*, const QWidget* ) const override; //* complex controls - void drawComplexControl( ComplexControl, const QStyleOptionComplex*, QPainter*, const QWidget* ) const ; + void drawComplexControl( ComplexControl, const QStyleOptionComplex*, QPainter*, const QWidget* ) const override; //* generic text rendering void drawItemText( QPainter*, const QRect&, int alignment, const QPalette&, bool enabled, - const QString&, QPalette::ColorRole = QPalette::NoRole) const ; + const QString&, QPalette::ColorRole = QPalette::NoRole) const override; //*@name event filters //@{ - bool eventFilter(QObject *, QEvent *) ; + bool eventFilter(QObject *, QEvent *) override; bool eventFilterComboBoxContainer( QWidget*, QEvent* ); bool eventFilterDockWidget( QDockWidget*, QEvent* ); bool eventFilterMdiSubWindow( QMdiSubWindow*, QEvent* ); #if QT_VERSION >= 0x050000 bool eventFilterCommandLinkButton( QCommandLinkButton*, QEvent* ); #endif bool eventFilterScrollBar( QWidget*, QEvent* ); bool eventFilterTabBar( QWidget*, QEvent* ); bool eventFilterToolBar( QToolBar*, QEvent* ); bool eventFilterToolBox( QToolBox*, QEvent* ); //* install event filter to object, in a unique way void addEventFilter( QObject* object ) { object->removeEventFilter( this ); object->installEventFilter( this ); } //@} protected Q_SLOTS: - //* update configuration - void configurationChanged( void ); - //* standard icons virtual QIcon standardIconImplementation( StandardPixmap, const QStyleOption*, const QWidget* ) const; protected: //* standard icons - QIcon standardIcon( StandardPixmap pixmap, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const + QIcon standardIcon( StandardPixmap pixmap, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const override { return standardIconImplementation( pixmap, option, widget ); } + private Q_SLOTS: + + //* update configuration + void configurationChanged( void ); + + private: + //* load configuration void loadConfiguration(); //*@name enumerations and convenience classes //@{ //* used to store slab characteristics class SlabRect { public: //* constructor explicit SlabRect(void); //* constructor SlabRect( const QRect& rect, int tiles ); //* validity bool isValid( void ) const; /** adjust rectangle depending on tiles and tileSize so that it is rendered properly **/ void adjust( int ); /** adjust rectangle depending on tiles and tileSize so that it is rendered properly **/ SlabRect adjusted( int ) const; QRect rect; TileSet::Tiles tiles; //* list of slabs using List = QList; }; //@} //*@name subelementRect specialized functions //@{ //* default implementation. Does not change anything QRect defaultSubElementRect( const QStyleOption* option, const QWidget* ) const { return option->rect; } QRect pushButtonContentsRect( const QStyleOption* option, const QWidget* ) const; QRect checkBoxContentsRect( const QStyleOption* option, const QWidget* ) const; QRect lineEditContentsRect( const QStyleOption*, const QWidget* ) const; QRect progressBarGrooveRect( const QStyleOption* option, const QWidget* ) const; QRect progressBarContentsRect( const QStyleOption* option, const QWidget* ) const; QRect headerArrowRect( const QStyleOption* option, const QWidget* ) const; QRect headerLabelRect( const QStyleOption* option, const QWidget* ) const; QRect tabBarTabLeftButtonRect( const QStyleOption*, const QWidget* ) const; QRect tabBarTabRightButtonRect( const QStyleOption*, const QWidget* ) const; QRect tabWidgetTabBarRect( const QStyleOption*, const QWidget* ) const; QRect tabWidgetTabContentsRect( const QStyleOption*, const QWidget* ) const; QRect tabWidgetTabPaneRect( const QStyleOption*, const QWidget* ) const; QRect tabWidgetCornerRect( SubElement, const QStyleOption* option, const QWidget* widget ) const; QRect toolBoxTabContentsRect( const QStyleOption* option, const QWidget* ) const; //@} //*@name subcontrol Rect specialized functions //@{ QRect groupBoxSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const; QRect toolButtonSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const; QRect comboBoxSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const; QRect spinBoxSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const; QRect scrollBarInternalSubControlRect( const QStyleOptionComplex*, SubControl ) const; QRect scrollBarSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const; QRect sliderSubControlRect( const QStyleOptionComplex*, SubControl, const QWidget* ) const; //@} //*@name sizeFromContents //@{ QSize defaultSizeFromContents( const QStyleOption*, const QSize& size, const QWidget* ) const { return size; } QSize checkBoxSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize lineEditSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize comboBoxSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize spinBoxSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize sliderSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize pushButtonSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize toolButtonSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize menuBarItemSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize menuItemSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize tabWidgetSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize tabBarTabSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize headerSectionSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; QSize itemViewItemSizeFromContents( const QStyleOption*, const QSize&, const QWidget* ) const; //@} //*@name primitives specialized functions //@{ bool emptyPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const { return true; } bool drawFramePrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameLineEditPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameFocusRectPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameMenuPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameGroupBoxPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameTabWidgetPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameTabBarBasePrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawFrameWindowPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorArrowUpPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { return drawIndicatorArrowPrimitive( ArrowUp, option, painter, widget ); } bool drawIndicatorArrowDownPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { return drawIndicatorArrowPrimitive( ArrowDown, option, painter, widget ); } bool drawIndicatorArrowLeftPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { return drawIndicatorArrowPrimitive( ArrowLeft, option, painter, widget ); } bool drawIndicatorArrowRightPrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { return drawIndicatorArrowPrimitive( ArrowRight, option, painter, widget ); } //* dock widget separators /** it uses the same painting as QSplitter, but due to Qt, the horizontal/vertical convention is inverted */ bool drawIndicatorDockWidgetResizeHandlePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget) const { renderSplitter( option, painter, widget, !(option->state & State_Horizontal ) ); return true; } bool drawIndicatorArrowPrimitive( ArrowOrientation, const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorHeaderArrowPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawPanelButtonCommandPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawPanelButtonToolPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawTabBarPanelButtonToolPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawPanelScrollAreaCornerPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawPanelMenuPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawPanelTipLabelPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawPanelItemViewItemPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorMenuCheckMarkPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorCheckBoxPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorRadioButtonPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorButtonDropDownPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorTabClosePrimitive( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const; bool drawIndicatorTabTearPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorToolBarHandlePrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorToolBarSeparatorPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawIndicatorBranchPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; bool drawWidgetPrimitive( const QStyleOption*, QPainter*, const QWidget* ) const; //@} //*@name controls specialized functions //@{ bool emptyControl( const QStyleOption*, QPainter*, const QWidget* ) const { return true; } - virtual bool drawPushButtonLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawToolButtonLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawMenuBarItemControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawMenuItemControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawProgressBarControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawProgressBarContentsControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawProgressBarGrooveControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawProgressBarLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawScrollBarSliderControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawScrollBarAddLineControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawScrollBarSubLineControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawShapedFrameControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawRubberBandControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawHeaderSectionControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawHeaderEmptyAreaControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawTabBarTabLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawTabBarTabShapeControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawTabBarTabShapeControl_selected( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawTabBarTabShapeControl_unselected( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawToolBoxTabLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawToolBoxTabShapeControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawDockWidgetTitleControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawToolBarControl( const QStyleOption*, QPainter*, const QWidget* ) const; - virtual bool drawSplitterControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const + bool drawPushButtonLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawToolButtonLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawMenuBarItemControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawMenuItemControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawProgressBarControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawProgressBarContentsControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawProgressBarGrooveControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawProgressBarLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawScrollBarSliderControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawScrollBarAddLineControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawScrollBarSubLineControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawShapedFrameControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawRubberBandControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawHeaderSectionControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawHeaderEmptyAreaControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawTabBarTabLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawTabBarTabShapeControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawTabBarTabShapeControl_selected( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawTabBarTabShapeControl_unselected( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawToolBoxTabLabelControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawToolBoxTabShapeControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawDockWidgetTitleControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawToolBarControl( const QStyleOption*, QPainter*, const QWidget* ) const; + bool drawSplitterControl( const QStyleOption* option, QPainter* painter, const QWidget* widget ) const { renderSplitter( option, painter, widget, option->state & State_Horizontal ); return true; } //*@} //*@name complex ontrols specialized functions //@{ bool drawToolButtonComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const; bool drawComboBoxComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const; bool drawSpinBoxComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const; bool drawSliderComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const; bool drawDialComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const; bool drawScrollBarComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const; bool drawTitleBarComplexControl( const QStyleOptionComplex*, QPainter*, const QWidget* ) const; //@} //*@name internal rendering methods /** here mostly to avoid code duplication */ //@{ //* qdial slab void renderDialSlab( QPainter* p, const QRect& r, const QColor& c, const QStyleOption* option, StyleOptions opts = 0 ) const { renderDialSlab( p, r, c, option, opts, -1, AnimationNone ); } //* qdial slab void renderDialSlab( QPainter*, const QRect&, const QColor&, const QStyleOption*, StyleOptions, qreal, AnimationMode ) const; //* generic button slab void renderButtonSlab( QPainter* p, QRect r, const QColor& c, StyleOptions opts = 0, TileSet::Tiles tiles = TileSet::Ring) const { renderButtonSlab( p, r, c, opts, -1, AnimationNone, tiles ); } //* generic button slab void renderButtonSlab( QPainter*, QRect, const QColor&, StyleOptions, qreal, AnimationMode, TileSet::Tiles ) const; //* generic slab void renderSlab( QPainter* painter, const SlabRect& slab, const QColor& color, StyleOptions options = 0 ) const { renderSlab( painter, slab.rect, color, options, slab.tiles ); } //* generic slab void renderSlab( QPainter* painter, QRect rect, const QColor& color, StyleOptions options = 0, TileSet::Tiles tiles = TileSet::Ring) const { renderSlab( painter, rect, color, options, -1, AnimationNone, tiles ); } //* generic slab void renderSlab( QPainter* painter, const SlabRect& slab, const QColor& color, StyleOptions options, qreal opacity, AnimationMode mode ) const { renderSlab( painter, slab.rect, color, options, opacity, mode, slab.tiles ); } //* generic slab void renderSlab( QPainter*, QRect, const QColor&, StyleOptions, qreal, AnimationMode, TileSet::Tiles ) const; //* tab background /** this paints window background behind tab when tab is being dragged */ void fillTabBackground( QPainter*, const QRect&, const QColor&, const QWidget* ) const; //* tab filling void fillTab( QPainter*, const QRect&, const QColor&, const QTabBar::Shape ) const; //* spinbox arrows void renderSpinBoxArrow( QPainter*, const QStyleOptionSpinBox*, const QWidget*, const SubControl& ) const; //* splitter void renderSplitter( const QStyleOption*, QPainter*, const QWidget*, bool ) const; //* mdi subwindow titlebar button void renderTitleBarButton( QPainter*, const QStyleOptionTitleBar*, const QWidget*, const SubControl& ) const; void renderTitleBarButton( QPainter*, const QRect& r, const QColor&, const QColor&, const SubControl& ) const; void renderTitleBarIcon( QPainter*, const QRect&, const SubControl& ) const; //* header background void renderHeaderBackground( const QRect&, const QPalette&, QPainter*, const QWidget*, bool horizontal, bool reverse ) const; void renderHeaderLines( const QRect&, const QPalette&, QPainter*, TileSet::Tiles ) const; //* menu item background void renderMenuItemBackground( const QStyleOption*, QPainter*, const QWidget* ) const; void renderMenuItemRect( const QStyleOption* opt, const QRect& rect, const QPalette& pal, QPainter* p, qreal opacity = -1 ) const { renderMenuItemRect( opt, rect, pal.color(QPalette::Window), p, opacity ); } void renderMenuItemRect( const QStyleOption*, const QRect&, const QColor&, const QPalette&, QPainter* p, qreal opacity = -1 ) const; //* checkbox state (used for checkboxes _and_ radio buttons) enum CheckBoxState { CheckOn, CheckOff, CheckTriState, CheckSunken }; //* checkbox void renderCheckBox( QPainter*, const QRect&, const QPalette&, StyleOptions, CheckBoxState, qreal opacity = -1, AnimationMode mode = AnimationNone ) const; //* radio button void renderRadioButton( QPainter*, const QRect&, const QPalette&, StyleOptions, CheckBoxState, qreal opacity = -1, AnimationMode mode = AnimationNone ) const; //* scrollbar hole void renderScrollBarHole( QPainter*, const QRect&, const QColor&, const Qt::Orientation&, const TileSet::Tiles& = TileSet::Full ) const; //* scrollbar handle (non animated) void renderScrollBarHandle( QPainter* painter, const QRect& r, const QPalette& palette, const Qt::Orientation& orientation, const bool& hover) const { renderScrollBarHandle( painter, r, palette, orientation, hover, -1 ); } //* scrollbar handle (animated) void renderScrollBarHandle( QPainter*, const QRect&, const QPalette&, const Qt::Orientation&, const bool&, const qreal& ) const; //* scrollbar arrow void renderScrollBarArrow( QPainter*, const QRect&, const QColor&, const QColor&, ArrowOrientation ) const; //* returns true if given scrollbar arrow is animated QColor scrollBarArrowColor( const QStyleOptionSlider*, const SubControl&, const QWidget* ) const; //@} - //!*@name various utilty functions + //**@name various utilty functions //@{ //* return dial angle based on option and value qreal dialAngle( const QStyleOptionSlider*, int ) const; //* polish scrollarea void polishScrollArea( QAbstractScrollArea* ) const; //* toolbar mask /** this masks out toolbar expander buttons, when visible, from painting */ QRegion tabBarClipRegion( const QTabBar* ) const; //* returns point position for generic arrows QPolygonF genericArrow( ArrowOrientation, ArrowSize = ArrowNormal ) const; //* scrollbar buttons enum ScrollBarButtonType { NoButton, SingleButton, DoubleButton }; //* returns height for scrollbar buttons depending of button types int scrollBarButtonHeight( const ScrollBarButtonType& type ) const { switch( type ) { case NoButton: return _noButtonHeight; case SingleButton: return _singleButtonHeight; case DoubleButton: return _doubleButtonHeight; default: return 0; } } /** separator can have a title and an icon in that case they are rendered as sunken flat toolbuttons return toolbutton option that matches named separator menu items */ QStyleOptionToolButton separatorMenuItemOption( const QStyleOptionMenuItem*, const QWidget* ) const; //* return true if option corresponds to QtQuick control bool isQtQuickControl( const QStyleOption*, const QWidget* ) const; //@} //* adjust rect based on provided margins QRect insideMargin( const QRect& r, int margin ) const { return insideMargin( r, margin, margin ); } //* adjust rect based on provided margins QRect insideMargin( const QRect& r, int marginWidth, int marginHeight ) const { return r.adjusted( marginWidth, marginHeight, -marginWidth, -marginHeight ); } //* expand size based on margins QSize expandSize( const QSize& size, int margin ) const { return expandSize( size, margin, margin ); } //* expand size based on margins QSize expandSize( const QSize& size, int marginWidth, int marginHeight ) const { return size + 2*QSize( marginWidth, marginHeight ); } //* returns true for vertical tabs bool isVerticalTab( const QStyleOptionTab* option ) const { return isVerticalTab( option->shape ); } bool isVerticalTab( const QTabBar::Shape& shape ) const { return shape == QTabBar::RoundedEast || shape == QTabBar::RoundedWest || shape == QTabBar::TriangularEast || shape == QTabBar::TriangularWest; } //* right to left alignment handling using ParentStyleClass::visualRect; QRect visualRect(const QStyleOption* opt, const QRect& subRect) const { return ParentStyleClass::visualRect(opt->direction, opt->rect, subRect); } //* centering QRect centerRect(const QRect &rect, const QSize& size ) const { return centerRect( rect, size.width(), size.height() ); } QRect centerRect(const QRect &rect, int width, int height) const { return QRect(rect.left() + (rect.width() - width)/2, rect.top() + (rect.height() - height)/2, width, height); } /* Checks whether the point is before the bound rect for bound of given orientation. This is needed to implement custom number of buttons in scrollbars, as well as proper mouse-hover */ inline bool preceeds( const QPoint&, const QRect&, const QStyleOption* ) const; //* return which arrow button is hit by point for scrollbar double buttons inline QStyle::SubControl scrollBarHitTest( const QRect&, const QPoint&, const QStyleOption* ) const; //* adjusted slabRect inline void adjustSlabRect( SlabRect& slab, const QRect&, bool documentMode, bool vertical ) const; - //! return true if one of the widget's parent inherits requested type + //* return true if one of the widget's parent inherits requested type inline bool hasParent( const QWidget*, const char* ) const; //* return true if one of the widget's parent inherits requested type template bool hasParent( const QWidget* ) const; - private: - //*@name scrollbar button types (for addLine and subLine ) //@{ ScrollBarButtonType _addLineButtons = DoubleButton; ScrollBarButtonType _subLineButtons = SingleButton; //@} //*@name metrics for scrollbar buttons //@{ int _noButtonHeight = 0; int _singleButtonHeight = 14; int _doubleButtonHeight = 28; //@} //* helper StyleHelper* _helper; //* shadow helper ShadowHelper* _shadowHelper; //* animations Animations* _animations; //* transitions Transitions* _transitions; //* window manager WindowManager* _windowManager; //* toplevel manager TopLevelManager* _topLevelManager; //* frame shadows FrameShadowFactory* _frameShadowFactory; //* mdi window shadows MdiWindowShadowFactory* _mdiWindowShadowFactory; //* keyboard accelerators Mnemonics* _mnemonics; //* blur helper BlurHelper* _blurHelper; //* widget explorer WidgetExplorer* _widgetExplorer; //* tabBar data OxygenPrivate::TabBarData* _tabBarData; //* splitter Factory, to extend splitters hit area SplitterFactory* _splitterFactory; //* pointer to primitive specialized function using StylePrimitive = bool(Style::*)(const QStyleOption*, QPainter*, const QWidget* ) const; StylePrimitive _frameFocusPrimitive = nullptr; //* pointer to control specialized function using StyleControl = bool (Style::*)( const QStyleOption*, QPainter*, const QWidget* ) const; //* pointer to control specialized function using StyleComplexControl = bool (Style::*)( const QStyleOptionComplex*, QPainter*, const QWidget* ) const; //*@name custom elements //@{ //* use Argb Drag and Drop Window QStyle::StyleHint SH_ArgbDndWindow; //* styled painting for KCapacityBar QStyle::ControlElement CE_CapacityBar; //@} //* tab close button icon (cached) mutable QIcon _tabCloseIcon; friend class OxygenPrivate::TabBarData; }; //_________________________________________________________________________ bool Style::preceeds( const QPoint& point, const QRect& bound, const QStyleOption* option ) const { if( option->state&QStyle::State_Horizontal) { if( option->direction == Qt::LeftToRight) return point.x() < bound.right(); else return point.x() > bound.x(); } else return point.y() < bound.y(); } //_________________________________________________________________________ QStyle::SubControl Style::scrollBarHitTest( const QRect& rect, const QPoint& point, const QStyleOption* option ) const { if( option->state & QStyle::State_Horizontal) { if( option->direction == Qt::LeftToRight ) return point.x() < rect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine; else return point.x() > rect.center().x() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine; } else return point.y() < rect.center().y() ? QStyle::SC_ScrollBarSubLine : QStyle::SC_ScrollBarAddLine; } //___________________________________________________________________________________ void Style::adjustSlabRect( SlabRect& slab, const QRect& tabWidgetRect, bool documentMode, bool vertical ) const { // no tabWidget found, do nothing if( documentMode || !tabWidgetRect.isValid() ) return; else if( vertical ) { slab.rect.setTop( qMax( slab.rect.top(), tabWidgetRect.top() ) ); slab.rect.setBottom( qMin( slab.rect.bottom(), tabWidgetRect.bottom() ) ); } else { slab.rect.setLeft( qMax( slab.rect.left(), tabWidgetRect.left() ) ); slab.rect.setRight( qMin( slab.rect.right(), tabWidgetRect.right() ) ); } return; } //_________________________________________________________________________ bool Style::hasParent( const QWidget* widget, const char* className ) const { if( !widget ) return false; while( (widget = widget->parentWidget()) ) { if( widget->inherits( className ) ) return true; } return false; } //_________________________________________________________________________ template< typename T > bool Style::hasParent( const QWidget* widget ) const { if( !widget ) return false; while( (widget = widget->parentWidget()) ) { if( qobject_cast( widget ) ) return true; } return false; } } #endif diff --git a/kstyle/oxygenstylehelper.h b/kstyle/oxygenstylehelper.h index e03a6e1f..27031f6e 100644 --- a/kstyle/oxygenstylehelper.h +++ b/kstyle/oxygenstylehelper.h @@ -1,309 +1,305 @@ #ifndef oxygen_style_helper_h #define oxygen_style_helper_h /* * Copyright 2010 Hugo Pereira Da Costa * Copyright 2008 Long Huynh Huu * Copyright 2007 Matthew Woehlke * Copyright 2007 Casper Boemann * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "oxygenhelper.h" #include "oxygen.h" #include #if OXYGEN_HAVE_X11 #include #endif //* helper class /** contains utility functions used at multiple places in oxygen style */ namespace Oxygen { class StyleHelper : public Helper { public: //* constructor explicit StyleHelper( KSharedConfigPtr config ); #if OXYGEN_USE_KDE4 //* constructor explicit StyleHelper( const QByteArray& ); #endif //* destructor - virtual ~StyleHelper() {} - //* clear cache - void invalidateCaches() ; + void invalidateCaches() override; //* update maximum cache size - void setMaxCacheSize( int ) ; + void setMaxCacheSize( int ) override; //* background gradient - virtual void setUseBackgroundGradient( bool value ) + void setUseBackgroundGradient( bool value ) { _useBackgroundGradient = value; } //* render window background using a given color as a reference /** For the widget style, both the gradient and the background pixmap are rendered in the same method. All the actual rendering is performed by the base class */ using Helper::renderWindowBackground; - void renderWindowBackground( QPainter*, const QRect&, const QWidget*, const QColor&, int y_shift=-23 ) ; + void renderWindowBackground( QPainter*, const QRect&, const QWidget*, const QColor&, int y_shift=-23 ) override; //* set background gradient hint to widget - void setHasBackgroundGradient( WId, bool ) const ; + void setHasBackgroundGradient( WId, bool ) const override; // render menu background void renderMenuBackground( QPainter* p, const QRect& clipRect, const QWidget* widget, const QPalette& pal ) { renderMenuBackground( p, clipRect, widget, pal.color( widget->window()->backgroundRole() ) ); } // render menu background void renderMenuBackground( QPainter*, const QRect&, const QWidget*, const QColor& ); //*@name color utilities //@{ //* glow color for buttons (mouse-over takes precedence over focus) QColor buttonGlowColor( const QPalette& palette, StyleOptions options, qreal opacity, AnimationMode mode ) const { return buttonGlowColor( palette.currentColorGroup(), options, opacity, mode ); } //* glow color for frames (focus takes precedence over mouse-over) QColor frameGlowColor( const QPalette& palette, StyleOptions options, qreal opacity, AnimationMode mode ) const { return frameGlowColor( palette.currentColorGroup(), options, opacity, mode ); } //* glow color for arrows (mouse-over takes precedence over focus) QColor arrowColor( const QPalette& palette, StyleOptions options, qreal opacity, AnimationMode mode ) const; //* glow color for buttons (mouse-over takes precedence over focus) QColor buttonGlowColor( QPalette::ColorGroup, StyleOptions, qreal, AnimationMode ) const; //* glow color for frames (focus takes precedence over mouse-over) QColor frameGlowColor( QPalette::ColorGroup, StyleOptions, qreal, AnimationMode ) const; //* returns menu background color matching position in a given menu widget - virtual QColor menuBackgroundColor( const QColor& color, const QWidget* w, const QPoint& point ) + QColor menuBackgroundColor( const QColor& color, const QWidget* w, const QPoint& point ) { if( !( w && w->window() ) || checkAutoFillBackground( w ) ) return color; else return menuBackgroundColor( color, w->window()->height(), w->mapTo( w->window(), point ).y() ); } //* returns menu background color matching position in a menu widget of given height - virtual QColor menuBackgroundColor( const QColor& color, int height, int y ) + QColor menuBackgroundColor( const QColor& color, int height, int y ) { return backgroundColor( color, qMin( qreal( 1.0 ), qreal( y )/qMin( 200, 3*height/4 ) ) ); } //* color inline QColor calcMidColor( const QColor& color ); //* merge active and inactive palettes based on ratio, for smooth enable state change transition QPalette disabledPalette( const QPalette&, qreal ratio ) const; //@} //* overloaded window decoration buttons for MDI windows - virtual QPixmap dockWidgetButton( const QColor& color, bool pressed, int size = 21 ); + QPixmap dockWidgetButton( const QColor& color, bool pressed, int size = 21 ); //* round corners( used for Menus, combobox drop-down, detached toolbars and dockwidgets TileSet roundCorner( const QColor&, int size = 5 ); //* groupbox background TileSet slope( const QColor&, qreal shade, int size = TileSet::DefaultSize ); //*@name slabs //@{ //* inverse (inner-hole) shadow /** this method must be public because it is used directly by OxygenStyle to draw dials */ void drawInverseShadow( QPainter&, const QColor&, int pad, int size, qreal fuzz ) const; //* fill a slab of given size with brush set on painter void fillSlab( QPainter&, const QRect&, int size = TileSet::DefaultSize ) const; //* linear gradient used to fill buttons - virtual void fillButtonSlab( QPainter&, const QRect&, const QColor&, bool sunken ); + void fillButtonSlab( QPainter&, const QRect&, const QColor&, bool sunken ); //* default slab - virtual TileSet slab( const QColor& color, qreal shade, int size = TileSet::DefaultSize ) + TileSet slab( const QColor& color, qreal shade, int size = TileSet::DefaultSize ) { return slab( color, QColor(), shade, size ); } //* default slab (with glow) - virtual TileSet slab( const QColor&, const QColor& glow, qreal shade, int size = TileSet::DefaultSize ); + TileSet slab( const QColor&, const QColor& glow, qreal shade, int size = TileSet::DefaultSize ); //* sunken slab - virtual TileSet slabSunken( const QColor&, int size = TileSet::DefaultSize ); + TileSet slabSunken( const QColor&, int size = TileSet::DefaultSize ); //* progressbar TileSet progressBarIndicator( const QPalette&, int ); //* dial QPixmap dialSlab( const QColor& color, qreal shade, int size = TileSet::DefaultSize ) { return dialSlab( color, QColor(), shade, size ); } //* dial QPixmap dialSlab( const QColor&, const QColor&, qreal shade, int size = TileSet::DefaultSize ); // round slabs QPixmap roundSlab( const QColor& color, qreal shade, int size = TileSet::DefaultSize ) { return roundSlab( color, QColor(), shade, size ); } // round slab QPixmap roundSlab( const QColor&, const QColor& glow, qreal shade, int size = TileSet::DefaultSize ); //* slider slab QPixmap sliderSlab( const QColor&, const QColor& glow, bool sunken, qreal shade, int size = TileSet::DefaultSize ); //@} //* debug frame void renderDebugFrame( QPainter*, const QRect& ) const; //*@name holes //@{ void fillHole( QPainter&, const QRect&, int offset = 2 ) const; //* generic hole void renderHole( QPainter *painter, const QColor& color, const QRect &rect, StyleOptions options = 0, TileSet::Tiles tiles = TileSet::Ring ) { renderHole( painter, color, rect, options, -1, Oxygen::AnimationNone, tiles ); } //* generic hole (with animated glow) void renderHole( QPainter*, const QColor&, const QRect&, StyleOptions, qreal, Oxygen::AnimationMode, TileSet::Tiles = TileSet::Ring ); TileSet holeFlat( const QColor&, qreal shade, bool fill = true, int size = TileSet::DefaultSize ); //* scrollbar hole TileSet scrollHole( const QColor&, Qt::Orientation orientation, bool smallShadow = false ); //* scrollbar handle TileSet scrollHandle( const QColor&, const QColor&, int size = TileSet::DefaultSize ); //@} //* focus rect for flat toolbuttons TileSet slitFocused( const QColor& ); //* dock frame TileSet dockFrame( const QColor&, const QColor& ); //* selection TileSet selection( const QColor&, int height, bool custom ); //* inverse glow /** this method must be public because it is used directly by OxygenStyle to draw dials */ void drawInverseGlow( QPainter&, const QColor&, int pad, int size, int rsize ) const; //*@name utility functions //* returns true if compositing is active bool compositingActive( void ) const; //* returns true if a given widget supports alpha channel inline bool hasAlphaChannel( const QWidget* ) const; //* returns true if given widget will get a decoration bool hasDecoration( const QWidget* ) const; //@} - protected: + private: //*@name holes //@{ //* holes TileSet hole( const QColor& color, int size = TileSet::DefaultSize, StyleOptions options = 0 ) { return hole( color, QColor(), size, options ); } //* holes TileSet hole( const QColor&, const QColor& glow, int size = TileSet::DefaultSize, StyleOptions = 0 ); //@} //* generic slab painting (to be stored in tilesets) - virtual void drawSlab( QPainter&, const QColor&, qreal shade ); + void drawSlab( QPainter&, const QColor&, qreal shade ); // round slabs void drawRoundSlab( QPainter&, const QColor&, qreal ); // slider slabs void drawSliderSlab( QPainter&, const QColor&, bool sunken, qreal ); - private: - //* initialize void init( void ); //* background grandient bool _useBackgroundGradient; Cache _dialSlabCache; Cache _roundSlabCache; Cache _sliderSlabCache; Cache _holeCache; Cache _scrollHandleCache; Cache _slabCache; //* mid color cache ColorCache _midColorCache; //* dock button cache PixmapCache _dockWidgetButtonCache; using TileSetCache = BaseCache; TileSetCache _slabSunkenCache; TileSetCache _cornerCache; TileSetCache _holeFlatCache; TileSetCache _slopeCache; TileSetCache _slitCache; TileSetCache _dockFrameCache; TileSetCache _scrollHoleCache; TileSetCache _selectionCache; TileSetCache _progressBarCache; #if OXYGEN_HAVE_X11 //* atom used for compositing manager xcb_atom_t _compositingManagerAtom; #endif }; //____________________________________________________________________ QColor StyleHelper::calcMidColor( const QColor& color ) { const quint64 key( color.rgba() ); if( QColor* cachedColor = _midColorCache.object( key ) ) { return *cachedColor; } QColor out = KColorScheme::shade( color, KColorScheme::MidShade, _contrast - 1.0 ); _midColorCache.insert( key, new QColor( out ) ); return out; } //____________________________________________________________________ bool StyleHelper::hasAlphaChannel( const QWidget* widget ) const { return compositingActive() && widget && widget->testAttribute( Qt::WA_TranslucentBackground ); } } #endif diff --git a/kstyle/oxygenstyleplugin.h b/kstyle/oxygenstyleplugin.h index 3cb33069..d9cf8021 100644 --- a/kstyle/oxygenstyleplugin.h +++ b/kstyle/oxygenstyleplugin.h @@ -1,57 +1,57 @@ #ifndef oxygenstyleplugin_h #define oxygenstyleplugin_h /************************************************************************* * Copyright (C) 2014 by Hugo Pereira Da Costa * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ #include namespace Oxygen { class StylePlugin : public QStylePlugin { Q_OBJECT #if QT_VERSION >= 0x050000 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "oxygen.json" ) #endif public: //* constructor explicit StylePlugin(QObject *parent = 0): QStylePlugin(parent) {} //* destructor ~StylePlugin(); //* returns list of valid keys QStringList keys() const; //* create style - QStyle* create( const QString& ) ; + QStyle* create( const QString& ) override; }; } #endif diff --git a/kstyle/oxygenwindowmanager.cpp b/kstyle/oxygenwindowmanager.cpp index 4dcc96e3..1aa9ef05 100644 --- a/kstyle/oxygenwindowmanager.cpp +++ b/kstyle/oxygenwindowmanager.cpp @@ -1,982 +1,982 @@ /************************************************************************* * Copyright (C) 2014 by Hugo Pereira Da Costa * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ ////////////////////////////////////////////////////////////////////////////// // oxygenwindowmanager.cpp // pass some window mouse press/release/move event actions to window manager // ------------------- // // Copyright (c) 2014 Hugo Pereira Da Costa // // Largely inspired from BeSpin style // Copyright (C) 2007 Thomas Luebking // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenwindowmanager.h" #include "oxygenpropertynames.h" #include "oxygenstyleconfigdata.h" #include "oxygenhelper.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if QT_VERSION >= 0x050300 // needed to deal with device pixel ratio #include #endif #if OXYGEN_HAVE_X11 #include #include #if OXYGEN_USE_KDE4 #include #else #include #endif #endif #if !OXYGEN_USE_KDE4 #include #include #endif #if OXYGEN_HAVE_KWAYLAND #include #include #include #include #include #endif namespace Oxygen { //* provide application-wise event filter /** it us used to unlock dragging and make sure event look is properly restored after a drag has occurred */ class AppEventFilter: public QObject { public: //* constructor explicit AppEventFilter( WindowManager* parent ): QObject( parent ), _parent( parent ) {} //* event filter - bool eventFilter( QObject* object, QEvent* event ) + bool eventFilter( QObject* object, QEvent* event ) override { if( event->type() == QEvent::MouseButtonRelease ) { // stop drag timer if( _parent->_dragTimer.isActive() ) { _parent->resetDrag(); } // unlock if( _parent->isLocked() ) { _parent->setLocked( false ); } } if( !_parent->enabled() ) return false; /* if a drag is in progress, the widget will not receive any event we trigger on the first MouseMove or MousePress events that are received by any widget in the application to detect that the drag is finished */ if( _parent->useWMMoveResize() && _parent->_dragInProgress && _parent->_target && ( event->type() == QEvent::MouseMove || event->type() == QEvent::MouseButtonPress ) ) { return appMouseEvent( object, event ); } return false; } protected: //* application-wise event. /** needed to catch end of XMoveResize events */ bool appMouseEvent( QObject*, QEvent* event ) { #if OXYGEN_USE_KDE4 // store target window (see later) QWidget* window( _parent->_target.data()->window() ); #else Q_UNUSED( event ); #endif /* post some mouseRelease event to the target, in order to counter balance the mouse press that triggered the drag. Note that it triggers a resetDrag */ QMouseEvent mouseEvent( QEvent::MouseButtonRelease, _parent->_dragPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier ); qApp->sendEvent( _parent->_target.data(), &mouseEvent ); #if OXYGEN_USE_KDE4 if( event->type() == QEvent::MouseMove ) { /* HACK: quickly move the main cursor out of the window and back this is needed to get the focus right for the window children the origin of this issue is unknown at the moment. This apparently got fixed with qt5 */ const QPoint cursor = QCursor::pos(); QCursor::setPos(window->mapToGlobal( window->rect().topRight() ) + QPoint(1, 0) ); QCursor::setPos(cursor); } #endif return false; } private: //* parent WindowManager* _parent; }; //_____________________________________________________________ WindowManager::WindowManager( QObject* parent ): QObject( parent ), _enabled( true ), _useWMMoveResize( true ), _dragMode( StyleConfigData::WD_FULL ), _dragDistance( QApplication::startDragDistance() ), _dragDelay( QApplication::startDragTime() ), _dragAboutToStart( false ), _dragInProgress( false ), _locked( false ), _cursorOverride( false ) #if OXYGEN_HAVE_KWAYLAND , _seat( Q_NULLPTR ) , _pointer( Q_NULLPTR ) , _waylandSerial( 0 ) #endif { // install application wise event filter _appEventFilter = new AppEventFilter( this ); qApp->installEventFilter( _appEventFilter ); } //_____________________________________________________________ void WindowManager::initialize( void ) { setEnabled( StyleConfigData::windowDragMode() != StyleConfigData::WD_NONE ); setDragMode( StyleConfigData::windowDragMode() ); setUseWMMoveResize( StyleConfigData::useWMMoveResize() ); setDragDistance( QApplication::startDragDistance() ); setDragDelay( QApplication::startDragTime() ); initializeWhiteList(); initializeBlackList(); initializeWayland(); } //_______________________________________________________ void WindowManager::initializeWayland() { #if OXYGEN_HAVE_KWAYLAND if( !Helper::isWayland() ) return; if( _seat ) { // already initialized return; } using namespace KWayland::Client; auto connection = ConnectionThread::fromApplication( this ); if( !connection ) { return; } Registry *registry = new Registry( this ); registry->create( connection ); connect(registry, &Registry::interfacesAnnounced, this, [registry, this] { const auto interface = registry->interface( Registry::Interface::Seat ); if( interface.name != 0 ) { _seat = registry->createSeat( interface.name, interface.version, this ); connect(_seat, &Seat::hasPointerChanged, this, &WindowManager::waylandHasPointerChanged); } } ); registry->setup(); connection->roundtrip(); #endif } //_______________________________________________________ void WindowManager::waylandHasPointerChanged(bool hasPointer) { #if OXYGEN_HAVE_KWAYLAND Q_ASSERT( _seat ); if( hasPointer ) { if( !_pointer ) { _pointer = _seat->createPointer(this); connect(_pointer, &KWayland::Client::Pointer::buttonStateChanged, this, [this] (quint32 serial) { _waylandSerial = serial; } ); } } else { delete _pointer; _pointer = nullptr; } #else Q_UNUSED( hasPointer ); #endif } //_____________________________________________________________ void WindowManager::registerWidget( QWidget* widget ) { if( isBlackListed( widget ) || isDragable( widget ) ) { /* install filter for dragable widgets. also install filter for blacklisted widgets to be able to catch the relevant events and prevent the drag to happen */ widget->removeEventFilter( this ); widget->installEventFilter( this ); } } #if !OXYGEN_USE_KDE4 void WindowManager::registerQuickItem( QQuickItem* item ) { if ( !item ) return; QQuickWindow *window = item->window(); if (window) { QQuickItem *contentItem = window->contentItem(); contentItem->setAcceptedMouseButtons( Qt::LeftButton ); contentItem->removeEventFilter( this ); contentItem->installEventFilter( this ); } } #endif //_____________________________________________________________ void WindowManager::unregisterWidget( QWidget* widget ) { if( widget ) { widget->removeEventFilter( this ); } } //_____________________________________________________________ void WindowManager::initializeWhiteList( void ) { _whiteList.clear(); // add user specified whitelisted classnames _whiteList.insert( ExceptionId( QStringLiteral( "MplayerWindow" ) ) ); _whiteList.insert( ExceptionId( QStringLiteral( "ViewSliders@kmix" ) ) ); _whiteList.insert( ExceptionId( QStringLiteral( "Sidebar_Widget@konqueror" ) ) ); foreach( const QString& exception, StyleConfigData::windowDragWhiteList() ) { ExceptionId id( exception ); if( !id.className().isEmpty() ) { _whiteList.insert( ExceptionId( exception ) ); } } } //_____________________________________________________________ void WindowManager::initializeBlackList( void ) { _blackList.clear(); _blackList.insert( ExceptionId( QStringLiteral( "CustomTrackView@kdenlive" ) ) ); _blackList.insert( ExceptionId( QStringLiteral( "MuseScore" ) ) ); _blackList.insert( ExceptionId( QStringLiteral( "KGameCanvasWidget" ) ) ); foreach( const QString& exception, StyleConfigData::windowDragBlackList() ) { ExceptionId id( exception ); if( !id.className().isEmpty() ) { _blackList.insert( ExceptionId( exception ) ); } } } //_____________________________________________________________ bool WindowManager::eventFilter( QObject* object, QEvent* event ) { if( !enabled() ) return false; switch ( event->type() ) { case QEvent::MouseButtonPress: return mousePressEvent( object, event ); break; case QEvent::MouseMove: if ( object == _target.data() #if !OXYGEN_USE_KDE4 || object == _quickTarget.data() #endif ) return mouseMoveEvent( object, event ); break; case QEvent::MouseButtonRelease: if ( _target #if !OXYGEN_USE_KDE4 || _quickTarget #endif ) return mouseReleaseEvent( object, event ); break; default: break; } return false; } //_____________________________________________________________ void WindowManager::timerEvent( QTimerEvent* event ) { if( event->timerId() == _dragTimer.timerId() ) { _dragTimer.stop(); #if OXYGEN_USE_KDE4 if( _target ) { startDrag( _target.data()->window(), _globalDragPoint ); } #else if( _target ) { startDrag( _target.data()->window()->windowHandle(), _globalDragPoint ); } else if( _quickTarget ) { startDrag( _quickTarget.data()->window(), _globalDragPoint ); } #endif } else { return QObject::timerEvent( event ); } } //_____________________________________________________________ bool WindowManager::mousePressEvent( QObject* object, QEvent* event ) { // cast event and check buttons/modifiers QMouseEvent *mouseEvent = static_cast( event ); if( !( mouseEvent->modifiers() == Qt::NoModifier && mouseEvent->button() == Qt::LeftButton ) ) { return false; } #if !OXYGEN_USE_KDE4 if (mouseEvent->source() != Qt::MouseEventNotSynthesized) { return false; } #endif // check lock if( isLocked() ) return false; else setLocked( true ); #if !OXYGEN_USE_KDE4 // check QQuickItem - we can immediately start drag, because QQuickWindow's contentItem // only receives mouse events that weren't handled by children if ( QQuickItem *item = qobject_cast( object ) ) { _quickTarget = item; _dragPoint = mouseEvent->pos(); _globalDragPoint = mouseEvent->globalPos(); if( _dragTimer.isActive() ) _dragTimer.stop(); _dragTimer.start( _dragDelay, this ); return true; } #endif // cast to widget QWidget *widget = static_cast( object ); // check if widget can be dragged from current position if( isBlackListed( widget ) || !canDrag( widget ) ) return false; // retrieve widget's child at event position QPoint position( mouseEvent->pos() ); QWidget* child = widget->childAt( position ); if( !canDrag( widget, child, position ) ) return false; // save target and drag point _target = widget; _dragPoint = position; _globalDragPoint = mouseEvent->globalPos(); _dragAboutToStart = true; // send a move event to the current child with same position // if received, it is caught to actually start the drag QPoint localPoint( _dragPoint ); if( child ) localPoint = child->mapFrom( widget, localPoint ); else child = widget; QMouseEvent localMouseEvent( QEvent::MouseMove, localPoint, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier ); qApp->sendEvent( child, &localMouseEvent ); // never eat event return false; } //_____________________________________________________________ bool WindowManager::mouseMoveEvent( QObject* object, QEvent* event ) { Q_UNUSED( object ); QMouseEvent *mouseEvent = static_cast( event ); #if !OXYGEN_USE_KDE4 if (mouseEvent->source() != Qt::MouseEventNotSynthesized) { return false; } #endif // stop timer if( _dragTimer.isActive() ) _dragTimer.stop(); // cast event and check drag distance if( !_dragInProgress ) { if( _dragAboutToStart ) { if( mouseEvent->pos() == _dragPoint ) { // start timer, _dragAboutToStart = false; if( _dragTimer.isActive() ) _dragTimer.stop(); _dragTimer.start( _dragDelay, this ); } else resetDrag(); } else if( QPoint( mouseEvent->globalPos() - _globalDragPoint ).manhattanLength() >= _dragDistance ) { _dragTimer.start( 0, this ); } return true; } else if( !useWMMoveResize() && _target ) { // use QWidget::move for the grabbing /* this works only if the sending object and the target are identical */ QWidget* window( _target.data()->window() ); window->move( window->pos() + mouseEvent->pos() - _dragPoint ); return true; } else return false; } //_____________________________________________________________ bool WindowManager::mouseReleaseEvent( QObject* object, QEvent* event ) { Q_UNUSED( object ); Q_UNUSED( event ); resetDrag(); return false; } //_____________________________________________________________ bool WindowManager::isDragable( QWidget* widget ) { // check widget if( !widget ) return false; // accepted default types if( ( qobject_cast( widget ) && widget->isWindow() ) || ( qobject_cast( widget ) && widget->isWindow() ) || qobject_cast( widget ) ) { return true; } // more accepted types, provided they are not dock widget titles if( ( qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) || qobject_cast( widget ) ) && !isDockWidgetTitle( widget ) ) { return true; } if( widget->inherits( "KScreenSaver" ) && widget->inherits( "KCModule" ) ) { return true; } if( isWhiteListed( widget ) ) { return true; } // flat toolbuttons if( QToolButton* toolButton = qobject_cast( widget ) ) { if( toolButton->autoRaise() ) return true; } // viewports /* one needs to check that 1/ the widget parent is a scrollarea 2/ it matches its parent viewport 3/ the parent is not blacklisted */ if( QListView* listView = qobject_cast( widget->parentWidget() ) ) { if( listView->viewport() == widget && !isBlackListed( listView ) ) return true; } if( QTreeView* treeView = qobject_cast( widget->parentWidget() ) ) { if( treeView->viewport() == widget && !isBlackListed( treeView ) ) return true; } /* catch labels in status bars. this is because of kstatusbar who captures buttonPress/release events */ if( QLabel* label = qobject_cast( widget ) ) { if( label->textInteractionFlags().testFlag( Qt::TextSelectableByMouse ) ) return false; QWidget* parent = label->parentWidget(); while( parent ) { if( qobject_cast( parent ) ) return true; parent = parent->parentWidget(); } } return false; } //_____________________________________________________________ bool WindowManager::isBlackListed( QWidget* widget ) { // check against noAnimations propery QVariant propertyValue( widget->property( PropertyNames::noWindowGrab ) ); if( propertyValue.isValid() && propertyValue.toBool() ) return true; // list-based blacklisted widgets QString appName( qApp->applicationName() ); foreach( const ExceptionId& id, _blackList ) { if( !id.appName().isEmpty() && id.appName() != appName ) continue; if( id.className() == QStringLiteral( "*" ) && !id.appName().isEmpty() ) { // if application name matches and all classes are selected // disable the grabbing entirely setEnabled( false ); return true; } if( widget->inherits( id.className().toLatin1().data() ) ) return true; } return false; } //_____________________________________________________________ bool WindowManager::isWhiteListed( QWidget* widget ) const { QString appName( qApp->applicationName() ); foreach( const ExceptionId& id, _whiteList ) { if( !id.appName().isEmpty() && id.appName() != appName ) continue; if( widget->inherits( id.className().toLatin1().data() ) ) return true; } return false; } //_____________________________________________________________ bool WindowManager::canDrag( QWidget* widget ) { // check if enabled if( !enabled() ) return false; // assume isDragable widget is already passed // check some special cases where drag should not be effective // check mouse grabber if( QWidget::mouseGrabber() ) return false; /* check cursor shape. Assume that a changed cursor means that some action is in progress and should prevent the drag */ if( widget->cursor().shape() != Qt::ArrowCursor ) return false; // accept return true; } //_____________________________________________________________ bool WindowManager::canDrag( QWidget* widget, QWidget* child, const QPoint& position ) { // retrieve child at given position and check cursor again if( child && child->cursor().shape() != Qt::ArrowCursor ) return false; /* check against children from which drag should never be enabled, even if mousePress/Move has been passed to the parent */ if( child && ( qobject_cast(child ) || qobject_cast( child ) || qobject_cast( child ) ) ) { return false; } // tool buttons if( QToolButton* toolButton = qobject_cast( widget ) ) { if( dragMode() == StyleConfigData::WD_MINIMAL && !qobject_cast(widget->parentWidget() ) ) return false; return toolButton->autoRaise() && !toolButton->isEnabled(); } // check menubar if( QMenuBar* menuBar = qobject_cast( widget ) ) { // do not drag from menubars embedded in Mdi windows if( findParent( widget ) ) return false; // check if there is an active action if( menuBar->activeAction() && menuBar->activeAction()->isEnabled() ) return false; // check if action at position exists and is enabled if( QAction* action = menuBar->actionAt( position ) ) { if( action->isSeparator() ) return true; if( action->isEnabled() ) return false; } // return true in all other cases return true; } /* in MINIMAL mode, anything that has not been already accepted and does not come from a toolbar is rejected */ if( dragMode() == StyleConfigData::WD_MINIMAL ) { if( qobject_cast( widget ) ) return true; else return false; } /* following checks are relevant only for WD_FULL mode */ // tabbar. Make sure no tab is under the cursor if( QTabBar* tabBar = qobject_cast( widget ) ) { return tabBar->tabAt( position ) == -1; } /* check groupboxes prevent drag if unchecking grouboxes */ if( QGroupBox *groupBox = qobject_cast( widget ) ) { // non checkable group boxes are always ok if( !groupBox->isCheckable() ) return true; // gather options to retrieve checkbox subcontrol rect QStyleOptionGroupBox opt; opt.initFrom( groupBox ); if( groupBox->isFlat() ) opt.features |= QStyleOptionFrameV2::Flat; opt.lineWidth = 1; opt.midLineWidth = 0; opt.text = groupBox->title(); opt.textAlignment = groupBox->alignment(); opt.subControls = (QStyle::SC_GroupBoxFrame | QStyle::SC_GroupBoxCheckBox); if (!groupBox->title().isEmpty()) opt.subControls |= QStyle::SC_GroupBoxLabel; opt.state |= (groupBox->isChecked() ? QStyle::State_On : QStyle::State_Off); // check against groupbox checkbox if( groupBox->style()->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxCheckBox, groupBox ).contains( position ) ) { return false; } // check against groupbox label if( !groupBox->title().isEmpty() && groupBox->style()->subControlRect(QStyle::CC_GroupBox, &opt, QStyle::SC_GroupBoxLabel, groupBox ).contains( position ) ) { return false; } return true; } // labels if( QLabel* label = qobject_cast( widget ) ) { if( label->textInteractionFlags().testFlag( Qt::TextSelectableByMouse ) ) return false; } // abstract item views QAbstractItemView* itemView( nullptr ); if( ( itemView = qobject_cast( widget->parentWidget() ) ) || ( itemView = qobject_cast( widget->parentWidget() ) ) ) { if( widget == itemView->viewport() ) { // QListView if( itemView->frameShape() != QFrame::NoFrame ) return false; else if( itemView->selectionMode() != QAbstractItemView::NoSelection && itemView->selectionMode() != QAbstractItemView::SingleSelection && itemView->model() && itemView->model()->rowCount() ) return false; else if( itemView->model() && itemView->indexAt( position ).isValid() ) return false; } } else if( ( itemView = qobject_cast( widget->parentWidget() ) ) ) { if( widget == itemView->viewport() ) { // QAbstractItemView if( itemView->frameShape() != QFrame::NoFrame ) return false; else if( itemView->indexAt( position ).isValid() ) return false; } } else if( QGraphicsView* graphicsView = qobject_cast( widget->parentWidget() ) ) { if( widget == graphicsView->viewport() ) { // QGraphicsView if( graphicsView->frameShape() != QFrame::NoFrame ) return false; else if( graphicsView->dragMode() != QGraphicsView::NoDrag ) return false; else if( graphicsView->itemAt( position ) ) return false; } } return true; } //____________________________________________________________ void WindowManager::resetDrag( void ) { if( (!useWMMoveResize() ) && _target && _cursorOverride ) { qApp->restoreOverrideCursor(); _cursorOverride = false; } _target.clear(); #if !OXYGEN_USE_KDE4 _quickTarget.clear(); #endif if( _dragTimer.isActive() ) _dragTimer.stop(); _dragPoint = QPoint(); _globalDragPoint = QPoint(); _dragAboutToStart = false; _dragInProgress = false; } //____________________________________________________________ void WindowManager::startDrag( Window* window, const QPoint& position ) { if( !( enabled() && window ) ) return; if( QWidget::mouseGrabber() ) return; // ungrab pointer if( useWMMoveResize() ) { if( Helper::isX11() ) { startDragX11( window, position ); } else if( Helper::isWayland() ) { startDragWayland( window, position ); } } else if( !_cursorOverride ) { qApp->setOverrideCursor( Qt::SizeAllCursor ); _cursorOverride = true; } _dragInProgress = true; return; } //_______________________________________________________ void WindowManager::startDragX11( Window* window, const QPoint& position ) { #if OXYGEN_HAVE_X11 // connection xcb_connection_t* connection( Helper::connection() ); #if QT_VERSION >= 0x050300 const qreal dpiRatio = qApp->devicePixelRatio(); #else const qreal dpiRatio = 1; #endif #if OXYGEN_USE_KDE4 Display* net_connection = QX11Info::display(); #else xcb_connection_t* net_connection = connection; #endif xcb_ungrab_pointer( connection, XCB_TIME_CURRENT_TIME ); NETRootInfo( net_connection, NET::WMMoveResize ).moveResizeRequest( window->winId(), position.x() * dpiRatio, position.y() * dpiRatio, NET::Move ); #else Q_UNUSED( window ); Q_UNUSED( position ); #endif } //_______________________________________________________ void WindowManager::startDragWayland( Window* window, const QPoint& ) { #if OXYGEN_HAVE_KWAYLAND if( !_seat ) { return; } auto shellSurface = KWayland::Client::ShellSurface::fromWindow(window); if( !shellSurface ) { // TODO: also check for xdg-shell in future return; } shellSurface->requestMove( _seat, _waylandSerial ); #else Q_UNUSED( window ); #endif } //____________________________________________________________ bool WindowManager::supportWMMoveResize( void ) const { #if OXYGEN_HAVE_KWAYLAND if( Helper::isWayland() ) { return true; } #endif #if OXYGEN_HAVE_X11 return Helper::isX11(); #else return false; #endif } //____________________________________________________________ bool WindowManager::isDockWidgetTitle( const QWidget* widget ) const { if( !widget ) return false; if( const QDockWidget* dockWidget = qobject_cast( widget->parent() ) ) { return widget == dockWidget->titleBarWidget(); } else return false; } } diff --git a/kstyle/oxygenwindowmanager.h b/kstyle/oxygenwindowmanager.h index 72ec4056..aea4ebfc 100644 --- a/kstyle/oxygenwindowmanager.h +++ b/kstyle/oxygenwindowmanager.h @@ -1,329 +1,325 @@ #ifndef oxygenwindowmanager_h #define oxygenwindowmanager_h /************************************************************************* * Copyright (C) 2014 by Hugo Pereira Da Costa * * * * This program 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 program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * *************************************************************************/ #include "oxygen.h" #include "config-liboxygen.h" #include #include #include #include #include #include #if !OXYGEN_USE_KDE4 #include #endif #if OXYGEN_HAVE_KWAYLAND namespace KWayland { namespace Client { class Pointer; class Seat; } } #endif namespace Oxygen { class WindowManager: public QObject { Q_OBJECT public: //* constructor explicit WindowManager( QObject* ); - //* destructor - virtual ~WindowManager( void ) - {} - //* initialize /** read relevant options from config */ void initialize( void ); //* register widget void registerWidget( QWidget* ); #if !OXYGEN_USE_KDE4 //* register quick item void registerQuickItem( QQuickItem* ); #endif //* unregister widget void unregisterWidget( QWidget* ); //* event filter [reimplemented] - bool eventFilter( QObject*, QEvent* ) ; + bool eventFilter( QObject*, QEvent* ) override; protected: //* timer event, /** used to start drag if button is pressed for a long enough time */ - void timerEvent( QTimerEvent* ) ; + void timerEvent( QTimerEvent* ) override; + + private: //* mouse press event bool mousePressEvent( QObject*, QEvent* ); //* mouse move event bool mouseMoveEvent( QObject*, QEvent* ); //* mouse release event bool mouseReleaseEvent( QObject*, QEvent* ); //*@name configuration //@{ //* enable state bool enabled( void ) const { return _enabled; } //* enable state void setEnabled( bool value ) { _enabled = value; } //* returns true if window manager is used for moving bool useWMMoveResize( void ) const { return supportWMMoveResize() && _useWMMoveResize; } //* use window manager for moving, when available void setUseWMMoveResize( bool value ) { _useWMMoveResize = value; } //* drag mode int dragMode( void ) const { return _dragMode; } //* drag mode void setDragMode( int value ) { _dragMode = value; } //* drag distance (pixels) void setDragDistance( int value ) { _dragDistance = value; } //* drag delay (msec) void setDragDelay( int value ) { _dragDelay = value; } //* set list of whiteListed widgets /** white list is read from options and is used to adjust per-app window dragging issues */ void initializeWhiteList(); //* set list of blackListed widgets /** black list is read from options and is used to adjust per-app window dragging issues */ void initializeBlackList( void ); //* initializes the Wayland specific parts void initializeWayland(); //* The Wayland Seat's hasPointer property changed void waylandHasPointerChanged( bool hasPointer ); //@} //* returns true if widget is dragable bool isDragable( QWidget* ); //* returns true if widget is dragable bool isBlackListed( QWidget* ); //* returns true if widget is dragable bool isWhiteListed( QWidget* ) const; //* returns true if drag can be started from current widget bool canDrag( QWidget* ); //* returns true if drag can be started from current widget and position /** child at given position is passed as second argument */ bool canDrag( QWidget*, QWidget*, const QPoint& ); //* reset drag void resetDrag( void ); #if QT_VERSION >= 0x050000 using Window = QWindow; #else using Window = QWidget; #endif //* start drag void startDrag( Window*, const QPoint& ); //* X11 specific implementation for startDrag void startDragX11( Window*, const QPoint& ); //* Wayland specific implementation for startDrag void startDragWayland( Window*, const QPoint& ); //* returns true if window manager is used for moving /** right now this is true only for X11 */ bool supportWMMoveResize( void ) const; //* utility function bool isDockWidgetTitle( const QWidget* ) const; //*@name lock //@{ void setLocked( bool value ) { _locked = value; } //* lock bool isLocked( void ) const { return _locked; } //@} //* returns first widget matching given class, or 0L if none template T findParent( const QWidget* ) const; - private: - //* enability bool _enabled; //* use WM moveResize bool _useWMMoveResize; //* drag mode int _dragMode; //* drag distance /** this is copied from kwin::geometry */ int _dragDistance; //* drag delay /** this is copied from kwin::geometry */ int _dragDelay; //* wrapper for exception id class ExceptionId: public QPair { public: //* constructor explicit ExceptionId( const QString& value ) { const QStringList args( value.split( QChar::fromLatin1( '@' ) ) ); if( args.isEmpty() ) return; second = args[0].trimmed(); if( args.size()>1 ) first = args[1].trimmed(); } const QString& appName( void ) const { return first; } const QString& className( void ) const { return second; } }; //* exception set using ExceptionSet = QSet; //* list of white listed special widgets /** it is read from options and is used to adjust per-app window dragging issues */ ExceptionSet _whiteList; //* list of black listed special widgets /** it is read from options and is used to adjust per-app window dragging issues */ ExceptionSet _blackList; //* drag point QPoint _dragPoint; QPoint _globalDragPoint; //* drag timer QBasicTimer _dragTimer; //* target being dragged /** Weak pointer is used in case the target gets deleted while drag is in progress */ WeakPointer _target; #if !OXYGEN_USE_KDE4 WeakPointer _quickTarget; #endif //* true if drag is about to start bool _dragAboutToStart; //* true if drag is in progress bool _dragInProgress; //* true if drag is locked bool _locked; //* cursor override /** used to keep track of application cursor being overridden when dragging in non-WM mode */ bool _cursorOverride; //* application event filter QObject* _appEventFilter; #if OXYGEN_HAVE_KWAYLAND //* The Wayland seat object which needs to be passed to move requests. KWayland::Client::Seat* _seat; //* The Wayland pointer object where we get pointer events on. KWayland::Client::Pointer* _pointer; //* latest searial which needs to be passed to the move requests. quint32 _waylandSerial; #endif //* allow access of all private members to the app event filter friend class AppEventFilter; }; //____________________________________________________________________ template T WindowManager::findParent( const QWidget* widget ) const { if( !widget ) return 0L; for( QWidget* parent = widget->parentWidget(); parent; parent = parent->parentWidget() ) { if( T cast = qobject_cast(parent) ) return cast; } return 0L; } } #endif diff --git a/kstyle/transitions/oxygencomboboxdata.h b/kstyle/transitions/oxygencomboboxdata.h index 690a7bfb..5f243678 100644 --- a/kstyle/transitions/oxygencomboboxdata.h +++ b/kstyle/transitions/oxygencomboboxdata.h @@ -1,95 +1,93 @@ #ifndef oxygencombobox_datah #define oxygencombobox_datah ////////////////////////////////////////////////////////////////////////////// // oxygencomboboxdata.h // data container for QComboBox transition // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygentransitiondata.h" #include #include #include #include #include namespace Oxygen { - //! generic data + //* generic data class ComboBoxData: public TransitionData { Q_OBJECT public: - //! constructor + //* constructor ComboBoxData( QObject*, QComboBox*, int ); - //! destructor - virtual ~ComboBoxData( void ) - {} - - //! event filter - bool eventFilter( QObject*, QEvent* ) ; + //* event filter + bool eventFilter( QObject*, QEvent* ) override; protected: - //! timer event - void timerEvent( QTimerEvent* ) ; - - //! target rect - /*! return rect corresponding to the area to be updated when animating */ - QRect targetRect( void ) const - { return _target ? _target.data()->rect().adjusted( 5, 5, -5, -5 ):QRect(); } + //* timer event + void timerEvent( QTimerEvent* ) override; protected Q_SLOTS: - //! triggered when item is activated in combobox - virtual void indexChanged( void ); + //* initialize animation + bool initializeAnimation( void ) override; - //! initialize animation - bool initializeAnimation( void ) ; + //* animate + bool animate( void ) override; - //! animate - bool animate( void ) ; + private Q_SLOTS: - //! called when target is destroyed - virtual void targetDestroyed( void ); + //* triggered when item is activated in combobox + void indexChanged( void ); + + //* called when target is destroyed + void targetDestroyed( void ); private: - //! needed to start animations out of parent paintEvent + //* target rect + /** return rect corresponding to the area to be updated when animating */ + QRect targetRect( void ) const + { return _target ? _target.data()->rect().adjusted( 5, 5, -5, -5 ):QRect(); } + + //* needed to start animations out of parent paintEvent QBasicTimer _timer; - //! target + //* target WeakPointer _target; }; } #endif diff --git a/kstyle/transitions/oxygencomboboxengine.h b/kstyle/transitions/oxygencomboboxengine.h index d40ee436..90aa769e 100644 --- a/kstyle/transitions/oxygencomboboxengine.h +++ b/kstyle/transitions/oxygencomboboxengine.h @@ -1,86 +1,82 @@ #ifndef oxygencomboboxengine_h #define oxygencomboboxengine_h ////////////////////////////////////////////////////////////////////////////// // oxygencomboboxengine.h // stores event filters and maps widgets to animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygencomboboxdata.h" namespace Oxygen { - //! used for simple widgets + //* used for simple widgets class ComboBoxEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit ComboBoxEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~ComboBoxEngine( void ) - {} - - //! register widget - virtual bool registerWidget( QComboBox* ); + //* register widget + bool registerWidget( QComboBox* ); - //! duration - void setEnabled( bool value ) + //* duration + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! maps + //* maps DataMap _data; }; } #endif diff --git a/kstyle/transitions/oxygenlabeldata.h b/kstyle/transitions/oxygenlabeldata.h index c9be9912..2597521c 100644 --- a/kstyle/transitions/oxygenlabeldata.h +++ b/kstyle/transitions/oxygenlabeldata.h @@ -1,114 +1,114 @@ #ifndef oxygenlabel_datah #define oxygenlabel_datah ////////////////////////////////////////////////////////////////////////////// // oxygenlabeldata.h // data container for QLabel transition // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygentransitiondata.h" #include #include #include namespace Oxygen { - //! generic data + //* generic data class LabelData: public TransitionData { Q_OBJECT public: - //! constructor + //* constructor LabelData( QObject*, QLabel*, int ); - //! destructor - virtual ~LabelData( void ) - {} + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! event filter - bool eventFilter( QObject*, QEvent* ) ; - - //! returns true if animations are locked + //* returns true if animations are locked bool isLocked( void ) const { return _animationLockTimer.isActive(); } - //! start lock animation timer + //* start lock animation timer void lockAnimations( void ) { _animationLockTimer.start( _lockTime, this ); } - //! start lock animation timer + //* start lock animation timer void unlockAnimations( void ) { _animationLockTimer.stop(); } + protected: + + //* timer event + void timerEvent( QTimerEvent* ) override; + protected Q_SLOTS: - //! initialize animation - bool initializeAnimation( void ) ; + //* initialize animation + bool initializeAnimation( void ) override; - //! animate - bool animate( void ) ; + //* animate + bool animate( void ) override; - //! called when target is destroyed - virtual void targetDestroyed( void ); + private Q_SLOTS: + + //* called when target is destroyed + void targetDestroyed( void ); - protected: + private: - //! true if transparent + //* true if transparent bool transparent( void ) const { return transition() && transition().data()->testFlag( TransitionWidget::Transparent ); } - //! timer event - void timerEvent( QTimerEvent* ) ; - private: - //! lock time (milliseconds + //* lock time (milliseconds static const int _lockTime; - //! timer used to disable animations when triggered too early + //* timer used to disable animations when triggered too early QBasicTimer _animationLockTimer; - //! needed to start animations out of parent paintEvent + //* needed to start animations out of parent paintEvent QBasicTimer _timer; - //! target + //* target WeakPointer _target; - //! old text + //* old text QString _text; - //! widget rect + //* widget rect /*! needed to properly handle QLabel geometry changes */ QRect _widgetRect; }; } #endif diff --git a/kstyle/transitions/oxygenlabelengine.h b/kstyle/transitions/oxygenlabelengine.h index f077e000..2a941ea5 100644 --- a/kstyle/transitions/oxygenlabelengine.h +++ b/kstyle/transitions/oxygenlabelengine.h @@ -1,86 +1,82 @@ #ifndef oxygenlabelengine_h #define oxygenlabelengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenlabelengine.h // stores event filters and maps widgets to animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenlabeldata.h" namespace Oxygen { - //! used for simple widgets + //* used for simple widgets class LabelEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit LabelEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~LabelEngine( void ) - {} - - //! register widget - virtual bool registerWidget( QLabel* ); + //* register widget + bool registerWidget( QLabel* ); - //! duration - void setEnabled( bool value ) + //* duration + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! maps + //* maps DataMap _data; }; } #endif diff --git a/kstyle/transitions/oxygenlineeditdata.h b/kstyle/transitions/oxygenlineeditdata.h index edc02204..bb0c2ed5 100644 --- a/kstyle/transitions/oxygenlineeditdata.h +++ b/kstyle/transitions/oxygenlineeditdata.h @@ -1,144 +1,142 @@ #ifndef oxygenlineedit_datah #define oxygenlineedit_datah ////////////////////////////////////////////////////////////////////////////// // oxygenlineeditdata.h // data container for QLineEdit transition // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygentransitiondata.h" #include #include #include namespace Oxygen { - //! generic data + //* generic data class LineEditData: public TransitionData { Q_OBJECT public: - //! constructor + //* constructor LineEditData( QObject*, QLineEdit*, int ); - //! destructor - virtual ~LineEditData( void ) - {} + //* event filter + bool eventFilter( QObject*, QEvent* ) override; - //! event filter - bool eventFilter( QObject*, QEvent* ) ; - - //! returns true if animations are locked + //* returns true if animations are locked bool isLocked( void ) const { return _animationLockTimer.isActive(); } - //! start lock animation timer + //* start lock animation timer void lockAnimations( void ) { _animationLockTimer.start( _lockTime, this ); } - //! start lock animation timer + //* start lock animation timer void unlockAnimations( void ) { _animationLockTimer.stop(); } protected Q_SLOTS: - //! text edited - virtual void textEdited( void ); + //* initialize animation + bool initializeAnimation( void ) override; + + //* animate + bool animate( void ) override; - //! selection changed - virtual void selectionChanged( void ); + protected: - //! text changed - virtual void textChanged( void ); + //* timer event + void timerEvent( QTimerEvent* ) override; - //! initialize animation - bool initializeAnimation( void ) ; + private Q_SLOTS: - //! animate - bool animate( void ) ; + //* text edited + void textEdited( void ); - //! called when target is destroyed - virtual void targetDestroyed( void ); + //* selection changed + void selectionChanged( void ); - protected: + //* text changed + void textChanged( void ); - //! timer event - void timerEvent( QTimerEvent* ) ; + //* called when target is destroyed + void targetDestroyed( void ); - //! target rect + private: + + //* target rect /*! return rect corresponding to the area to be updated when animating */ QRect targetRect( void ) const { if( !_target ) return QRect(); QRect out( _target.data()->rect() ); if( _hasClearButton && _clearButtonRect.isValid() ) { out.setRight( _clearButtonRect.left() ); } return out; } - //! check if target has clear button + //* check if target has clear button void checkClearButton( void ); - private: - - //! lock time (milliseconds + //* lock time (milliseconds static const int _lockTime; - //! timer used to disable animations when triggered too early + //* timer used to disable animations when triggered too early QBasicTimer _animationLockTimer; - //! needed to start animations out of parent paintEvent + //* needed to start animations out of parent paintEvent QBasicTimer _timer; - //! target + //* target WeakPointer _target; - //! true if target has clean button + //* true if target has clean button bool _hasClearButton; - //! clear button rect + //* clear button rect QRect _clearButtonRect; - //! true if text was manually edited + //* true if text was manually edited /*! needed to trigger animation only on programatically enabled text */ bool _edited; - //! old text + //* old text QString _text; - //! widget rect + //* widget rect /*! needed to properly handle QLabel geometry changes */ QRect _widgetRect; }; } #endif diff --git a/kstyle/transitions/oxygenlineeditengine.h b/kstyle/transitions/oxygenlineeditengine.h index c16d91f1..3d5f6658 100644 --- a/kstyle/transitions/oxygenlineeditengine.h +++ b/kstyle/transitions/oxygenlineeditengine.h @@ -1,86 +1,82 @@ #ifndef oxygenlineeditengine_h #define oxygenlineeditengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenlineeditengine.h // stores event filters and maps widgets to animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenlineeditdata.h" namespace Oxygen { - //! used for simple widgets + //* used for simple widgets class LineEditEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit LineEditEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~LineEditEngine( void ) - {} - - //! register widget - virtual bool registerWidget( QLineEdit* ); + //* register widget + bool registerWidget( QLineEdit* ); - //! duration - void setEnabled( bool value ) + //* duration + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! maps + //* maps DataMap _data; }; } #endif diff --git a/kstyle/transitions/oxygenstackedwidgetdata.h b/kstyle/transitions/oxygenstackedwidgetdata.h index 89a92002..a8f87d87 100644 --- a/kstyle/transitions/oxygenstackedwidgetdata.h +++ b/kstyle/transitions/oxygenstackedwidgetdata.h @@ -1,78 +1,76 @@ #ifndef oxygenstackedwidget_datah #define oxygenstackedwidget_datah ////////////////////////////////////////////////////////////////////////////// // oxygenstackedwidgetdata.h // data container for QStackedWidget transition // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygentransitiondata.h" #include namespace Oxygen { - //! generic data + //* generic data class StackedWidgetData: public TransitionData { Q_OBJECT public: - //! constructor + //* constructor StackedWidgetData( QObject*, QStackedWidget*, int ); - //! destructor - virtual ~StackedWidgetData( void ) - {} - protected Q_SLOTS: - //! initialize animation - bool initializeAnimation( void ) ; + //* initialize animation + bool initializeAnimation( void ) override; + + //* animate + bool animate( void ) override; - //! animate - bool animate( void ) ; + private Q_SLOTS: - //! finish animation - virtual void finishAnimation( void ); + //* finish animation + void finishAnimation( void ); - //! called when target is destroyed - virtual void targetDestroyed( void ); + //* called when target is destroyed + void targetDestroyed( void ); private: - //! target + //* target WeakPointer _target; - //! current index + //* current index int _index; }; } #endif diff --git a/kstyle/transitions/oxygenstackedwidgetengine.h b/kstyle/transitions/oxygenstackedwidgetengine.h index cde8b200..52f94780 100644 --- a/kstyle/transitions/oxygenstackedwidgetengine.h +++ b/kstyle/transitions/oxygenstackedwidgetengine.h @@ -1,86 +1,82 @@ #ifndef oxygenstackedwidgetengine_h #define oxygenstackedwidgetengine_h ////////////////////////////////////////////////////////////////////////////// // oxygenstackedwidgetengine.h // stores event filters and maps widgets to animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenbaseengine.h" #include "oxygendatamap.h" #include "oxygenstackedwidgetdata.h" namespace Oxygen { - //! used for simple widgets + //* used for simple widgets class StackedWidgetEngine: public BaseEngine { Q_OBJECT public: - //! constructor + //* constructor explicit StackedWidgetEngine( QObject* parent ): BaseEngine( parent ) {} - //! destructor - virtual ~StackedWidgetEngine( void ) - {} - - //! register widget - virtual bool registerWidget( QStackedWidget* ); + //* register widget + bool registerWidget( QStackedWidget* ); - //! duration - void setEnabled( bool value ) + //* duration + void setEnabled( bool value ) override { BaseEngine::setEnabled( value ); _data.setEnabled( value ); } - //! duration - void setDuration( int value ) + //* duration + void setDuration( int value ) override { BaseEngine::setDuration( value ); _data.setDuration( value ); } public Q_SLOTS: - //! remove widget from map - bool unregisterWidget( QObject* object ) + //* remove widget from map + bool unregisterWidget( QObject* object ) override { return _data.unregisterWidget( object ); } private: - //! maps + //* maps DataMap _data; }; } #endif diff --git a/kstyle/transitions/oxygentransitiondata.h b/kstyle/transitions/oxygentransitiondata.h index a8884dd1..7b7c69b0 100644 --- a/kstyle/transitions/oxygentransitiondata.h +++ b/kstyle/transitions/oxygentransitiondata.h @@ -1,144 +1,144 @@ #ifndef oxygentransitiondata_h #define oxygentransitiondata_h ////////////////////////////////////////////////////////////////////////////// // oxygentransitiondata.h // data container for generic transitions // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygentransitionwidget.h" #include #include #include namespace Oxygen { - //! generic data + //* generic data class TransitionData: public QObject { Q_OBJECT public: - //! constructor + //* constructor TransitionData( QObject* parent, QWidget* target, int ); - //! destructor - virtual ~TransitionData( void ); + //* destructor + ~TransitionData( void ) override; - //! enability + //* enability virtual void setEnabled( bool value ) { _enabled = value; } - //! enability + //* enability virtual bool enabled( void ) const { return _enabled; } - //! duration + //* duration virtual void setDuration( int duration ) { if( _transition ) { _transition.data()->setDuration( duration ); } } - //! max render time + //* max render time void setMaxRenderTime( int value ) { _maxRenderTime = value; } - //! max renderTime + //* max renderTime const int& maxRenderTime( void ) const { return _maxRenderTime; } - //! start clock + //* start clock void startClock( void ) { if( _clock.isNull() ) _clock.start(); else _clock.restart(); } - //! check if rendering is two slow + //* check if rendering is two slow bool slow( void ) const { return !( _clock.isNull() || _clock.elapsed() <= maxRenderTime() ); } protected Q_SLOTS: - //! initialize animation + //* initialize animation virtual bool initializeAnimation( void ) = 0; - //! animate + //* animate virtual bool animate( void ) = 0; protected: - //! returns true if one parent matches given class name + //* returns true if one parent matches given class name inline bool hasParent( const QWidget*, const char* ) const; - //! transition widget - virtual const TransitionWidget::Pointer& transition( void ) const + //* transition widget + const TransitionWidget::Pointer& transition( void ) const { return _transition; } - //! used to avoid recursion when grabbing widgets + //* used to avoid recursion when grabbing widgets void setRecursiveCheck( bool value ) { _recursiveCheck = value; } - //! used to avoid recursion when grabbing widgets + //* used to avoid recursion when grabbing widgets bool recursiveCheck( void ) const { return _recursiveCheck; } private: - //! enability + //* enability bool _enabled = true; - //! used to avoid recursion when grabbing widgets + //* used to avoid recursion when grabbing widgets bool _recursiveCheck = false; - //! timer used to detect slow rendering + //* timer used to detect slow rendering QTime _clock; - //! max render time - /*! used to detect slow rendering */ + //* max render time + /** used to detect slow rendering */ int _maxRenderTime = 200; - //! animation handling + //* animation handling TransitionWidget::Pointer _transition; }; //_____________________________________________________________________________________ bool TransitionData::hasParent( const QWidget* widget, const char* className ) const { if( !widget ) return false; for( QWidget* parent = widget->parentWidget(); parent; parent = parent->parentWidget() ) { if( parent->inherits( className ) ) return true; } return false; } } #endif diff --git a/kstyle/transitions/oxygentransitions.h b/kstyle/transitions/oxygentransitions.h index 26178afd..00906426 100644 --- a/kstyle/transitions/oxygentransitions.h +++ b/kstyle/transitions/oxygentransitions.h @@ -1,105 +1,101 @@ #ifndef oxygentransitions_h #define oxygentransitions_h ////////////////////////////////////////////////////////////////////////////// // oxygentransitions.h // container for all transition engines // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygencomboboxengine.h" #include "oxygenlabelengine.h" #include "oxygenlineeditengine.h" #include "oxygenstackedwidgetengine.h" namespace Oxygen { - //! stores engines + //* stores engines class Transitions: public QObject { Q_OBJECT public: - //! constructor + //* constructor explicit Transitions( QObject* ); - //! destructor - virtual ~Transitions( void ) - {} - - //! register animations corresponding to given widget, depending on its type. + //* register animations corresponding to given widget, depending on its type. void registerWidget( QWidget* widget ) const; - /*! unregister all animations associated to a widget */ + /** unregister all animations associated to a widget */ void unregisterWidget( QWidget* widget ) const; - //! qlabel engine + //* qlabel engine ComboBoxEngine& comboBoxEngine( void ) const { return *_comboBoxEngine; } - //! qlabel engine + //* qlabel engine LabelEngine& labelEngine( void ) const { return *_labelEngine; } - //! qlineedit engine + //* qlineedit engine LineEditEngine& lineEditEngine( void ) const { return *_lineEditEngine; } - //! stacked widget engine + //* stacked widget engine StackedWidgetEngine& stackedWidgetEngine( void ) const { return *_stackedWidgetEngine; } public Q_SLOTS: - //! setup engines + //* setup engines void setupEngines( void ); private: - //! register new engine + //* register new engine void registerEngine( BaseEngine* engine ) { _engines.push_back( engine ); } - //! qcombobox engine + //* qcombobox engine ComboBoxEngine* _comboBoxEngine; - //! qlabel engine + //* qlabel engine LabelEngine* _labelEngine; - //! qlineedit engine + //* qlineedit engine LineEditEngine* _lineEditEngine; - //! stacked widget engine + //* stacked widget engine StackedWidgetEngine* _stackedWidgetEngine; - //! keep list of existing engines + //* keep list of existing engines QList< BaseEngine::Pointer > _engines; }; } #endif diff --git a/kstyle/transitions/oxygentransitionwidget.h b/kstyle/transitions/oxygentransitionwidget.h index 1aafce9f..e2c2fedc 100644 --- a/kstyle/transitions/oxygentransitionwidget.h +++ b/kstyle/transitions/oxygentransitionwidget.h @@ -1,235 +1,232 @@ #ifndef oxygentransitionwidget_h #define oxygentransitionwidget_h ////////////////////////////////////////////////////////////////////////////// // oxygentransitionwidget.h // stores event filters and maps widgets to transitions for transitions // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenanimation.h" #include "oxygen.h" #include #include namespace Oxygen { - //! temporary widget used to perform smooth transition between one widget state and another + //* temporary widget used to perform smooth transition between one widget state and another class TransitionWidget: public QWidget { Q_OBJECT - //! declare opacity property + //* declare opacity property Q_PROPERTY( qreal opacity READ opacity WRITE setOpacity ) public: - //! shortcut to painter + //* shortcut to painter using Pointer = WeakPointer; - //! constructor + //* constructor TransitionWidget( QWidget* parent, int duration ); - //! destructor - virtual ~TransitionWidget( void ) = default; - - //!@name flags + //*@name flags //@{ enum Flag { None = 0, GrabFromWindow = 1<<0, Transparent = 1<<1, PaintOnWidget = 1<<2 }; Q_DECLARE_FLAGS(Flags, Flag) void setFlags( Flags value ) { _flags = value; } void setFlag( Flag flag, bool value = true ) { if( value ) _flags |= flag; else _flags &= (~flag); } bool testFlag( Flag flag ) const { return _flags.testFlag( flag ); } //@} - //! duration + //* duration void setDuration( int duration ) { if( _animation ) { _animation.data()->setDuration( duration ); } } - //! duration + //* duration int duration( void ) const { return ( _animation ) ? _animation.data()->duration() : 0; } - //! steps + //* steps static void setSteps( int value ) { _steps = value; } - //!@name opacity + //*@name opacity //@{ - virtual qreal opacity( void ) const + qreal opacity( void ) const { return _opacity; } - virtual void setOpacity( qreal value ) + void setOpacity( qreal value ) { value = digitize( value ); if( _opacity == value ) return; _opacity = value; update(); } //@} //@name pixmaps handling //@{ - //! start + //* start void resetStartPixmap( void ) { setStartPixmap( QPixmap() ); } - //! start + //* start void setStartPixmap( QPixmap pixmap ) { _startPixmap = pixmap; } - //! start + //* start const QPixmap& startPixmap( void ) const { return _startPixmap; } - //! end + //* end void resetEndPixmap( void ) { setEndPixmap( QPixmap() ); } - //! end + //* end void setEndPixmap( QPixmap pixmap ) { _endPixmap = pixmap; _currentPixmap = pixmap; } - //! start + //* start const QPixmap& endPixmap( void ) const { return _endPixmap; } - //! current + //* current const QPixmap& currentPixmap( void ) const { return _currentPixmap; } //@} - //! grap pixmap + //* grap pixmap QPixmap grab( QWidget* = 0, QRect = QRect() ); - //! true if animated - virtual bool isAnimated( void ) const + //* true if animated + bool isAnimated( void ) const { return _animation.data()->isRunning(); } - //! end animation - virtual void endAnimation( void ) + //* end animation + void endAnimation( void ) { if( _animation.data()->isRunning() ) _animation.data()->stop(); } - //! animate transition - virtual void animate( void ) + //* animate transition + void animate( void ) { if( _animation.data()->isRunning() ) _animation.data()->stop(); _animation.data()->start(); } - //! true if paint is enabled + //* true if paint is enabled static bool paintEnabled( void ); protected: - //! generic event filter - bool event( QEvent* ) ; + //* generic event filter + bool event( QEvent* ) override; + + //* paint event + void paintEvent( QPaintEvent* ) override; - //! paint event - void paintEvent( QPaintEvent* ) ; + private: - //! grab widget background + //* grab widget background /*! Background is not rendered properly using QWidget::render. Use home-made grabber instead. This is directly inspired from bespin. Copyright (C) 2007 Thomas Luebking */ - virtual void grabBackground( QPixmap&, QWidget*, QRect& ) const; + void grabBackground( QPixmap&, QWidget*, QRect& ) const; - //! grab widget - virtual void grabWidget( QPixmap&, QWidget*, QRect& ) const; + //* grab widget + void grabWidget( QPixmap&, QWidget*, QRect& ) const; - //! fade pixmap - virtual void fade( const QPixmap& source, QPixmap& target, qreal opacity, const QRect& ) const; + //* fade pixmap + void fade( const QPixmap& source, QPixmap& target, qreal opacity, const QRect& ) const; - //! apply step - virtual qreal digitize( const qreal& value ) const + //* apply step + qreal digitize( const qreal& value ) const { if( _steps > 0 ) return std::floor( value*_steps )/_steps; else return value; } - private: - - //! Flags + //* Flags Flags _flags = None; - //! paint enabled + //* paint enabled static bool _paintEnabled; - //! internal transition animation + //* internal transition animation Animation::Pointer _animation; - //! animation starting pixmap + //* animation starting pixmap QPixmap _startPixmap; - //! animation starting pixmap + //* animation starting pixmap QPixmap _localStartPixmap; - //! animation starting pixmap + //* animation starting pixmap QPixmap _endPixmap; - //! current pixmap + //* current pixmap QPixmap _currentPixmap; - //! current state opacity + //* current state opacity qreal _opacity = 0; - //! steps + //* steps static int _steps; }; } #endif diff --git a/liboxygen/oxygenanimation.h b/liboxygen/oxygenanimation.h index 732a7342..f461df3b 100644 --- a/liboxygen/oxygenanimation.h +++ b/liboxygen/oxygenanimation.h @@ -1,74 +1,70 @@ #ifndef oxygenanimation_h #define oxygenanimation_h ////////////////////////////////////////////////////////////////////////////// // oxygenanimation.h // stores event filters and maps widgets to animations for animations // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include #include "oxygen_export.h" #include "liboxygen.h" namespace Oxygen { class OXYGEN_EXPORT Animation: public QPropertyAnimation { Q_OBJECT public: //! TimeLine shared pointer using Pointer = WeakPointer; //! constructor Animation( int duration, QObject* parent ): QPropertyAnimation( parent ) { setDuration( duration ); } - //! destructor - virtual ~Animation( void ) - {} - //! true if running bool isRunning( void ) const { return state() == Animation::Running; } //! restart void restart( void ) { if( isRunning() ) stop(); start(); } }; } #endif diff --git a/liboxygen/oxygenanimationconfigitem.h b/liboxygen/oxygenanimationconfigitem.h index 280007a4..4f570783 100644 --- a/liboxygen/oxygenanimationconfigitem.h +++ b/liboxygen/oxygenanimationconfigitem.h @@ -1,108 +1,108 @@ #ifndef oxygenanimationconfigitem_h #define oxygenanimationconfigitem_h ////////////////////////////////////////////////////////////////////////////// // oxygenanimationconfigitem.h // animation configuration item // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygen_config_export.h" #include #include class Ui_AnimationConfigItem; namespace Oxygen { class OXYGEN_CONFIG_EXPORT AnimationConfigItem: public QWidget { Q_OBJECT public: - //! constructor + //* constructor explicit AnimationConfigItem( QWidget* parent, const QString& title = QString(), const QString& description = QString() ); - //! destructor - virtual ~AnimationConfigItem( void ); + //* destructor + ~AnimationConfigItem( void ) override; - //! title - virtual void setTitle( const QString& ); + //* title + void setTitle( const QString& ); - //! title - virtual QString title( void ) const; + //* title + QString title( void ) const; - //! description - virtual void setDescription( const QString& ); + //* description + void setDescription( const QString& ); - //! description - virtual const QString& description( void ) const + //* description + const QString& description( void ) const { return _description; } - //! enability - virtual void setEnabled( const bool& ); + //* enability + void setEnabled( const bool& ); - //! enability - virtual bool enabled( void ) const; + //* enability + bool enabled( void ) const; - //! config widget + //* config widget virtual QWidget* configurationWidget( void ) const = 0; - //! initialize config widget + //* initialize config widget virtual void initializeConfigurationWidget( QWidget* ) = 0; - //! configuration button + //* configuration button QAbstractButton* configurationButton( void ) const; Q_SIGNALS: - //! emmited when changed + //* emmited when changed void changed( void ); protected Q_SLOTS: - //! about info + //* about info virtual void about( void ); protected: - //! set configuration widget + //* set configuration widget virtual void setConfigurationWidget( QWidget* widget ); private: - //! description + //* description QString _description; - //! ui + //* ui Ui_AnimationConfigItem* ui; }; } #endif diff --git a/liboxygen/oxygenbaseanimationconfigwidget.h b/liboxygen/oxygenbaseanimationconfigwidget.h index 8dd77ae0..837dd38e 100644 --- a/liboxygen/oxygenbaseanimationconfigwidget.h +++ b/liboxygen/oxygenbaseanimationconfigwidget.h @@ -1,114 +1,114 @@ #ifndef oxygenbaseanimationconfigwidget_h #define oxygenbaseanimationconfigwidget_h ////////////////////////////////////////////////////////////////////////////// // oxygenbaseanimationconfigwidget.h // animation configuration item // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygen_config_export.h" #include #include #include class Ui_AnimationConfigWidget; namespace Oxygen { class AnimationConfigItem; class OXYGEN_CONFIG_EXPORT BaseAnimationConfigWidget: public QWidget { Q_OBJECT public: - //! constructor + //* constructor explicit BaseAnimationConfigWidget( QWidget* = 0 ); - //! destructor + //* destructor virtual ~BaseAnimationConfigWidget( void ); - //! true if changed + //* true if changed virtual bool isChanged( void ) const { return _changed; } Q_SIGNALS: - //! emmited when layout is changed + //* emmited when layout is changed void layoutChanged( void ); - //! emmited when changed + //* emmited when changed void changed( bool ); public Q_SLOTS: - //! read current configuration + //* read current configuration virtual void load( void ) = 0; - //! save current configuration + //* save current configuration virtual void save( void ) = 0; protected Q_SLOTS: - //! update visible ites + //* update visible ites virtual void updateItems( bool ); - //! check whether configuration is changed and emit appropriate signal if yes + //* check whether configuration is changed and emit appropriate signal if yes virtual void updateChanged() = 0; protected: - //! get global animations enabled checkbox + //* get global animations enabled checkbox QCheckBox* animationsEnabled( void ) const; - //! add item to ui + //* add item to ui virtual void setupItem( QGridLayout*, AnimationConfigItem* ); - //! set changed state + //* set changed state virtual void setChanged( bool value ) { _changed = value; emit changed( value ); } - //! user interface - Ui_AnimationConfigWidget* ui; + //* user interface + Ui_AnimationConfigWidget* ui = nullptr; - //! row index - int _row; + //* row index + int _row = 0; private: - //! changed state - bool _changed; + //* changed state + bool _changed = false; }; } #endif diff --git a/liboxygen/oxygengenericanimationconfigitem.cpp b/liboxygen/oxygengenericanimationconfigitem.cpp index 0f9eb7f7..74b8243f 100644 --- a/liboxygen/oxygengenericanimationconfigitem.cpp +++ b/liboxygen/oxygengenericanimationconfigitem.cpp @@ -1,63 +1,61 @@ ////////////////////////////////////////////////////////////////////////////// // oxygengenericanimationconfigitem.cpp // animation configuration item // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygengenericanimationconfigitem.h" #include "ui_oxygengenericanimationconfigbox.h" #include namespace Oxygen { //_______________________________________________ GenericAnimationConfigBox::GenericAnimationConfigBox(QWidget* parent): QFrame( parent ), - ui( new Ui_GenericAnimationConfigBox() ) - { - ui->setupUi( this ); - } + ui( new Ui_GenericAnimationConfigBox ) + { ui->setupUi( this ); } //_______________________________________________ - GenericAnimationConfigBox::~GenericAnimationConfigBox( void ) + GenericAnimationConfigBox::~GenericAnimationConfigBox() { delete ui; } //_______________________________________________ QSpinBox* GenericAnimationConfigBox::durationSpinBox( void ) const { return ui->durationSpinBox; } //_______________________________________________ void GenericAnimationConfigItem::initializeConfigurationWidget( QWidget* parent ) { Q_ASSERT( !_configurationWidget ); _configurationWidget = new GenericAnimationConfigBox( parent ); setConfigurationWidget( _configurationWidget.data() ); connect( _configurationWidget.data()->durationSpinBox(), SIGNAL(valueChanged(int)), SIGNAL(changed()) ); } } diff --git a/liboxygen/oxygengenericanimationconfigitem.h b/liboxygen/oxygengenericanimationconfigitem.h index 81a7212d..1b7e451a 100644 --- a/liboxygen/oxygengenericanimationconfigitem.h +++ b/liboxygen/oxygengenericanimationconfigitem.h @@ -1,109 +1,106 @@ #ifndef oxygengenericanimationconfigitem_h #define oxygengenericanimationconfigitem_h ////////////////////////////////////////////////////////////////////////////// // oxygengenericanimationconfigitem.h // animation configuration item // ------------------- // // Copyright (c) 2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygen_config_export.h" #include "oxygenanimationconfigitem.h" #include #include #include class Ui_GenericAnimationConfigBox; namespace Oxygen { class OXYGEN_CONFIG_EXPORT GenericAnimationConfigBox: public QFrame { Q_OBJECT public: - //! constructor + //* constructor explicit GenericAnimationConfigBox(QWidget*); - //! destructor - virtual ~GenericAnimationConfigBox( void ); + //* destructor + virtual ~GenericAnimationConfigBox(); - //! duration spin box + //* duration spin box QSpinBox* durationSpinBox( void ) const; private: - Ui_GenericAnimationConfigBox* ui; + Ui_GenericAnimationConfigBox* ui = nullptr; }; - //! generic animation config item + //* generic animation config item class OXYGEN_CONFIG_EXPORT GenericAnimationConfigItem: public AnimationConfigItem { Q_OBJECT public: - //! constructor + //* constructor explicit GenericAnimationConfigItem( QWidget* parent, const QString& title = QString(), const QString& description = QString() ): AnimationConfigItem( parent, title, description ) {} - //! configure - void initializeConfigurationWidget( QWidget* ) ; + //* configure + void initializeConfigurationWidget( QWidget* ) override; - //! configuration widget - QWidget* configurationWidget( void ) const - { - Q_CHECK_PTR( _configurationWidget ); - return _configurationWidget.data(); - } + //* configuration widget + QWidget* configurationWidget( void ) const override + { return _configurationWidget.data(); } - //! duration + //* duration virtual int duration( void ) const - { return (_configurationWidget) ? _configurationWidget.data()->durationSpinBox()->value():0; } + { return _configurationWidget ? _configurationWidget.data()->durationSpinBox()->value():0; } public Q_SLOTS: - //! duration + //* duration virtual void setDuration( int value ) { if( _configurationWidget ) { _configurationWidget.data()->durationSpinBox()->setValue( value ); } } private: - //! configuration widget + //* configuration widget QPointer _configurationWidget; }; } #endif diff --git a/liboxygen/oxygenitemmodel.h b/liboxygen/oxygenitemmodel.h index 6f17984e..394283e6 100644 --- a/liboxygen/oxygenitemmodel.h +++ b/liboxygen/oxygenitemmodel.h @@ -1,115 +1,111 @@ #ifndef ItemModel_h #define ItemModel_h ////////////////////////////////////////////////////////////////////////////// // itemmodel.h // ------------------- // // Copyright (c) 2009-2010 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygen_export.h" #include namespace Oxygen { - //! Job model. Stores job information for display in lists + //* Job model. Stores job information for display in lists class OXYGEN_EXPORT ItemModel : public QAbstractItemModel { public: - //! constructor - explicit ItemModel(QObject *parent = 0); + //* constructor + explicit ItemModel(QObject* = nullptr); - //! destructor - virtual ~ItemModel() - {} - - //! return all indexes in model starting from parent [recursive] + //* return all indexes in model starting from parent [recursive] QModelIndexList indexes( int column = 0, const QModelIndex& parent = QModelIndex() ) const; - //!@name sorting + //*@name sorting //@{ - //! sort - virtual void sort( void ) + //* sort + void sort( void ) { sort( sortColumn(), sortOrder() ); } - //! sort - void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) ; + //* sort + void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) override; - //! current sorting column - const int& sortColumn( void ) const + //* current sorting column + int sortColumn( void ) const { return _sortColumn; } - //! current sort order - const Qt::SortOrder& sortOrder( void ) const + //* current sort order + Qt::SortOrder sortOrder( void ) const { return _sortOrder; } //@} protected: - //! this sort columns without calling the layout changed callbacks + //* this sort columns without calling the layout changed callbacks void privateSort( void ) { privateSort( sortColumn(), sortOrder() ); } - //! private sort, with no signals emmitted + //* private sort, with no signals emmitted virtual void privateSort( int column, Qt::SortOrder order ) = 0; - //! used to sort items in list + //* used to sort items in list class SortFTor { public: - //! constructor + //* constructor explicit SortFTor( const int& type, Qt::SortOrder order = Qt::AscendingOrder ): _type( type ), _order( order ) {} protected: - //! column - int _type; + //* column + int _type = 0; - //! order - Qt::SortOrder _order; + //* order + Qt::SortOrder _order = Qt::AscendingOrder; }; private: - //! sorting column - int _sortColumn; + //* sorting column + int _sortColumn = 0; - //! sorting order - Qt::SortOrder _sortOrder; + //* sorting order + Qt::SortOrder _sortOrder = Qt::AscendingOrder; }; } #endif diff --git a/liboxygen/oxygenlistmodel.h b/liboxygen/oxygenlistmodel.h index e40ad58c..621833c6 100644 --- a/liboxygen/oxygenlistmodel.h +++ b/liboxygen/oxygenlistmodel.h @@ -1,366 +1,360 @@ #ifndef ListModel_h #define ListModel_h ////////////////////////////////////////////////////////////////////////////// // listmodel.h // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenitemmodel.h" #include #include #include namespace Oxygen { - //! Job model. Stores job information for display in lists + //* Job model. Stores job information for display in lists template class ListModel : public ItemModel { public: - //! value type + //* value type using ValueType = T; - //! reference + //* reference using Reference = T&; - //! pointer + //* pointer using Pointer = T*; - //! value list and iterators + //* value list and iterators using List = QList; using ListIterator = QListIterator; using MutableListIterator = QMutableListIterator; - //! constructor - ListModel(QObject *parent = 0): + //* constructor + ListModel(QObject *parent = nullptr): ItemModel( parent ) {} - //! destructor - virtual ~ListModel() - {} - - //!@name methods reimplemented from base class + //*@name methods reimplemented from base class //@{ - //! flags - Qt::ItemFlags flags(const QModelIndex &index) const + //* flags + Qt::ItemFlags flags(const QModelIndex &index) const override { if (!index.isValid()) return 0; 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 + //* 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 + //* index of parent + QModelIndex parent(const QModelIndex &) const override { return QModelIndex(); } - //! number of rows below given index - int rowCount(const QModelIndex &parent = QModelIndex()) const + //* number of rows below given index + int rowCount(const QModelIndex &parent = QModelIndex()) const override { return parent.isValid() ? 0:_values.size(); } //@} - //!@name selection + //*@name selection //@{ - //! clear internal list selected items - virtual void clearSelectedIndexes( void ) + //* clear internal list selected items + void clearSelectedIndexes( void ) { _selection.clear(); } - //! store index internal selection state - virtual void setIndexSelected( const QModelIndex& index, bool value ) + //* store index internal selection state + 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( void ) const + //* get list of internal selected items + QModelIndexList selectedIndexes( void ) 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 + //*@name interface //@{ - //! add value - virtual void add( const ValueType& value ) + //* add value + void add( const ValueType& value ) { emit layoutAboutToBeChanged(); _add( value ); privateSort(); emit layoutChanged(); } - //! add values - virtual void add( const List& values ) + //* add values + 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 ) + //* insert values + 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 ) + //* insert values + 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 ) + //* insert values + 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 ) + //* remove + void remove( const ValueType& value ) { emit layoutAboutToBeChanged(); _remove( value ); emit layoutChanged(); return; } - //! remove - virtual void remove( const List& values ) + //* remove + 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(); return; } - //! clear - virtual void clear( void ) + //* clear + void clear( void ) { set( List() ); } - //! update values from 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 ) + 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 ) + //* set all values + void set( const List& values ) { emit layoutAboutToBeChanged(); _values = values; _selection.clear(); privateSort(); emit layoutChanged(); return; } - //! return all values + //* return all values const List& get( void ) const { return _values; } - //! return value for given index - virtual ValueType get( const QModelIndex& index ) const + //* return value for given index + 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 ) + //* return value for given index + ValueType& get( const QModelIndex& index ) { Q_ASSERT( index.isValid() && index.row() < int( _values.size() ) ); return _values[index.row()]; } - //! return all values + //* 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 + //* return index associated to a given value + 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 true if model contains given index + bool contains( const QModelIndex& index ) const { return index.isValid() && index.row() < _values.size(); } - protected: + private: - //! return all values + //* return all values List& _get( void ) { return _values; } - //! add, without update - virtual void _add( const ValueType& value ) + //* add, without update + 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 ) + //* add, without update + 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 ) + //* remove, without update + 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 + //* values List _values; - //! selection + //* selection List _selection; }; } #endif diff --git a/liboxygen/oxygenshadowcache.h b/liboxygen/oxygenshadowcache.h index aad729e3..01f01b7e 100644 --- a/liboxygen/oxygenshadowcache.h +++ b/liboxygen/oxygenshadowcache.h @@ -1,204 +1,198 @@ #ifndef oxygen_shadowCacheh #define oxygen_shadowCacheh ////////////////////////////////////////////////////////////////////////////// // oxygenshadowcache.h // handles caching of TileSet objects to draw shadows // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenhelper.h" #include "oxygen_export.h" #include #include #include namespace Oxygen { class OXYGEN_EXPORT ShadowCache { public: //* constructor explicit ShadowCache( Helper& ); - //* destructor - virtual ~ShadowCache( void ) - {} - //* read configuration void readConfig( void ); //* animations duration void setAnimationsDuration( int ); //* cache size void setEnabled( bool enabled ) { _enabled = enabled; if( enabled ) { _shadowCache.setMaxCost( 1<<6 ); _animatedShadowCache.setMaxCost( _maxIndex<<6 ); } else { _shadowCache.setMaxCost( 1 ); _animatedShadowCache.setMaxCost( 1 ); } } //* max animation index int maxIndex( void ) const { return _maxIndex; } //* max animation index void setMaxIndex( int value ) { _maxIndex = value; if( _enabled ) { _shadowCache.setMaxCost( 1<<6 ); _animatedShadowCache.setMaxCost( _maxIndex<<6 ); } } //* invalidate caches void invalidateCaches( void ) { _shadowCache.clear(); _animatedShadowCache.clear(); } //* true if shadow is enabled for a given group bool isEnabled( QPalette::ColorGroup ) const; //* set shadow size manually void setShadowSize( QPalette::ColorGroup, int ); //* shadow size int shadowSize( void ) const; //* Key class to be used into QCache /*! class is entirely inline for optimization */ class Key { public: //* explicit constructor explicit Key( void ) {} //* constructor from int explicit Key( int hash ): index( hash >> 3 ), active( ( hash >> 2 )&1 ), isShade( ( hash >> 1)&1 ), hasBorder( (hash)&1 ) {} //* hash function int hash( void ) const { return ( index << 3 ) | ( active << 2 ) | ( isShade<< 1 ) | ( hasBorder ); } int index = 0; bool active = false; bool isShade = false; bool hasBorder = true; }; //* get shadow matching client TileSet tileSet( const Key& ); //* get shadow matching client and opacity TileSet tileSet( Key, qreal ); //* simple pixmap QPixmap pixmap( const Key& key ) const { return pixmap( key, key.active ); } //* simple pixmap, with opacity QPixmap animatedPixmap( const Key&, qreal opacity ); - protected: + private: Helper& helper( void ) const { return _helper; } //* simple pixmap QPixmap pixmap( const Key&, bool active ) const; //* draw gradient into rect /*! a separate method is used in order to properly account for corners */ void renderGradient( QPainter&, const QRectF&, const QRadialGradient&, bool hasBorder = true ) const; - private: - //* helper Helper& _helper; //* defines overlap between shadows and body enum { overlap = 4 }; //* caching enable state bool _enabled; //* shadow size int _activeShadowSize; //* shadow size int _inactiveShadowSize; //* max index /*! it is used to set caches max cost, and calculate animation opacity */ int _maxIndex; //* cache using TileSetCache = QCache; //* shadow cache TileSetCache _shadowCache; //* animated shadow cache TileSetCache _animatedShadowCache; }; } #endif diff --git a/liboxygen/oxygenshadowconfigwidget.cpp b/liboxygen/oxygenshadowconfigwidget.cpp index e3baf035..7cbafb3f 100644 --- a/liboxygen/oxygenshadowconfigwidget.cpp +++ b/liboxygen/oxygenshadowconfigwidget.cpp @@ -1,182 +1,180 @@ ////////////////////////////////////////////////////////////////////////////// // ShadowConfigurationui->cpp // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include "oxygenshadowconfigwidget.h" #include "oxygenactiveshadowconfiguration.h" #include "oxygeninactiveshadowconfiguration.h" #include "ui_oxygenshadowconfigurationui.h" #include "config-liboxygen.h" #include #include #include namespace Oxygen { //_________________________________________________________ ShadowConfigWidget::ShadowConfigWidget( QWidget* parent ): QGroupBox( parent ), - ui( new Ui_ShadowConfiguraionUI() ), - _group( QPalette::Inactive ), - _changed( false ) + ui( new Ui_ShadowConfiguraionUI() ) { setCheckable( true ); ui->setupUi( this ); // connections connect( ui->shadowSize, SIGNAL(valueChanged(int)), SLOT(updateChanged()) ); connect( ui->verticalOffset, SIGNAL(valueChanged(int)), SLOT(updateChanged()) ); connect( ui->innerColor, SIGNAL(changed(QColor)), SLOT(updateChanged()) ); connect( ui->outerColor, SIGNAL(changed(QColor)), SLOT(updateChanged()) ); connect( ui->useOuterColor, SIGNAL(toggled(bool)), SLOT(updateChanged()) ); connect( this, SIGNAL(toggled(bool)), SLOT(updateChanged()) ); } //_________________________________________________________ ShadowConfigWidget::~ShadowConfigWidget( void ) { delete ui; } //_________________________________________________________ void ShadowConfigWidget::save( void ) const { if( _group == QPalette::Active ) { ActiveShadowConfiguration::setShadowSize( ui->shadowSize->value() ); ActiveShadowConfiguration::setVerticalOffset( 0.1*ui->verticalOffset->value() ); ActiveShadowConfiguration::setInnerColor( ui->innerColor->color() ); ActiveShadowConfiguration::setOuterColor( ui->outerColor->color() ); ActiveShadowConfiguration::setUseOuterColor( ui->useOuterColor->isChecked() ); ActiveShadowConfiguration::setEnabled( isChecked() ); #if OXYGEN_USE_KDE4 ActiveShadowConfiguration::self()->writeConfig(); #else ActiveShadowConfiguration::self()->save(); #endif } else if( _group == QPalette::Inactive ) { InactiveShadowConfiguration::setShadowSize( ui->shadowSize->value() ); InactiveShadowConfiguration::setVerticalOffset( 0.1*ui->verticalOffset->value() ); InactiveShadowConfiguration::setInnerColor( ui->innerColor->color() ); InactiveShadowConfiguration::setOuterColor( ui->outerColor->color() ); InactiveShadowConfiguration::setUseOuterColor( ui->useOuterColor->isChecked() ); InactiveShadowConfiguration::setEnabled( isChecked() ); #if OXYGEN_USE_KDE4 InactiveShadowConfiguration::self()->writeConfig(); #else InactiveShadowConfiguration::self()->save(); #endif } } //_________________________________________________________ void ShadowConfigWidget::updateChanged( void ) { if( _group == QPalette::Active ) { setChanged( ( ui->shadowSize->value() != ActiveShadowConfiguration::shadowSize() ) || ( ui->verticalOffset->value() != 10*ActiveShadowConfiguration::verticalOffset() ) || ( ui->innerColor->color() != ActiveShadowConfiguration::innerColor() ) || ( ui->useOuterColor->isChecked() != ActiveShadowConfiguration::useOuterColor() ) || ( ui->outerColor->color() != ActiveShadowConfiguration::outerColor() ) || ( isChecked() != ActiveShadowConfiguration::enabled() ) ); } else if( _group == QPalette::Inactive ) { setChanged( ( ui->shadowSize->value() != InactiveShadowConfiguration::shadowSize() ) || ( ui->verticalOffset->value() != 10*InactiveShadowConfiguration::verticalOffset() ) || ( ui->innerColor->color() != InactiveShadowConfiguration::innerColor() ) || ( ui->useOuterColor->isChecked() != InactiveShadowConfiguration::useOuterColor() ) || ( ui->outerColor->color() != InactiveShadowConfiguration::outerColor() ) || ( isChecked() != InactiveShadowConfiguration::enabled() ) ); } } //_________________________________________________________ void ShadowConfigWidget::load( bool defaults ) { if( _group == QPalette::Active ) { if( defaults ) ActiveShadowConfiguration::self()->setDefaults(); else { #if OXYGEN_USE_KDE4 ActiveShadowConfiguration::self()->readConfig(); #else ActiveShadowConfiguration::self()->load(); #endif } ui->shadowSize->setValue( ActiveShadowConfiguration::shadowSize() ); ui->verticalOffset->setValue( 10*ActiveShadowConfiguration::verticalOffset() ); ui->innerColor->setColor( ActiveShadowConfiguration::innerColor() ); ui->outerColor->setColor( ActiveShadowConfiguration::outerColor() ); ui->useOuterColor->setChecked( ActiveShadowConfiguration::useOuterColor() ); setChecked( ActiveShadowConfiguration::enabled() ); } else if( _group == QPalette::Inactive ) { if( defaults ) InactiveShadowConfiguration::self()->setDefaults(); else { #if OXYGEN_USE_KDE4 InactiveShadowConfiguration::self()->readConfig(); #else InactiveShadowConfiguration::self()->load(); #endif } ui->shadowSize->setValue( InactiveShadowConfiguration::shadowSize() ); ui->verticalOffset->setValue( 10*InactiveShadowConfiguration::verticalOffset() ); ui->innerColor->setColor( InactiveShadowConfiguration::innerColor() ); ui->outerColor->setColor( InactiveShadowConfiguration::outerColor() ); ui->useOuterColor->setChecked( InactiveShadowConfiguration::useOuterColor() ); setChecked( InactiveShadowConfiguration::enabled() ); } } } diff --git a/liboxygen/oxygenshadowconfigwidget.h b/liboxygen/oxygenshadowconfigwidget.h index cc9b3c4e..9fa72a50 100644 --- a/liboxygen/oxygenshadowconfigwidget.h +++ b/liboxygen/oxygenshadowconfigwidget.h @@ -1,110 +1,108 @@ #ifndef ShadowConfigWidget_h #define ShadowConfigWidget_h ////////////////////////////////////////////////////////////////////////////// // ShadowConfigWidget.h // ------------------- // // Copyright (c) 2009 Hugo Pereira Da Costa // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. ////////////////////////////////////////////////////////////////////////////// #include #include #include #include "oxygen_config_export.h" // forward declaration class Ui_ShadowConfiguraionUI; namespace Oxygen { - //! shadow configuration widget + //* shadow configuration widget class OXYGEN_CONFIG_EXPORT ShadowConfigWidget: public QGroupBox { Q_OBJECT public: - //! constructor + //* constructor explicit ShadowConfigWidget( QWidget* ); - //! destructor - virtual ~ShadowConfigWidget( void ); + //* destructor + ~ShadowConfigWidget( void ) override; - //! group + //* group void setGroup( QPalette::ColorGroup group ) { _group = group; } - //! read defaults + //* read defaults void setDefaults( void ) { load(true ); } - //! read config + //* read config void load( void ) { load( false ); } - //! write config + //* write config void save( void ) const; - //! true if modified + //* true if modified bool isChanged( void ) const { return _changed; } Q_SIGNALS: - //! emmitted when configuration is changed + //* emmitted when configuration is changed void changed( bool ); - protected Q_SLOTS: + private Q_SLOTS: - //! update changed state - virtual void updateChanged(); + //* update changed state + void updateChanged(); - protected: + private: - //! read config + //* read config void load( bool ); - //! set changed state - virtual void setChanged( bool value ) + //* set changed state + void setChanged( bool value ) { _changed = value; emit changed( value ); } - private: - - //! ui - Ui_ShadowConfiguraionUI* ui; + //* ui + Ui_ShadowConfiguraionUI* ui = nullptr; - //! color group - QPalette::ColorGroup _group; + //* color group + QPalette::ColorGroup _group = QPalette::Inactive; - //! changed state - bool _changed; + //* changed state + bool _changed = false; }; } #endif diff --git a/liboxygen/oxygentileset.h b/liboxygen/oxygentileset.h index 961c4ce9..43335f59 100644 --- a/liboxygen/oxygentileset.h +++ b/liboxygen/oxygentileset.h @@ -1,175 +1,169 @@ #ifndef oxygentileset_h #define oxygentileset_h /* * Copyright 2009-2010 Hugo Pereira Da Costa * Copyright 2008 Long Huynh Huu * Copyright 2007 Matthew Woehlke * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License version 2 as published by the Free Software Foundation. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "oxygen_export.h" #include #include #include //* handles proper scaling of pixmap to match widget rect. /** tilesets are collections of stretchable pixmaps corresponding to a given widget corners, sides, and center. corner pixmaps are never stretched. center pixmaps are */ namespace Oxygen { - class OXYGEN_EXPORT TileSet + class OXYGEN_EXPORT TileSet final { public: //* default size for tileset tiles enum { DefaultSize = 7 }; /** Create a TileSet from a pixmap. The size of the bottom/right chunks is whatever is left over from the other chunks, whose size is specified in the required parameters. @param w1 width of the left chunks @param h1 height of the top chunks @param w2 width of the not-left-or-right chunks @param h2 height of the not-top-or-bottom chunks */ TileSet(const QPixmap&, int w1, int h1, int w2, int h2 ); /** Create a TileSet from a pixmap. The size of the top/left and bottom/right chunks is specified, with the middle chunks created from the specified portion of the pixmap. This allows the middle chunks to overlap the outer chunks (or to not use all pixels). The top/left and bottom/right chunks are carved out of the corners of the pixmap. @param w1 width of the left chunks @param h1 height of the top chunks @param w3 width of the right chunks @param h3 height of bottom chunks @param x2 x-coordinate of the top of the not-left-or-right chunks @param y2 y-coordinate of the left of the not-top-or-bottom chunks @param w2 width of the not-left-or-right chunks @param h2 height of the not-top-or-bottom chunks */ TileSet(const QPixmap &pix, int w1, int h1, int w3, int h3, int x2, int y2, int w2, int h2 ); //* empty constructor TileSet(); - //* destructor - virtual ~TileSet() - {} - /** Flags specifying what sides to draw in ::render. Corners are drawn when the sides forming that corner are drawn, e.g. Top|Left draws the top-center, center-left, and top-left chunks. The center-center chunk is only drawn when Center is requested. */ enum Tile { Top = 0x1, Left = 0x2, Bottom = 0x4, Right = 0x8, Center = 0x10, TopLeft = Top|Left, TopRight = Top|Right, BottomLeft = Bottom|Left, BottomRight = Bottom|Right, Ring = Top|Left|Bottom|Right, Horizontal = Left|Right|Center, Vertical = Top|Bottom|Center, Full = Ring|Center }; Q_DECLARE_FLAGS(Tiles, Tile) /** Adjust rect to deal with missing tiles This will extend the relevant side so that the missing tiles extends beyond the rect passed as argument */ QRect adjust( const QRect&, Tiles ) const; /** Fills the specified rect with tiled chunks. Corners are never tiled, edges are tiled in one direction, and the center chunk is tiled in both directions. Partial tiles are used as needed so that the entire rect is perfectly filled. Filling is performed as if all chunks are being drawn. */ void render(const QRect&, QPainter*, Tiles = Ring) const; //* return size associated to this tileset QSize size( void ) const { return QSize( _w1 + _w3, _h1 + _h3 ); } //* is valid bool isValid( void ) const { return _pixmaps.size() == 9; } //* side extend /** it is used to (pre) tile the side pixmaps, in order to make further tiling faster when rendering, at the cost of using more memory for the cache. Changes to this member only affects tilesets that are created afterwards. */ void setSideExtent( int value ) { _sideExtent = value; } //* returns pixmap for given index QPixmap pixmap( int index ) const { return _pixmaps[index]; } - protected: + private: //* shortcut to pixmap list using PixmapList = QVector; //* initialize pixmap void initPixmap( PixmapList&, const QPixmap&, int w, int h, const QRect& ); - private: - //* side extend /** it is used to (pre) tile the side pixmaps, in order to make further tiling faster when rendering, at the cost of using more memory for the cache. */ static int _sideExtent; //* pixmap arry PixmapList _pixmaps; // dimensions - int _w1; - int _h1; - int _w3; - int _h3; + int _w1 = 0; + int _h1 = 0; + int _w3 = 0; + int _h3 = 0; }; } Q_DECLARE_OPERATORS_FOR_FLAGS(Oxygen::TileSet::Tiles) #endif //TILESET_H