Added field button, menu, and menu item classes.

This commit is contained in:
Jim Evins
2014-07-19 13:37:11 -04:00
parent f3c164e308
commit 06ff813618
7 changed files with 486 additions and 0 deletions
+6
View File
@@ -15,6 +15,9 @@ set (glabels_sources
ColorPaletteDialog.cpp
ColorPaletteItem.cpp
ColorSwatch.cpp
FieldButton.cpp
FieldMenu.cpp
FieldMenuItem.cpp
File.cpp
Help.cpp
LabelModel.cpp
@@ -40,6 +43,9 @@ set (glabels_qobject_headers
ColorHistory.h
ColorPaletteDialog.h
ColorPaletteItem.h
FieldButton.h
FieldMenu.h
FieldMenuItem.h
LabelModel.h
LabelModelObject.h
LabelModelBoxObject.h
+118
View File
@@ -0,0 +1,118 @@
/* FieldButton.cpp
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FieldButton.h"
namespace glabels
{
///
/// Constructor
///
FieldButton::FieldButton( const QString& name, QWidget* parent )
: QPushButton(parent)
{
if ( name.isNull() || name.isEmpty() )
{
setText( tr("(None)") );
mLabelIsKey = false;
}
else
{
setText( name );
mLabelIsKey = true;
}
setEnabled( false );
mMenu = new FieldMenu();
setMenu( mMenu );
connect( mMenu, SIGNAL(keySelected(const QString&)), this, SLOT(onMenuKeySelected(const QString&)) );
}
void FieldButton::setKeys( const QList<QString>& keyList )
{
mMenu->setKeys( keyList );
if ( keyList.length() > 0 )
{
mKey = keyList.first();
if ( mLabelIsKey )
{
setText( mKey );
}
else
{
setText( tr("(None)") );
}
setEnabled( true );
}
else
{
setEnabled( false );
}
}
void FieldButton::clearKeys()
{
if ( !mLabelIsKey )
{
setText( tr("(None)") );
}
setEnabled( false );
}
///
/// key getter
///
QString FieldButton::key() const
{
return mKey;
}
///
/// onMenuKeySelected slot
///
void FieldButton::onMenuKeySelected( const QString& key )
{
mKey = key;
if ( mLabelIsKey )
{
setText( key );
}
emit keySelected( key );
}
}
+88
View File
@@ -0,0 +1,88 @@
/* FieldButton.h
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_FieldButton_h
#define glabels_FieldButton_h
#include <QPushButton>
#include <QString>
#include "FieldMenu.h"
namespace glabels
{
///
/// Field Button
///
class FieldButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldButton( const QString& name, QWidget* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void keySelected( const QString& key );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
QString key() const;
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setKeys( const QList<QString>& keyList );
void clearKeys();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuKeySelected( const QString& key );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
FieldMenu* mMenu;
QString mKey;
bool mLabelIsKey;
};
}
#endif // glabels_FieldButton_h
+64
View File
@@ -0,0 +1,64 @@
/* FieldMenu.cpp
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FieldMenu.h"
#include "FieldMenuItem.h"
namespace glabels
{
///
/// Constructor
///
FieldMenu::FieldMenu()
{
}
///
/// set keys
///
void FieldMenu::setKeys( const QList<QString>& keyList )
{
clear();
foreach ( QString key, keyList )
{
FieldMenuItem* menuItem = new FieldMenuItem( key );
connect( menuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) );
addAction( menuItem );
}
}
///
/// onMenuItemActivated slot
///
void FieldMenu::onMenuItemActivated( const QString& key )
{
emit keySelected( key );
}
}
+76
View File
@@ -0,0 +1,76 @@
/* FieldMenu.h
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_FieldMenu_h
#define glabels_FieldMenu_h
#include <QMenu>
#include <QString>
namespace glabels
{
///
/// Field Menu
///
class FieldMenu : public QMenu
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldMenu();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void keySelected( const QString& key );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setKeys( const QList<QString>& keyList );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuItemActivated( const QString& key );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
};
}
#endif // glabels_FieldMenu_h
+57
View File
@@ -0,0 +1,57 @@
/* FieldMenuItem.cpp
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FieldMenuItem.h"
namespace glabels
{
///
/// Constructor From Data
///
FieldMenuItem::FieldMenuItem( const QString& key, QObject* parent )
: QAction(parent), mKey(key)
{
setText( key );
connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) );
}
///
/// key Property Getter
///
QString FieldMenuItem::key() const
{
return mKey;
}
///
/// onTriggered slot
///
void FieldMenuItem::onTriggered()
{
emit activated( mKey );
}
}
+77
View File
@@ -0,0 +1,77 @@
/* FieldMenuItem.h
*
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_FieldMenuItem_h
#define glabels_FieldMenuItem_h
#include <QAction>
#include <QString>
namespace glabels
{
///
/// Field Menu Item
///
class FieldMenuItem : public QAction
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldMenuItem( const QString& key, QObject* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( const QString& key );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
QString key() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onTriggered();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
const QString mKey;
};
}
#endif // glabels_FieldMenuItem_h