More tweaking of color button and dialog.
This commit is contained in:
+31
-13
@@ -22,7 +22,6 @@
|
||||
|
||||
#include "ColorSwatch.h"
|
||||
#include <QIcon>
|
||||
#include <QMenu>
|
||||
#include <QHBoxLayout>
|
||||
#include <QtDebug>
|
||||
|
||||
@@ -53,16 +52,12 @@ namespace glabels
|
||||
setCheckable( true );
|
||||
|
||||
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)),
|
||||
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 )
|
||||
{
|
||||
qDebug() << "Palette Dialog Changed.";
|
||||
|
||||
mColorNode = colorNode;
|
||||
mIsDefault = isDefault;
|
||||
|
||||
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
|
||||
setText( "" );
|
||||
|
||||
mMenu->setVisible( false );
|
||||
|
||||
|
||||
emit colorChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,9 @@ namespace glabels
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onButtonToggled( bool checked );
|
||||
void onPaletteDialogAccepted();
|
||||
void onPaletteDialogRejected();
|
||||
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
|
||||
|
||||
|
||||
@@ -87,7 +90,6 @@ namespace glabels
|
||||
ColorNode mColorNode;
|
||||
|
||||
ColorPaletteDialog* mDialog;
|
||||
QMenu* mMenu;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -124,7 +124,6 @@ namespace glabels
|
||||
///
|
||||
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
event->ignore(); // Allow event to propagate to parent
|
||||
emit activated();
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,9 @@ namespace glabels
|
||||
mDefaultColor = defaultColor;
|
||||
mColorNode = ColorNode( color );
|
||||
|
||||
setStyleSheet( "background: white; border: 1px solid black" );
|
||||
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
|
||||
|
||||
QVBoxLayout* vLayout = new QVBoxLayout();
|
||||
vLayout->setContentsMargins( 0, 0, 0, 0 );
|
||||
vLayout->setSpacing( 0 );
|
||||
@@ -181,6 +184,7 @@ namespace glabels
|
||||
mColorNode.setKey( "" );
|
||||
|
||||
emit colorChanged( mColorNode, true );
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
@@ -191,6 +195,7 @@ namespace glabels
|
||||
mColorNode.setKey( "" );
|
||||
|
||||
emit colorChanged( mColorNode, false );
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
@@ -201,12 +206,14 @@ namespace glabels
|
||||
mColorNode.setKey( "" );
|
||||
|
||||
emit colorChanged( mColorNode, false );
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
void ColorPaletteDialog::onCustomColorItemActivated()
|
||||
{
|
||||
// TODO
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -163,7 +163,6 @@ 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