From a9d9313e5a5ac2b5e5a5983a598f7633d0e6b3bd Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 6 Jul 2014 00:13:41 -0400 Subject: [PATCH] Added Barcode menu class. --- app/BarcodeMenu.cpp | 68 ++++++++++++++++++++++++++++++++++++ app/BarcodeMenu.h | 77 +++++++++++++++++++++++++++++++++++++++++ app/BarcodeMenuItem.cpp | 19 +++++----- app/BarcodeMenuItem.h | 21 ++++++++--- app/CMakeLists.txt | 3 ++ 5 files changed, 176 insertions(+), 12 deletions(-) create mode 100644 app/BarcodeMenu.cpp create mode 100644 app/BarcodeMenu.h diff --git a/app/BarcodeMenu.cpp b/app/BarcodeMenu.cpp new file mode 100644 index 0000000..f1bfe10 --- /dev/null +++ b/app/BarcodeMenu.cpp @@ -0,0 +1,68 @@ +/* BarcodeMenu.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 "BarcodeMenu.h" + +#include "BarcodeBackends.h" +#include "BarcodeMenuItem.h" + + +namespace glabels +{ + + /// + /// Constructor + /// + BarcodeMenu::BarcodeMenu() + { + foreach ( QString name, BarcodeBackends::getNameList() ) + { + const BarcodeStyle* bcStyle = BarcodeBackends::lookupStyleFromName( name ); + + BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle ); + connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) ); + + addAction( bcMenuItem ); + } + } + + + /// + /// bcStyle getter + /// + const BarcodeStyle* BarcodeMenu::bcStyle() const + { + return mBcStyle; + } + + + /// + /// onMenuItemActivated slot + /// + void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle ) + { + mBcStyle = bcStyle; + + emit styleChanged(); + } + + +} + diff --git a/app/BarcodeMenu.h b/app/BarcodeMenu.h new file mode 100644 index 0000000..90bb4a1 --- /dev/null +++ b/app/BarcodeMenu.h @@ -0,0 +1,77 @@ +/* BarcodeMenu.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_BarcodeMenu_h +#define glabels_BarcodeMenu_h + +#include +#include "BarcodeStyle.h" + + +namespace glabels +{ + + /// + /// Barcode Menu Item + /// + class BarcodeMenu : public QMenu + { + Q_OBJECT + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// + public: + BarcodeMenu(); + + + ///////////////////////////////// + // Signals + ///////////////////////////////// + signals: + void styleChanged(); + + + ///////////////////////////////// + // Properties + ///////////////////////////////// + public: + const BarcodeStyle* bcStyle() const; + + + ///////////////////////////////// + // Slots + ///////////////////////////////// + private slots: + void onMenuItemActivated( BarcodeStyle *bcStyle ); + + + ///////////////////////////////// + // Private Data + ///////////////////////////////// + private: + BarcodeStyle* mBcStyle; + + }; + + +} + +#endif // glabels_BarcodeMenu_h diff --git a/app/BarcodeMenuItem.cpp b/app/BarcodeMenuItem.cpp index 333470f..f0fd229 100644 --- a/app/BarcodeMenuItem.cpp +++ b/app/BarcodeMenuItem.cpp @@ -27,18 +27,12 @@ namespace glabels /// /// Constructor From Data /// - BarcodeMenuItem::BarcodeMenuItem( BarcodeStyle* bcStyle, QObject* parent ) + BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent ) : QAction(parent), mBcStyle(bcStyle) { setText( bcStyle->name() ); - } - - /// - /// Destructor - /// - BarcodeMenuItem::~BarcodeMenuItem() - { + connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) ); } @@ -50,5 +44,14 @@ namespace glabels return mBcStyle; } + + /// + /// onTriggered slot + /// + void BarcodeMenuItem::onTriggered() + { + emit activated( mBcStyle ); + } + } diff --git a/app/BarcodeMenuItem.h b/app/BarcodeMenuItem.h index 11b3104..5f54812 100644 --- a/app/BarcodeMenuItem.h +++ b/app/BarcodeMenuItem.h @@ -33,28 +33,41 @@ namespace glabels /// class BarcodeMenuItem : public QAction { + Q_OBJECT ///////////////////////////////// // Life Cycle ///////////////////////////////// public: - BarcodeMenuItem( BarcodeStyle* bcStyle, QObject* parent ); + BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = 0 ); - virtual ~BarcodeMenuItem(); + + ///////////////////////////////// + // Signals + ///////////////////////////////// + signals: + void activated( const BarcodeStyle* bcStyle ); ///////////////////////////////// // Properties ///////////////////////////////// - + public: const BarcodeStyle* bcStyle() const; + ///////////////////////////////// + // Slots + ///////////////////////////////// + private slots: + void onTriggered(); + + ///////////////////////////////// // Private Data ///////////////////////////////// private: - BarcodeStyle* mBcStyle; + const BarcodeStyle* mBcStyle; }; diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index db0daed..eb06709 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -5,6 +5,7 @@ project (app CXX) set (glabels_sources glabels_main.cpp BarcodeBackends.cpp + BarcodeMenu.cpp BarcodeMenuItem.cpp BarcodeStyle.cpp ColorNode.cpp @@ -26,6 +27,8 @@ set (glabels_sources ) set (glabels_qobject_headers + BarcodeMenu.h + BarcodeMenuItem.h LabelModel.h LabelModelObject.h LabelModelBoxObject.h