More tweaking of color button and dialog.
This commit is contained in:
+30
-12
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include "ColorSwatch.h"
|
#include "ColorSwatch.h"
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QMenu>
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
|
||||||
@@ -53,16 +52,12 @@ namespace glabels
|
|||||||
setCheckable( true );
|
setCheckable( true );
|
||||||
|
|
||||||
mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color );
|
mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color );
|
||||||
//mDialog->setModal( true );
|
|
||||||
|
|
||||||
mMenu = new QMenu();
|
|
||||||
QHBoxLayout* layout = new QHBoxLayout;
|
|
||||||
layout->addWidget( mDialog );
|
|
||||||
mMenu->setLayout( layout );
|
|
||||||
setMenu( mMenu );
|
|
||||||
|
|
||||||
|
connect( this, SIGNAL(toggled(bool)), this, SLOT(onButtonToggled(bool)) );
|
||||||
connect( mDialog, SIGNAL(colorChanged(ColorNode,bool)),
|
connect( mDialog, SIGNAL(colorChanged(ColorNode,bool)),
|
||||||
this, SLOT(onPaletteDialogChanged(ColorNode,bool)) );
|
this, SLOT(onPaletteDialogChanged(ColorNode,bool)) );
|
||||||
|
connect( mDialog, SIGNAL(accepted()), this, SLOT(onPaletteDialogAccepted()) );
|
||||||
|
connect( mDialog, SIGNAL(rejected()), this, SLOT(onPaletteDialogRejected()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,18 +124,41 @@ namespace glabels
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ColorButton::onButtonToggled( bool checked )
|
||||||
|
{
|
||||||
|
if ( checked )
|
||||||
|
{
|
||||||
|
///
|
||||||
|
/// @TODO: improve positioning of dialog -- near edges of screen.
|
||||||
|
///
|
||||||
|
QPoint dialogPos( 0, height() );
|
||||||
|
mDialog->move( mapToGlobal(dialogPos) );
|
||||||
|
|
||||||
|
mDialog->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ColorButton::onPaletteDialogAccepted()
|
||||||
|
{
|
||||||
|
setChecked( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ColorButton::onPaletteDialogRejected()
|
||||||
|
{
|
||||||
|
setChecked( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorButton::onPaletteDialogChanged( ColorNode colorNode, bool isDefault )
|
void ColorButton::onPaletteDialogChanged( ColorNode colorNode, bool isDefault )
|
||||||
{
|
{
|
||||||
qDebug() << "Palette Dialog Changed.";
|
|
||||||
|
|
||||||
mColorNode = colorNode;
|
mColorNode = colorNode;
|
||||||
mIsDefault = isDefault;
|
mIsDefault = isDefault;
|
||||||
|
|
||||||
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
|
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
|
||||||
setText( "" );
|
setText( "" );
|
||||||
|
|
||||||
mMenu->setVisible( false );
|
|
||||||
|
|
||||||
emit colorChanged();
|
emit colorChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ namespace glabels
|
|||||||
// Slots
|
// Slots
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
private slots:
|
private slots:
|
||||||
|
void onButtonToggled( bool checked );
|
||||||
|
void onPaletteDialogAccepted();
|
||||||
|
void onPaletteDialogRejected();
|
||||||
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
|
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +90,6 @@ namespace glabels
|
|||||||
ColorNode mColorNode;
|
ColorNode mColorNode;
|
||||||
|
|
||||||
ColorPaletteDialog* mDialog;
|
ColorPaletteDialog* mDialog;
|
||||||
QMenu* mMenu;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ namespace glabels
|
|||||||
///
|
///
|
||||||
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
|
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
event->ignore(); // Allow event to propagate to parent
|
|
||||||
emit activated();
|
emit activated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,9 @@ namespace glabels
|
|||||||
mDefaultColor = defaultColor;
|
mDefaultColor = defaultColor;
|
||||||
mColorNode = ColorNode( color );
|
mColorNode = ColorNode( color );
|
||||||
|
|
||||||
|
setStyleSheet( "background: white; border: 1px solid black" );
|
||||||
|
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
|
||||||
|
|
||||||
QVBoxLayout* vLayout = new QVBoxLayout();
|
QVBoxLayout* vLayout = new QVBoxLayout();
|
||||||
vLayout->setContentsMargins( 0, 0, 0, 0 );
|
vLayout->setContentsMargins( 0, 0, 0, 0 );
|
||||||
vLayout->setSpacing( 0 );
|
vLayout->setSpacing( 0 );
|
||||||
@@ -181,6 +184,7 @@ namespace glabels
|
|||||||
mColorNode.setKey( "" );
|
mColorNode.setKey( "" );
|
||||||
|
|
||||||
emit colorChanged( mColorNode, true );
|
emit colorChanged( mColorNode, true );
|
||||||
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -191,6 +195,7 @@ namespace glabels
|
|||||||
mColorNode.setKey( "" );
|
mColorNode.setKey( "" );
|
||||||
|
|
||||||
emit colorChanged( mColorNode, false );
|
emit colorChanged( mColorNode, false );
|
||||||
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -201,12 +206,14 @@ namespace glabels
|
|||||||
mColorNode.setKey( "" );
|
mColorNode.setKey( "" );
|
||||||
|
|
||||||
emit colorChanged( mColorNode, false );
|
emit colorChanged( mColorNode, false );
|
||||||
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorPaletteDialog::onCustomColorItemActivated()
|
void ColorPaletteDialog::onCustomColorItemActivated()
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
|
accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,6 @@ namespace glabels
|
|||||||
///
|
///
|
||||||
void ColorPaletteItem::mousePressEvent( QMouseEvent* event )
|
void ColorPaletteItem::mousePressEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
event->ignore(); // Allow event to propagate to parent
|
|
||||||
emit activated( mId );
|
emit activated( mId );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user