Commit b3bedbd6 authored by Frédéric Larue's avatar Frédéric Larue
Browse files

First version of ThemeSettingsDialog plugged to the corresponding menu action.

parent 2c0c6e03
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#include <UIMainWindow.h>
#include <ThemeSettingsDialog.h>
ThemeSettingsDialog::ThemeSettingsDialog( QWidget *parent ) : QDialog( parent )
{
// Setup the dialog grid layout.
QGridLayout *l = new QGridLayout();
l->setSpacing( 0 );
setLayout( l );
// Define horizontal labels corresponding to color group names.
int buttonWidth = 0;
for( int i=0; i<QPalette::NColorGroups; ++i )
{
QString groupName = PaletteDictionary::ColorGroupName( (QPalette::ColorGroup) i );
groupName[0] = groupName[0].toUpper();
l->addWidget( new QLabel(groupName), 0, i+1, Qt::AlignHCenter );
int w = QApplication::fontMetrics().width( groupName ) + 10;
if( w > buttonWidth )
buttonWidth = w;
}
// Define vertical labels corresponding to color role names.
for( int i=0; i<QPalette::NColorRoles; ++i )
{
QString roleName = PaletteDictionary::ColorRoleName( (QPalette::ColorRole) i );
for( int j=0; j<roleName.length(); ++j )
if( j == 0 || roleName[j-1] == '-' )
roleName[j] = roleName[j].toUpper();
l->addWidget( new QLabel(roleName.remove('-')), i+1, 0 );
}
// Create the matrix made of buttons corresponding to the palette colors.
for( int i=0; i<QPalette::NColorGroups; ++i )
for( int j=0; j<QPalette::NColorRoles; ++j )
{
QPushButton *b = new QPushButton( QString::number(j*QPalette::NColorGroups+i) );
b->setMinimumWidth( buttonWidth );
QColor c = QApplication::palette().color( (QPalette::ColorGroup) i, (QPalette::ColorRole) j );
setButtonColor( b, c );
connect( b, SIGNAL(clicked(bool)), this, SLOT(onColorButtonTrigger()) );
l->addWidget( b, j+1, i+1 );
}
}
void ThemeSettingsDialog::setButtonColor( QPushButton *button, const QColor& c )
{
QString colorString = "rgb(" + QString::number(c.red()) + "," + QString::number(c.green()) + "," + QString::number(c.blue()) + ")";
QString styleSheet = "QPushButton { border-radius:0; background-color:"+colorString+"; color:"+colorString+"; }";
button->setStyleSheet( styleSheet );
}
void ThemeSettingsDialog::onColorButtonTrigger()
{
QPushButton *src = (QPushButton*) sender();
int n = src->text().toInt();
QPalette::ColorGroup group = (QPalette::ColorGroup)( n % QPalette::NColorGroups );
QPalette::ColorRole role = (QPalette::ColorRole )( n / QPalette::NColorGroups );
QPalette palette = QApplication::palette();
QColor currentColor = palette.color( group, role );
QColor newColor = QColorDialog::getColor( currentColor, this );
if( newColor.isValid() )
{
setButtonColor( src, newColor );
palette.setColor( group, role, newColor );
QApplication::setPalette( palette );
QApplication* app = (QApplication*) QApplication::instance();
app->setStyleSheet( app->styleSheet() );
}
}
/*
* (c) LSIIT, UMR CNRS/UdS
* Authors: F. Larue.
*
* See licence.txt for additional information.
*/
#ifndef __THEMESETTINGSDIALOG_H__
#define __THEMESETTINGSDIALOG_H__
#include <PaletteDictionary.h>
#include <QtWidgets>
class ThemeSettingsDialog : public QDialog
{
Q_OBJECT
public:
ThemeSettingsDialog( QWidget *parent = NULL );
void setButtonColor( QPushButton *button, const QColor& c );
public slots:
void onColorButtonTrigger();
};
#endif //__THEMESETTINGSDIALOG_H__
......@@ -24,6 +24,7 @@
#include "UIDataWidget.h"
#include "Interfaces.h"
#include "UIParamDialog.h"
#include "ThemeSettingsDialog.h"
#include "NodeEditor.h"
//#include "ShaderGraph.h"
......@@ -235,6 +236,7 @@ void UIMainWindow::init()
connect( ui->actionWireframeMode, SIGNAL(triggered()), this, SLOT(toWireframeMode()) );
connect( ui->actionSolidMode, SIGNAL(triggered()), this, SLOT(toSolidMode()) );
connect( m_CurrentViewer, SIGNAL(keyPressed(QKeyEvent*)), this, SLOT(keyPressedInGLViewer(QKeyEvent*)) );
connect( ui->actionCustomizeTheme, SIGNAL(triggered()), this, SLOT(showThemeSettingsDialog()) );
ui->actionSolidMode->setVisible( false );
......@@ -1948,3 +1950,10 @@ void UIMainWindow::customMenuActionTriggered()
if( act )
onCustomMenuActionTriggered( act );
}
void UIMainWindow::showThemeSettingsDialog()
{
ThemeSettingsDialog dlg;
dlg.exec();
}
......@@ -155,6 +155,7 @@ private slots:
void keyPressedInGLViewer( QKeyEvent *evt ) { additionalGLViewerHotkeys( evt ); }
void customMenuActionTriggered();
void selectionChanged();
void showThemeSettingsDialog();
public slots:
void toolExecutionFinished( bool needUpdate );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment