Tweaking color button menu.
This commit is contained in:
+19
-10
@@ -22,6 +22,9 @@
|
|||||||
|
|
||||||
#include "ColorSwatch.h"
|
#include "ColorSwatch.h"
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QtDebug>
|
||||||
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -50,10 +53,16 @@ namespace glabels
|
|||||||
setCheckable( true );
|
setCheckable( true );
|
||||||
|
|
||||||
mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color );
|
mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color );
|
||||||
mDialog->setModal( true );
|
//mDialog->setModal( true );
|
||||||
|
|
||||||
connect( this, SIGNAL(pressed()), this, SLOT(onButtonPressed()) );
|
mMenu = new QMenu();
|
||||||
connect( mDialog, SIGNAL(colorChanged(colorNode,bool)), this, SLOT(onColorPaletteDialogChanged(colorNode,bool)) );
|
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 )
|
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() ) ) );
|
||||||
|
setText( "" );
|
||||||
|
|
||||||
|
mMenu->setVisible( false );
|
||||||
|
|
||||||
emit colorChanged();
|
emit colorChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ namespace glabels
|
|||||||
// Slots
|
// Slots
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
private slots:
|
private slots:
|
||||||
void onButtonPressed();
|
|
||||||
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
|
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
|
||||||
|
|
||||||
|
|
||||||
@@ -88,6 +87,7 @@ namespace glabels
|
|||||||
ColorNode mColorNode;
|
ColorNode mColorNode;
|
||||||
|
|
||||||
ColorPaletteDialog* mDialog;
|
ColorPaletteDialog* mDialog;
|
||||||
|
QMenu* mMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -123,6 +124,7 @@ namespace glabels
|
|||||||
///
|
///
|
||||||
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
|
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
|
||||||
{
|
{
|
||||||
|
event->ignore(); // Allow event to propagate to parent
|
||||||
emit activated();
|
emit activated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,11 +87,15 @@ namespace glabels
|
|||||||
mColorHistory = ColorHistory::instance();
|
mColorHistory = ColorHistory::instance();
|
||||||
connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) );
|
connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) );
|
||||||
|
|
||||||
|
mDefaultColor = defaultColor;
|
||||||
|
mColorNode = ColorNode( color );
|
||||||
|
|
||||||
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 );
|
||||||
|
|
||||||
ColorPaletteButtonItem* defaultButton = new ColorPaletteButtonItem( defaultLabel );
|
ColorPaletteButtonItem* defaultButton = new ColorPaletteButtonItem( defaultLabel );
|
||||||
|
connect( defaultButton, SIGNAL(activated()), this, SLOT(onDefaultItemActivated()) );
|
||||||
vLayout->addWidget( defaultButton );
|
vLayout->addWidget( defaultButton );
|
||||||
|
|
||||||
QFrame* hline1 = new QFrame;
|
QFrame* hline1 = new QFrame;
|
||||||
@@ -141,6 +145,7 @@ namespace glabels
|
|||||||
vLayout->addWidget( hline3 );
|
vLayout->addWidget( hline3 );
|
||||||
|
|
||||||
ColorPaletteButtonItem* customColorButton = new ColorPaletteButtonItem( tr("Custom color") );
|
ColorPaletteButtonItem* customColorButton = new ColorPaletteButtonItem( tr("Custom color") );
|
||||||
|
connect( customColorButton, SIGNAL(activated()), this, SLOT(onCustomColorItemActivated()) );
|
||||||
vLayout->addWidget( customColorButton );
|
vLayout->addWidget( customColorButton );
|
||||||
|
|
||||||
QFrame* hline4 = new QFrame;
|
QFrame* hline4 = new QFrame;
|
||||||
@@ -175,7 +180,6 @@ namespace glabels
|
|||||||
mColorNode.setColor( mDefaultColor );
|
mColorNode.setColor( mDefaultColor );
|
||||||
mColorNode.setKey( "" );
|
mColorNode.setKey( "" );
|
||||||
|
|
||||||
setVisible( false );
|
|
||||||
emit colorChanged( mColorNode, true );
|
emit colorChanged( mColorNode, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,7 +190,6 @@ namespace glabels
|
|||||||
mColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
|
mColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
|
||||||
mColorNode.setKey( "" );
|
mColorNode.setKey( "" );
|
||||||
|
|
||||||
setVisible( false );
|
|
||||||
emit colorChanged( mColorNode, false );
|
emit colorChanged( mColorNode, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,14 +200,12 @@ namespace glabels
|
|||||||
mColorNode.setColor( mColorHistory->getColor( id ) );
|
mColorNode.setColor( mColorHistory->getColor( id ) );
|
||||||
mColorNode.setKey( "" );
|
mColorNode.setKey( "" );
|
||||||
|
|
||||||
setVisible( false );
|
|
||||||
emit colorChanged( mColorNode, false );
|
emit colorChanged( mColorNode, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ColorPaletteDialog::onCustomColorItemActivated()
|
void ColorPaletteDialog::onCustomColorItemActivated()
|
||||||
{
|
{
|
||||||
setVisible( false );
|
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -162,6 +163,7 @@ 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