Tweaking color button menu.
This commit is contained in:
+19
-10
@@ -22,6 +22,9 @@
|
||||
|
||||
#include "ColorSwatch.h"
|
||||
#include <QIcon>
|
||||
#include <QMenu>
|
||||
#include <QHBoxLayout>
|
||||
#include <QtDebug>
|
||||
|
||||
|
||||
namespace
|
||||
@@ -50,10 +53,16 @@ namespace glabels
|
||||
setCheckable( true );
|
||||
|
||||
mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color );
|
||||
mDialog->setModal( true );
|
||||
//mDialog->setModal( true );
|
||||
|
||||
connect( this, SIGNAL(pressed()), this, SLOT(onButtonPressed()) );
|
||||
connect( mDialog, SIGNAL(colorChanged(colorNode,bool)), this, SLOT(onColorPaletteDialogChanged(colorNode,bool)) );
|
||||
mMenu = new QMenu();
|
||||
QHBoxLayout* layout = new QHBoxLayout;
|
||||
layout->addWidget( mDialog );
|
||||
mMenu->setLayout( layout );
|
||||
setMenu( mMenu );
|
||||
|
||||
connect( mDialog, SIGNAL(colorChanged(ColorNode,bool)),
|
||||
this, SLOT(onPaletteDialogChanged(ColorNode,bool)) );
|
||||
}
|
||||
|
||||
|
||||
@@ -121,18 +130,18 @@ namespace glabels
|
||||
}
|
||||
|
||||
|
||||
void ColorButton::onButtonPressed()
|
||||
{
|
||||
// TODO: move dialog -- see menu_position_function is VALA version
|
||||
mDialog->show();
|
||||
}
|
||||
|
||||
|
||||
void ColorButton::onPaletteDialogChanged( ColorNode colorNode, bool isDefault )
|
||||
{
|
||||
qDebug() << "Palette Dialog Changed.";
|
||||
|
||||
mColorNode = colorNode;
|
||||
mIsDefault = isDefault;
|
||||
|
||||
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
|
||||
setText( "" );
|
||||
|
||||
mMenu->setVisible( false );
|
||||
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@ namespace glabels
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onButtonPressed();
|
||||
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
|
||||
|
||||
|
||||
@@ -88,6 +87,7 @@ namespace glabels
|
||||
ColorNode mColorNode;
|
||||
|
||||
ColorPaletteDialog* mDialog;
|
||||
QMenu* mMenu;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
//
|
||||
@@ -123,6 +124,7 @@ namespace glabels
|
||||
///
|
||||
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
event->ignore(); // Allow event to propagate to parent
|
||||
emit activated();
|
||||
}
|
||||
|
||||
|
||||
@@ -87,11 +87,15 @@ namespace glabels
|
||||
mColorHistory = ColorHistory::instance();
|
||||
connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) );
|
||||
|
||||
mDefaultColor = defaultColor;
|
||||
mColorNode = ColorNode( color );
|
||||
|
||||
QVBoxLayout* vLayout = new QVBoxLayout();
|
||||
vLayout->setContentsMargins( 0, 0, 0, 0 );
|
||||
vLayout->setSpacing( 0 );
|
||||
|
||||
ColorPaletteButtonItem* defaultButton = new ColorPaletteButtonItem( defaultLabel );
|
||||
connect( defaultButton, SIGNAL(activated()), this, SLOT(onDefaultItemActivated()) );
|
||||
vLayout->addWidget( defaultButton );
|
||||
|
||||
QFrame* hline1 = new QFrame;
|
||||
@@ -141,6 +145,7 @@ namespace glabels
|
||||
vLayout->addWidget( hline3 );
|
||||
|
||||
ColorPaletteButtonItem* customColorButton = new ColorPaletteButtonItem( tr("Custom color") );
|
||||
connect( customColorButton, SIGNAL(activated()), this, SLOT(onCustomColorItemActivated()) );
|
||||
vLayout->addWidget( customColorButton );
|
||||
|
||||
QFrame* hline4 = new QFrame;
|
||||
@@ -175,7 +180,6 @@ namespace glabels
|
||||
mColorNode.setColor( mDefaultColor );
|
||||
mColorNode.setKey( "" );
|
||||
|
||||
setVisible( false );
|
||||
emit colorChanged( mColorNode, true );
|
||||
}
|
||||
|
||||
@@ -186,7 +190,6 @@ namespace glabels
|
||||
mColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
|
||||
mColorNode.setKey( "" );
|
||||
|
||||
setVisible( false );
|
||||
emit colorChanged( mColorNode, false );
|
||||
}
|
||||
|
||||
@@ -197,14 +200,12 @@ namespace glabels
|
||||
mColorNode.setColor( mColorHistory->getColor( id ) );
|
||||
mColorNode.setKey( "" );
|
||||
|
||||
setVisible( false );
|
||||
emit colorChanged( mColorNode, false );
|
||||
}
|
||||
|
||||
|
||||
void ColorPaletteDialog::onCustomColorItemActivated()
|
||||
{
|
||||
setVisible( false );
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
//
|
||||
@@ -162,6 +163,7 @@ namespace glabels
|
||||
///
|
||||
void ColorPaletteItem::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
event->ignore(); // Allow event to propagate to parent
|
||||
emit activated( mId );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user