From 06ff8136181f14e0449e7fe5abd0303a054f2d0c Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 19 Jul 2014 13:37:11 -0400 Subject: [PATCH] Added field button, menu, and menu item classes. --- glabels/CMakeLists.txt | 6 ++ glabels/FieldButton.cpp | 118 ++++++++++++++++++++++++++++++++++++++ glabels/FieldButton.h | 88 ++++++++++++++++++++++++++++ glabels/FieldMenu.cpp | 64 +++++++++++++++++++++ glabels/FieldMenu.h | 76 ++++++++++++++++++++++++ glabels/FieldMenuItem.cpp | 57 ++++++++++++++++++ glabels/FieldMenuItem.h | 77 +++++++++++++++++++++++++ 7 files changed, 486 insertions(+) create mode 100644 glabels/FieldButton.cpp create mode 100644 glabels/FieldButton.h create mode 100644 glabels/FieldMenu.cpp create mode 100644 glabels/FieldMenu.h create mode 100644 glabels/FieldMenuItem.cpp create mode 100644 glabels/FieldMenuItem.h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 14fc417..2ee7783 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -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 diff --git a/glabels/FieldButton.cpp b/glabels/FieldButton.cpp new file mode 100644 index 0000000..630f285 --- /dev/null +++ b/glabels/FieldButton.cpp @@ -0,0 +1,118 @@ +/* FieldButton.cpp + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#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& 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 ); + } + + +} + diff --git a/glabels/FieldButton.h b/glabels/FieldButton.h new file mode 100644 index 0000000..f4bd56a --- /dev/null +++ b/glabels/FieldButton.h @@ -0,0 +1,88 @@ +/* FieldButton.h + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#ifndef glabels_FieldButton_h +#define glabels_FieldButton_h + +#include +#include +#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& keyList ); + void clearKeys(); + + + ///////////////////////////////// + // Slots + ///////////////////////////////// + private slots: + void onMenuKeySelected( const QString& key ); + + + ///////////////////////////////// + // Private Data + ///////////////////////////////// + private: + FieldMenu* mMenu; + QString mKey; + bool mLabelIsKey; + + }; + + +} + +#endif // glabels_FieldButton_h diff --git a/glabels/FieldMenu.cpp b/glabels/FieldMenu.cpp new file mode 100644 index 0000000..60f3e02 --- /dev/null +++ b/glabels/FieldMenu.cpp @@ -0,0 +1,64 @@ +/* FieldMenu.cpp + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#include "FieldMenu.h" + +#include "FieldMenuItem.h" + + +namespace glabels +{ + + /// + /// Constructor + /// + FieldMenu::FieldMenu() + { + } + + + /// + /// set keys + /// + void FieldMenu::setKeys( const QList& 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 ); + } + + +} + diff --git a/glabels/FieldMenu.h b/glabels/FieldMenu.h new file mode 100644 index 0000000..d409885 --- /dev/null +++ b/glabels/FieldMenu.h @@ -0,0 +1,76 @@ +/* FieldMenu.h + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#ifndef glabels_FieldMenu_h +#define glabels_FieldMenu_h + +#include +#include + + +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& keyList ); + + + ///////////////////////////////// + // Slots + ///////////////////////////////// + private slots: + void onMenuItemActivated( const QString& key ); + + + ///////////////////////////////// + // Private Data + ///////////////////////////////// + private: + + }; + + +} + +#endif // glabels_FieldMenu_h diff --git a/glabels/FieldMenuItem.cpp b/glabels/FieldMenuItem.cpp new file mode 100644 index 0000000..9ccae90 --- /dev/null +++ b/glabels/FieldMenuItem.cpp @@ -0,0 +1,57 @@ +/* FieldMenuItem.cpp + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#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 ); + } + +} + diff --git a/glabels/FieldMenuItem.h b/glabels/FieldMenuItem.h new file mode 100644 index 0000000..47f73ca --- /dev/null +++ b/glabels/FieldMenuItem.h @@ -0,0 +1,77 @@ +/* FieldMenuItem.h + * + * Copyright (C) 2014 Jim Evins + * + * 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 . + */ + +#ifndef glabels_FieldMenuItem_h +#define glabels_FieldMenuItem_h + +#include +#include + + +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