From 7559544b064235f3ed82d1e34d7f3e1569f6bf30 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 27 Mar 2016 00:14:38 -0400 Subject: [PATCH] Some namespace cleanup. --- glabels/BarcodeBackends.cpp | 315 ++-- glabels/BarcodeBackends.h | 107 +- glabels/BarcodeMenu.cpp | 63 +- glabels/BarcodeMenu.h | 73 +- glabels/BarcodeMenuButton.cpp | 67 +- glabels/BarcodeMenuButton.h | 75 +- glabels/BarcodeMenuItem.cpp | 54 +- glabels/BarcodeMenuItem.h | 73 +- glabels/BarcodeStyle.cpp | 292 ++- glabels/BarcodeStyle.h | 115 +- glabels/ColorButton.cpp | 238 ++- glabels/ColorButton.h | 105 +- glabels/ColorHistory.cpp | 183 +- glabels/ColorHistory.h | 83 +- glabels/ColorNode.cpp | 266 ++- glabels/ColorNode.h | 114 +- glabels/ColorPaletteButtonItem.cpp | 164 +- glabels/ColorPaletteButtonItem.h | 71 +- glabels/ColorPaletteDialog.cpp | 379 ++-- glabels/ColorPaletteDialog.h | 119 +- glabels/ColorPaletteItem.cpp | 172 +- glabels/ColorPaletteItem.h | 95 +- glabels/ColorSwatch.cpp | 33 +- glabels/ColorSwatch.h | 30 +- glabels/Cursors.cpp | 12 +- glabels/Cursors.h | 80 +- glabels/FieldButton.cpp | 155 +- glabels/FieldButton.h | 91 +- glabels/FieldMenu.cpp | 65 +- glabels/FieldMenu.h | 71 +- glabels/FieldMenuItem.cpp | 54 +- glabels/FieldMenuItem.h | 73 +- glabels/File.cpp | 342 ++-- glabels/File.h | 42 +- glabels/FileUtil.cpp | 17 +- glabels/FileUtil.h | 15 +- glabels/Handles.cpp | 104 +- glabels/Handles.h | 463 +++-- glabels/Help.cpp | 58 +- glabels/Help.h | 22 +- glabels/Icons.h | 711 ++++---- glabels/LabelModel.cpp | 2016 +++++++++++---------- glabels/LabelModel.h | 508 +++--- glabels/LabelModelBoxObject.cpp | 195 +- glabels/LabelModelBoxObject.h | 48 +- glabels/LabelModelObject.cpp | 1599 +++++++++-------- glabels/LabelModelObject.h | 523 +++--- glabels/LabelModelShapeObject.cpp | 254 ++- glabels/LabelModelShapeObject.h | 102 +- glabels/LabelRegion.cpp | 23 +- glabels/LabelRegion.h | 188 +- glabels/MainWindow.cpp | 2637 ++++++++++++++-------------- glabels/MainWindow.h | 425 +++-- glabels/Merge.cpp | 209 ++- glabels/Merge.h | 206 ++- glabels/MergeField.h | 108 +- glabels/MergePropertyEditor.cpp | 71 +- glabels/MergePropertyEditor.h | 65 +- glabels/MergeRecord.cpp | 15 +- glabels/MergeRecord.h | 120 +- glabels/ObjectEditor.cpp | 459 +++-- glabels/ObjectEditor.h | 107 +- glabels/Outline.cpp | 8 +- glabels/Outline.h | 66 +- glabels/PageRenderer.cpp | 347 ++-- glabels/PageRenderer.h | 121 +- glabels/Preview.cpp | 290 ++- glabels/Preview.h | 95 +- glabels/PreviewOverlayItem.cpp | 33 +- glabels/PreviewOverlayItem.h | 59 +- glabels/PrintView.cpp | 283 ++- glabels/PrintView.h | 77 +- glabels/PropertiesView.cpp | 277 ++- glabels/PropertiesView.h | 69 +- glabels/SelectProductDialog.cpp | 195 +- glabels/SelectProductDialog.h | 70 +- glabels/SimplePreview.cpp | 395 ++--- glabels/SimplePreview.h | 92 +- glabels/TemplatePicker.cpp | 116 +- glabels/TemplatePicker.h | 52 +- glabels/TemplatePickerItem.cpp | 43 +- glabels/TemplatePickerItem.h | 50 +- glabels/TextNode.cpp | 368 ++-- glabels/TextNode.h | 92 +- glabels/View.cpp | 126 +- glabels/View.h | 318 ++-- glabels/XmlLabelCreator.cpp | 82 +- glabels/XmlLabelCreator.h | 87 +- glabels/XmlLabelParser.cpp | 50 +- glabels/XmlLabelParser.h | 87 +- glabels/glabels_main.cpp | 13 +- glabels/ui/ObjectEditor.ui | 20 +- glabels/ui/PrintView.ui | 4 +- glabels/ui/PropertiesView.ui | 4 +- glabels/ui/SelectProductDialog.ui | 4 +- libglabels/Category.cpp | 4 +- libglabels/Category.h | 10 +- libglabels/Category.inl | 4 +- libglabels/Config.h.in | 10 +- libglabels/Constants.h | 8 +- libglabels/Db.cpp | 6 +- libglabels/Db.h | 10 +- libglabels/Db.inl | 4 +- libglabels/Distance.cpp | 2 +- libglabels/Distance.h | 8 +- libglabels/Distance.inl | 2 +- libglabels/Frame.cpp | 4 +- libglabels/Frame.h | 10 +- libglabels/Frame.inl | 4 +- libglabels/FrameCd.cpp | 2 +- libglabels/FrameCd.h | 8 +- libglabels/FrameCd.inl | 2 +- libglabels/FrameEllipse.cpp | 2 +- libglabels/FrameEllipse.h | 8 +- libglabels/FrameEllipse.inl | 2 +- libglabels/FrameRect.cpp | 2 +- libglabels/FrameRect.h | 10 +- libglabels/FrameRect.inl | 2 +- libglabels/FrameRound.cpp | 2 +- libglabels/FrameRound.h | 8 +- libglabels/FrameRound.inl | 2 +- libglabels/Layout.cpp | 2 +- libglabels/Layout.h | 8 +- libglabels/Layout.inl | 2 +- libglabels/Markup.cpp | 2 +- libglabels/Markup.h | 8 +- libglabels/Markup.inl | 2 +- libglabels/MiniPreviewPixmap.cpp | 2 +- libglabels/MiniPreviewPixmap.h | 8 +- libglabels/Paper.cpp | 2 +- libglabels/Paper.h | 8 +- libglabels/Paper.inl | 4 +- libglabels/Point.cpp | 4 +- libglabels/Point.h | 8 +- libglabels/Point.inl | 2 +- libglabels/StrUtil.cpp | 4 +- libglabels/StrUtil.h | 10 +- libglabels/Template.cpp | 2 +- libglabels/Template.h | 8 +- libglabels/Template.inl | 2 +- libglabels/Vendor.cpp | 4 +- libglabels/Vendor.h | 10 +- libglabels/Vendor.inl | 4 +- libglabels/XmlCategoryParser.cpp | 4 +- libglabels/XmlCategoryParser.h | 10 +- libglabels/XmlPaperParser.cpp | 4 +- libglabels/XmlPaperParser.h | 10 +- libglabels/XmlTemplateCreator.cpp | 2 +- libglabels/XmlTemplateCreator.h | 10 +- libglabels/XmlTemplateParser.cpp | 2 +- libglabels/XmlTemplateParser.h | 8 +- libglabels/XmlUtil.cpp | 2 +- libglabels/XmlUtil.h | 8 +- libglabels/XmlVendorParser.cpp | 4 +- libglabels/XmlVendorParser.h | 10 +- libglabels/privateConstants.h | 10 +- 156 files changed, 9732 insertions(+), 10126 deletions(-) diff --git a/glabels/BarcodeBackends.cpp b/glabels/BarcodeBackends.cpp index c51910d..4811a17 100644 --- a/glabels/BarcodeBackends.cpp +++ b/glabels/BarcodeBackends.cpp @@ -21,166 +21,159 @@ #include "BarcodeBackends.h" -namespace glabels +namespace { - - namespace - { - const std::string default_id = "code39"; - } - - BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap; - BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap; - - BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap; - BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap; - - QList BarcodeBackends::mBackendNameList; - QList BarcodeBackends::mNameList; - - - BarcodeBackends::BarcodeBackends() - { - registerStyle( "postnet", "", tr("POSTNET (any)"), - false, false, true, false, "12345-6789-12", false, 11 ); - - registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"), - false, false, true, false, "12345", false, 5 ); - - registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"), - false, false, true, false, "12345-6789", false, 9 ); - - registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"), - false, false, true, false, "12345-6789-12", false, 11 ); - - registerStyle( "cepnet", "", tr("CEPNET"), - false, false, true, false, "12345-678", false, 8 ); - - registerStyle( "onecode", "", tr("USPS Intelligent Mail"), - false, false, true, false, "12345678901234567890", false, 20 ); - - registerStyle( "code39", "", tr("Code 39"), - true, true, true, true, "1234567890", true, 10 ); - - registerStyle( "code39ext", "", tr("Code 39 Extended"), - true, true, true, true, "1234567890", true, 10 ); - - registerStyle( "upc-A", "", tr("UPC-A"), - true, false, true, false, "12345678901", false, 11 ); - - registerStyle( "ean-13", "", tr("EAN-13"), - true, false, true, false, "123456789012", false, 12 ); - - registerStyle( "datamatrix", "", tr("DataMatrix"), - false, false, true, false, "1234567890AB", false, 12 ); - - registerStyle( "qrcode", "", tr("QRCode"), - false, false, true, false, "1234567890AB", false, 12 ); - } - - - void BarcodeBackends::init( void ) - { - static BarcodeBackends* singletonInstance = NULL; - - if ( singletonInstance == NULL ) - { - singletonInstance = new BarcodeBackends(); - } - } - - - QString BarcodeBackends::BackendIdToName( const QString& backendId ) - { - BackendMap::iterator i = mBackendIdMap.find( backendId ); - if ( i != mBackendIdMap.end() ) - { - return i.value(); - } - - return ""; - } - - - QString BarcodeBackends::BackendNameToId( const QString& backendName ) - { - BackendMap::iterator i = mBackendNameMap.find( backendName ); - if ( i != mBackendNameMap.end() ) - { - return i.value(); - } - - return ""; - } - - - const QList& BarcodeBackends::getBackendNameList() - { - return mBackendNameList; - } - - - const QList& BarcodeBackends::getNameList() - { - return mNameList; - } - - - const BarcodeStyle* BarcodeBackends::lookupStyleFromId( const QString& id ) - { - StyleMap::iterator i = mStyleIdMap.find( id ); - if ( i != mStyleIdMap.end() ) - { - return i.value(); - } - - return 0; - } - - - const BarcodeStyle* BarcodeBackends::lookupStyleFromName( const QString& name ) - { - StyleMap::iterator i = mStyleNameMap.find( name ); - if ( i != mStyleNameMap.end() ) - { - return i.value(); - } - - return 0; - } - - - void BarcodeBackends::registerBackend( QString& id, QString& name) - { - mBackendNameList.append( name ); - mBackendIdMap.insert( id, name ); - mBackendNameMap.insert( name, id ); - } - - - void BarcodeBackends::registerStyle( const char* id, - const char* backendId, - const QString& name, - bool canText, - bool textOptional, - bool canChecksum, - bool checksumOptional, - const char* defaultDigits, - bool canFreeForm, - int preferedN ) - { - BarcodeStyle* style = new BarcodeStyle( QString(id), QString(backendId), name, - canText, textOptional, - canChecksum, checksumOptional, - QString(defaultDigits), canFreeForm, preferedN ); - - QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique - - mNameList.append( name ); - mStyleIdMap.insert( id, style ); - mStyleNameMap.insert( fqName, style ); - } - - - + const std::string default_id = "code39"; +} + +BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap; +BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap; + +BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap; +BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap; + +QList BarcodeBackends::mBackendNameList; +QList BarcodeBackends::mNameList; + + +BarcodeBackends::BarcodeBackends() +{ + registerStyle( "postnet", "", tr("POSTNET (any)"), + false, false, true, false, "12345-6789-12", false, 11 ); + + registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"), + false, false, true, false, "12345", false, 5 ); + + registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"), + false, false, true, false, "12345-6789", false, 9 ); + + registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"), + false, false, true, false, "12345-6789-12", false, 11 ); + + registerStyle( "cepnet", "", tr("CEPNET"), + false, false, true, false, "12345-678", false, 8 ); + + registerStyle( "onecode", "", tr("USPS Intelligent Mail"), + false, false, true, false, "12345678901234567890", false, 20 ); + + registerStyle( "code39", "", tr("Code 39"), + true, true, true, true, "1234567890", true, 10 ); + + registerStyle( "code39ext", "", tr("Code 39 Extended"), + true, true, true, true, "1234567890", true, 10 ); + + registerStyle( "upc-A", "", tr("UPC-A"), + true, false, true, false, "12345678901", false, 11 ); + + registerStyle( "ean-13", "", tr("EAN-13"), + true, false, true, false, "123456789012", false, 12 ); + + registerStyle( "datamatrix", "", tr("DataMatrix"), + false, false, true, false, "1234567890AB", false, 12 ); + + registerStyle( "qrcode", "", tr("QRCode"), + false, false, true, false, "1234567890AB", false, 12 ); +} + + +void BarcodeBackends::init( void ) +{ + static BarcodeBackends* singletonInstance = NULL; + + if ( singletonInstance == NULL ) + { + singletonInstance = new BarcodeBackends(); + } +} + + +QString BarcodeBackends::BackendIdToName( const QString& backendId ) +{ + BackendMap::iterator i = mBackendIdMap.find( backendId ); + if ( i != mBackendIdMap.end() ) + { + return i.value(); + } + + return ""; +} + + +QString BarcodeBackends::BackendNameToId( const QString& backendName ) +{ + BackendMap::iterator i = mBackendNameMap.find( backendName ); + if ( i != mBackendNameMap.end() ) + { + return i.value(); + } + + return ""; +} + + +const QList& BarcodeBackends::getBackendNameList() +{ + return mBackendNameList; +} + + +const QList& BarcodeBackends::getNameList() +{ + return mNameList; +} + + +const BarcodeStyle* BarcodeBackends::lookupStyleFromId( const QString& id ) +{ + StyleMap::iterator i = mStyleIdMap.find( id ); + if ( i != mStyleIdMap.end() ) + { + return i.value(); + } + + return 0; +} + + +const BarcodeStyle* BarcodeBackends::lookupStyleFromName( const QString& name ) +{ + StyleMap::iterator i = mStyleNameMap.find( name ); + if ( i != mStyleNameMap.end() ) + { + return i.value(); + } + + return 0; +} + + +void BarcodeBackends::registerBackend( QString& id, QString& name) +{ + mBackendNameList.append( name ); + mBackendIdMap.insert( id, name ); + mBackendNameMap.insert( name, id ); +} + + +void BarcodeBackends::registerStyle( const char* id, + const char* backendId, + const QString& name, + bool canText, + bool textOptional, + bool canChecksum, + bool checksumOptional, + const char* defaultDigits, + bool canFreeForm, + int preferedN ) +{ + BarcodeStyle* style = new BarcodeStyle( QString(id), QString(backendId), name, + canText, textOptional, + canChecksum, checksumOptional, + QString(defaultDigits), canFreeForm, preferedN ); + + QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique + + mNameList.append( name ); + mStyleIdMap.insert( id, style ); + mStyleNameMap.insert( fqName, style ); } diff --git a/glabels/BarcodeBackends.h b/glabels/BarcodeBackends.h index df4263a..81d39ab 100644 --- a/glabels/BarcodeBackends.h +++ b/glabels/BarcodeBackends.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_BarcodeBackends_h -#define glabels_BarcodeBackends_h +#ifndef BarcodeBackends_h +#define BarcodeBackends_h #include "BarcodeStyle.h" @@ -29,73 +29,68 @@ #include -namespace glabels +/// +/// Barcode Backends Database +/// +class BarcodeBackends : public QObject { - /// - /// Barcode Backends Database - /// - class BarcodeBackends : public QObject - { + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +private: + BarcodeBackends(); - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - private: - BarcodeBackends(); +public: + static void init( void ); - public: - static void init( void ); + ///////////////////////////////// + // Public Methods + ///////////////////////////////// +public: + static QString BackendIdToName( const QString& backendId ); + static QString BackendNameToId( const QString& backendName ); - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - static QString BackendIdToName( const QString& backendId ); - static QString BackendNameToId( const QString& backendName ); + static const QList& getBackendNameList(); + static const QList& getNameList(); - static const QList& getBackendNameList(); - static const QList& getNameList(); - - static const BarcodeStyle* lookupStyleFromId( const QString& id ); - static const BarcodeStyle* lookupStyleFromName( const QString& name ); + static const BarcodeStyle* lookupStyleFromId( const QString& id ); + static const BarcodeStyle* lookupStyleFromName( const QString& name ); - ///////////////////////////////// - // Private Methods - ///////////////////////////////// - private: - static void registerBackend( QString &id, QString &name); + ///////////////////////////////// + // Private Methods + ///////////////////////////////// +private: + static void registerBackend( QString &id, QString &name); - static void registerStyle( const char* id, - const char* backendId, - const QString& name, - bool canText, - bool textOptional, - bool canChecksum, - bool checksumOptional, - const char* defaultDigits, - bool canFreeForm, - int preferedN ); + static void registerStyle( const char* id, + const char* backendId, + const QString& name, + bool canText, + bool textOptional, + bool canChecksum, + bool checksumOptional, + const char* defaultDigits, + bool canFreeForm, + int preferedN ); - ///////////////////////////////// - // Private Members - ///////////////////////////////// - typedef QMap BackendMap; - static BackendMap mBackendIdMap; - static BackendMap mBackendNameMap; + ///////////////////////////////// + // Private Members + ///////////////////////////////// + typedef QMap BackendMap; + static BackendMap mBackendIdMap; + static BackendMap mBackendNameMap; - typedef QMap StyleMap; - static StyleMap mStyleIdMap; - static StyleMap mStyleNameMap; + typedef QMap StyleMap; + static StyleMap mStyleIdMap; + static StyleMap mStyleNameMap; - static QList mBackendNameList; - static QList mNameList; + static QList mBackendNameList; + static QList mNameList; - }; - -} +}; -#endif // glabels_BarcodeBackends_h +#endif // BarcodeBackends_h diff --git a/glabels/BarcodeMenu.cpp b/glabels/BarcodeMenu.cpp index f1bfe10..712cd2b 100644 --- a/glabels/BarcodeMenu.cpp +++ b/glabels/BarcodeMenu.cpp @@ -24,45 +24,38 @@ #include "BarcodeMenuItem.h" -namespace glabels +/// +/// Constructor +/// +BarcodeMenu::BarcodeMenu() { - - /// - /// Constructor - /// - BarcodeMenu::BarcodeMenu() + foreach ( QString name, BarcodeBackends::getNameList() ) { - foreach ( QString name, BarcodeBackends::getNameList() ) - { - const BarcodeStyle* bcStyle = BarcodeBackends::lookupStyleFromName( name ); + const BarcodeStyle* bcStyle = BarcodeBackends::lookupStyleFromName( name ); - BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle ); - connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) ); + BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle ); + connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) ); - addAction( bcMenuItem ); - } + addAction( bcMenuItem ); } - - - /// - /// bcStyle getter - /// - const BarcodeStyle* BarcodeMenu::bcStyle() const - { - return mBcStyle; - } - - - /// - /// onMenuItemActivated slot - /// - void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle ) - { - mBcStyle = bcStyle; - - emit styleChanged(); - } - - } + +/// +/// bcStyle getter +/// +const BarcodeStyle* BarcodeMenu::bcStyle() const +{ + return mBcStyle; +} + + +/// +/// onMenuItemActivated slot +/// +void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle ) +{ + mBcStyle = bcStyle; + + emit styleChanged(); +} diff --git a/glabels/BarcodeMenu.h b/glabels/BarcodeMenu.h index 189f56d..14c98d3 100644 --- a/glabels/BarcodeMenu.h +++ b/glabels/BarcodeMenu.h @@ -18,60 +18,55 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_BarcodeMenu_h -#define glabels_BarcodeMenu_h +#ifndef BarcodeMenu_h +#define BarcodeMenu_h #include #include "BarcodeStyle.h" -namespace glabels +/// +/// Barcode Menu +/// +class BarcodeMenu : public QMenu { + Q_OBJECT - /// - /// Barcode Menu - /// - class BarcodeMenu : public QMenu - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - BarcodeMenu(); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + BarcodeMenu(); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void styleChanged(); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void styleChanged(); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - const BarcodeStyle* bcStyle() const; + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + const BarcodeStyle* bcStyle() const; - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onMenuItemActivated( BarcodeStyle *bcStyle ); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onMenuItemActivated( BarcodeStyle *bcStyle ); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - BarcodeStyle* mBcStyle; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + BarcodeStyle* mBcStyle; - }; +}; -} - -#endif // glabels_BarcodeMenu_h +#endif // BarcodeMenu_h diff --git a/glabels/BarcodeMenuButton.cpp b/glabels/BarcodeMenuButton.cpp index 09d5991..89011b3 100644 --- a/glabels/BarcodeMenuButton.cpp +++ b/glabels/BarcodeMenuButton.cpp @@ -24,45 +24,38 @@ #include "BarcodeMenuItem.h" -namespace glabels +/// +/// Constructor +/// +BarcodeMenuButton::BarcodeMenuButton( QWidget* parent ) + : QPushButton(parent) { + mMenu = new BarcodeMenu(); + setMenu( mMenu ); - /// - /// Constructor - /// - BarcodeMenuButton::BarcodeMenuButton( QWidget* parent ) - : QPushButton(parent) - { - mMenu = new BarcodeMenu(); - setMenu( mMenu ); - - mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style - setText( mBcStyle->name() ); - - connect( mMenu, SIGNAL(styleChanged()), this, SLOT(onMenuStyleChanged()) ); - } - - - /// - /// bcStyle getter - /// - const BarcodeStyle* BarcodeMenuButton::bcStyle() const - { - return mBcStyle; - } - - - /// - /// onMenuStyleChanged slot - /// - void BarcodeMenuButton::onMenuStyleChanged() - { - mBcStyle = mMenu->bcStyle(); - setText( mBcStyle->name() ); - - emit styleChanged(); - } - + mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style + setText( mBcStyle->name() ); + connect( mMenu, SIGNAL(styleChanged()), this, SLOT(onMenuStyleChanged()) ); } + +/// +/// bcStyle getter +/// +const BarcodeStyle* BarcodeMenuButton::bcStyle() const +{ + return mBcStyle; +} + + +/// +/// onMenuStyleChanged slot +/// +void BarcodeMenuButton::onMenuStyleChanged() +{ + mBcStyle = mMenu->bcStyle(); + setText( mBcStyle->name() ); + + emit styleChanged(); +} diff --git a/glabels/BarcodeMenuButton.h b/glabels/BarcodeMenuButton.h index 4e75b3c..4b7a7f8 100644 --- a/glabels/BarcodeMenuButton.h +++ b/glabels/BarcodeMenuButton.h @@ -18,62 +18,57 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_BarcodeMenuButton_h -#define glabels_BarcodeMenuButton_h +#ifndef BarcodeMenuButton_h +#define BarcodeMenuButton_h #include #include "BarcodeMenu.h" #include "BarcodeStyle.h" -namespace glabels +/// +/// Barcode Menu Button +/// +class BarcodeMenuButton : public QPushButton { + Q_OBJECT - /// - /// Barcode Menu Button - /// - class BarcodeMenuButton : public QPushButton - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - BarcodeMenuButton( QWidget* parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + BarcodeMenuButton( QWidget* parent = 0 ); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void styleChanged(); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void styleChanged(); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - const BarcodeStyle* bcStyle() const; + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + const BarcodeStyle* bcStyle() const; - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onMenuStyleChanged(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onMenuStyleChanged(); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - BarcodeMenu* mMenu; - const BarcodeStyle* mBcStyle; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + BarcodeMenu* mMenu; + const BarcodeStyle* mBcStyle; - }; +}; -} - -#endif // glabels_BarcodeMenuButton_h +#endif // BarcodeMenuButton_h diff --git a/glabels/BarcodeMenuItem.cpp b/glabels/BarcodeMenuItem.cpp index f0fd229..99dfd54 100644 --- a/glabels/BarcodeMenuItem.cpp +++ b/glabels/BarcodeMenuItem.cpp @@ -21,37 +21,31 @@ #include "BarcodeMenuItem.h" -namespace glabels +/// +/// Constructor From Data +/// +BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent ) + : QAction(parent), mBcStyle(bcStyle) { + setText( bcStyle->name() ); - /// - /// Constructor From Data - /// - BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent ) - : QAction(parent), mBcStyle(bcStyle) - { - setText( bcStyle->name() ); - - connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) ); - } - - - /// - /// bcStyle Property Getter - /// - const BarcodeStyle* BarcodeMenuItem::bcStyle() const - { - return mBcStyle; - } - - - /// - /// onTriggered slot - /// - void BarcodeMenuItem::onTriggered() - { - emit activated( mBcStyle ); - } - + connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) ); } + +/// +/// bcStyle Property Getter +/// +const BarcodeStyle* BarcodeMenuItem::bcStyle() const +{ + return mBcStyle; +} + + +/// +/// onTriggered slot +/// +void BarcodeMenuItem::onTriggered() +{ + emit activated( mBcStyle ); +} diff --git a/glabels/BarcodeMenuItem.h b/glabels/BarcodeMenuItem.h index 5f54812..b6b93d4 100644 --- a/glabels/BarcodeMenuItem.h +++ b/glabels/BarcodeMenuItem.h @@ -18,60 +18,55 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_BarcodeMenuItem_h -#define glabels_BarcodeMenuItem_h +#ifndef BarcodeMenuItem_h +#define BarcodeMenuItem_h #include #include "BarcodeStyle.h" -namespace glabels +/// +/// Barcode Menu Item +/// +class BarcodeMenuItem : public QAction { + Q_OBJECT - /// - /// Barcode Menu Item - /// - class BarcodeMenuItem : public QAction - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = 0 ); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void activated( const BarcodeStyle* bcStyle ); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void activated( const BarcodeStyle* bcStyle ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - const BarcodeStyle* bcStyle() const; + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + const BarcodeStyle* bcStyle() const; - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onTriggered(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onTriggered(); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - const BarcodeStyle* mBcStyle; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + const BarcodeStyle* mBcStyle; - }; +}; -} - -#endif // glabels_BarcodeMenuItem_h +#endif // BarcodeMenuItem_h diff --git a/glabels/BarcodeStyle.cpp b/glabels/BarcodeStyle.cpp index 39b36c1..ed9d2b5 100644 --- a/glabels/BarcodeStyle.cpp +++ b/glabels/BarcodeStyle.cpp @@ -23,160 +23,154 @@ #include -namespace glabels +/// +/// Default Constructor +/// +BarcodeStyle::BarcodeStyle () + : mId( "" ), + mBackendId( "" ), + mName( "" ), + mCanText( false ), + mTextOptional( false ), + mCanChecksum( false ), + mChecksumOptional( false ), + mDefaultDigits( "" ), + mCanFreeform( false ), + mPreferedN( 0 ) { +} - /// - /// Default Constructor - /// - BarcodeStyle::BarcodeStyle () - : mId( "" ), - mBackendId( "" ), - mName( "" ), - mCanText( false ), - mTextOptional( false ), - mCanChecksum( false ), - mChecksumOptional( false ), - mDefaultDigits( "" ), - mCanFreeform( false ), - mPreferedN( 0 ) + +/// +/// Constructor From Data +/// +BarcodeStyle::BarcodeStyle ( const QString& id, + const QString& backendId, + const QString& name, + bool canText, + bool textOptional, + bool canChecksum, + bool checksumOptional, + const QString& defaultDigits, + bool canFreeform, + int preferedN ) + : mId( id ), + mBackendId( backendId ), + mName( name ), + mCanText( canText ), + mTextOptional( textOptional ), + mCanChecksum( canChecksum ), + mChecksumOptional( checksumOptional ), + mDefaultDigits( defaultDigits ), + mCanFreeform( canFreeform ), + mPreferedN( preferedN ) +{ +} + + +/// +/// ID Property Getter +/// +const QString& BarcodeStyle::id() const +{ + return mId; +} + + +/// +/// Backend ID Property Getter +/// +const QString& BarcodeStyle::backendId() const +{ + return mBackendId; +} + + +/// +/// Name Property Getter +/// +const QString& BarcodeStyle::name() const +{ + return mName; +} + + +/// +/// Can Text Property Getter +/// +bool BarcodeStyle::canText() const +{ + return mCanText; +} + + +/// +/// Text Optional Property Getter +/// +bool BarcodeStyle::textOptional() const +{ + return mTextOptional; +} + + +/// +/// Can Checksum Property Getter +/// +bool BarcodeStyle::canChecksum() const +{ + return mCanChecksum; +} + + +/// +/// Checksum Optional Property Getter +/// +bool BarcodeStyle::checksumOptional() const +{ + return mChecksumOptional; +} + + +/// +/// Default Digits Property Getter +/// +const QString& BarcodeStyle::defaultDigits() const +{ + return mDefaultDigits; +} + + +/// +/// Can Freeform Property Getter +/// +bool BarcodeStyle::canFreeform() const +{ + return mCanFreeform; +} + + +/// +/// Prefered N Property Getter +/// +int BarcodeStyle::preferedN() const +{ + return mPreferedN; +} + + +/// +/// Generate Example Digits +/// +QString BarcodeStyle::exampleDigits( int n ) const +{ + using std::max; + + if ( mCanFreeform ) { + return QString( max( n, 1 ), QChar('0') ); } - - - /// - /// Constructor From Data - /// - BarcodeStyle::BarcodeStyle ( const QString& id, - const QString& backendId, - const QString& name, - bool canText, - bool textOptional, - bool canChecksum, - bool checksumOptional, - const QString& defaultDigits, - bool canFreeform, - int preferedN ) - : mId( id ), - mBackendId( backendId ), - mName( name ), - mCanText( canText ), - mTextOptional( textOptional ), - mCanChecksum( canChecksum ), - mChecksumOptional( checksumOptional ), - mDefaultDigits( defaultDigits ), - mCanFreeform( canFreeform ), - mPreferedN( preferedN ) - { - } - - - /// - /// ID Property Getter - /// - const QString& BarcodeStyle::id() const - { - return mId; - } - - - /// - /// Backend ID Property Getter - /// - const QString& BarcodeStyle::backendId() const - { - return mBackendId; - } - - - /// - /// Name Property Getter - /// - const QString& BarcodeStyle::name() const - { - return mName; - } - - - /// - /// Can Text Property Getter - /// - bool BarcodeStyle::canText() const - { - return mCanText; - } - - - /// - /// Text Optional Property Getter - /// - bool BarcodeStyle::textOptional() const - { - return mTextOptional; - } - - - /// - /// Can Checksum Property Getter - /// - bool BarcodeStyle::canChecksum() const - { - return mCanChecksum; - } - - - /// - /// Checksum Optional Property Getter - /// - bool BarcodeStyle::checksumOptional() const - { - return mChecksumOptional; - } - - - /// - /// Default Digits Property Getter - /// - const QString& BarcodeStyle::defaultDigits() const + else { return mDefaultDigits; } - - - /// - /// Can Freeform Property Getter - /// - bool BarcodeStyle::canFreeform() const - { - return mCanFreeform; - } - - - /// - /// Prefered N Property Getter - /// - int BarcodeStyle::preferedN() const - { - return mPreferedN; - } - - - /// - /// Generate Example Digits - /// - QString BarcodeStyle::exampleDigits( int n ) const - { - using std::max; - - if ( mCanFreeform ) - { - return QString( max( n, 1 ), QChar('0') ); - } - else - { - return mDefaultDigits; - } - } - } - diff --git a/glabels/BarcodeStyle.h b/glabels/BarcodeStyle.h index fbd4bc7..a290b3f 100644 --- a/glabels/BarcodeStyle.h +++ b/glabels/BarcodeStyle.h @@ -18,88 +18,83 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_BarcodeStyle_h -#define glabels_BarcodeStyle_h +#ifndef BarcodeStyle_h +#define BarcodeStyle_h #include -namespace glabels +/// +/// Barcode Style Type +/// +struct BarcodeStyle { - /// - /// Barcode Style Type - /// - struct BarcodeStyle - { + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + BarcodeStyle (); - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - BarcodeStyle (); - - BarcodeStyle ( const QString& id, - const QString& backendId, - const QString& name, - bool canText, - bool textOptional, - bool canChecksum, - bool checksumOptional, - const QString& defaultDigits, - bool canFreeform, - int preferedN ); + BarcodeStyle ( const QString& id, + const QString& backendId, + const QString& name, + bool canText, + bool textOptional, + bool canChecksum, + bool checksumOptional, + const QString& defaultDigits, + bool canFreeform, + int preferedN ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - const QString& id() const; + ///////////////////////////////// + // Properties + ///////////////////////////////// + const QString& id() const; - const QString& backendId() const; + const QString& backendId() const; - const QString& name() const; + const QString& name() const; - bool canText() const; + bool canText() const; - bool textOptional() const; + bool textOptional() const; - bool canChecksum() const; + bool canChecksum() const; - bool checksumOptional() const; + bool checksumOptional() const; - const QString& defaultDigits() const; + const QString& defaultDigits() const; - bool canFreeform() const; + bool canFreeform() const; - int preferedN() const; + int preferedN() const; - ///////////////////////////////// - // Methods - ///////////////////////////////// - public: - QString exampleDigits( int n ) const; + ///////////////////////////////// + // Methods + ///////////////////////////////// +public: + QString exampleDigits( int n ) const; - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - QString mId; - QString mBackendId; - QString mName; - bool mCanText; - bool mTextOptional; - bool mCanChecksum; - bool mChecksumOptional; - QString mDefaultDigits; - bool mCanFreeform; - int mPreferedN; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + QString mId; + QString mBackendId; + QString mName; + bool mCanText; + bool mTextOptional; + bool mCanChecksum; + bool mChecksumOptional; + QString mDefaultDigits; + bool mCanFreeform; + int mPreferedN; - }; +}; -} - -#endif // glabels_BarcodeStyle_h +#endif // BarcodeStyle_h diff --git a/glabels/ColorButton.cpp b/glabels/ColorButton.cpp index e8cdb20..2e34444 100644 --- a/glabels/ColorButton.cpp +++ b/glabels/ColorButton.cpp @@ -33,134 +33,128 @@ namespace } -namespace glabels +ColorButton::ColorButton( QWidget* parent ) + : QPushButton( parent ) { +} - ColorButton::ColorButton( QWidget* parent ) - : QPushButton( parent ) + +void ColorButton::init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color ) +{ + mDefaultColor = defaultColor; + mColorNode = ColorNode( color ); + + setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) ); + setText( "" ); + setCheckable( true ); + + mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color ); + + 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()) ); +} + + +void ColorButton::setColorNode( ColorNode colorNode ) +{ + mIsDefault = false; + + mColorNode = colorNode; + + if ( colorNode.fieldFlag() ) { + setIcon( QIcon() ); + setText( colorNode.key() ); } - - - void ColorButton::init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color ) + else { - mDefaultColor = defaultColor; - mColorNode = ColorNode( color ); - - setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) ); - setText( "" ); - setCheckable( true ); - - mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color ); - - 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()) ); - } - - - void ColorButton::setColorNode( ColorNode colorNode ) - { - mIsDefault = false; - - mColorNode = colorNode; - - if ( colorNode.fieldFlag() ) - { - setIcon( QIcon() ); - setText( colorNode.key() ); - } - else - { - setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) ); - setText( "" ); - } - } - - - void ColorButton::setColor( QColor color ) - { - mIsDefault = false; - - mColorNode.setFieldFlag( false ); - mColorNode.setColor( color ); - mColorNode.setKey( "" ); - - setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) ); - setText( "" ); - } - - - void ColorButton::setToDefault() - { - mIsDefault = true; - - mColorNode.setFieldFlag( false ); - mColorNode.setColor( mDefaultColor ); - mColorNode.setKey( "" ); - - setIcon( QIcon(ColorSwatch( SWATCH_W, SWATCH_H, mDefaultColor ) ) ); - setText( "" ); - } - - - ColorNode ColorButton::colorNode() - { - return mColorNode; - } - - - void ColorButton::setKeys( const QList keyList ) - { - mDialog->setKeys( keyList ); - } - - - void ColorButton::clearKeys() - { - mDialog->clearKeys(); - } - - - 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 ) - { - mColorNode = colorNode; - mIsDefault = isDefault; - setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) ); setText( "" ); - - emit colorChanged(); } - - +} + + +void ColorButton::setColor( QColor color ) +{ + mIsDefault = false; + + mColorNode.setFieldFlag( false ); + mColorNode.setColor( color ); + mColorNode.setKey( "" ); + + setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) ); + setText( "" ); +} + + +void ColorButton::setToDefault() +{ + mIsDefault = true; + + mColorNode.setFieldFlag( false ); + mColorNode.setColor( mDefaultColor ); + mColorNode.setKey( "" ); + + setIcon( QIcon(ColorSwatch( SWATCH_W, SWATCH_H, mDefaultColor ) ) ); + setText( "" ); +} + + +ColorNode ColorButton::colorNode() +{ + return mColorNode; +} + + +void ColorButton::setKeys( const QList keyList ) +{ + mDialog->setKeys( keyList ); +} + + +void ColorButton::clearKeys() +{ + mDialog->clearKeys(); +} + + +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 ) +{ + mColorNode = colorNode; + mIsDefault = isDefault; + + setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) ); + setText( "" ); + + emit colorChanged(); } diff --git a/glabels/ColorButton.h b/glabels/ColorButton.h index 6a0b925..25eb6e3 100644 --- a/glabels/ColorButton.h +++ b/glabels/ColorButton.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ColorButton_h -#define glabels_ColorButton_h +#ifndef ColorButton_h +#define ColorButton_h #include @@ -27,72 +27,67 @@ #include "ColorPaletteDialog.h" -namespace glabels +/// +/// Color Button +/// +class ColorButton : public QPushButton { - - /// - /// Color Button - /// - class ColorButton : public QPushButton - { - Q_OBJECT + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - ColorButton( QWidget* parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + ColorButton( QWidget* parent = 0 ); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void colorChanged(); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void colorChanged(); - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color ); - void setColorNode( ColorNode colorNode ); - void setColor( QColor color ); - void setToDefault(); - ColorNode colorNode(); - void setKeys( const QList keyList ); - void clearKeys(); + ///////////////////////////////// + // Public Methods + ///////////////////////////////// +public: + void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color ); + void setColorNode( ColorNode colorNode ); + void setColor( QColor color ); + void setToDefault(); + ColorNode colorNode(); + void setKeys( const QList keyList ); + void clearKeys(); - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onButtonToggled( bool checked ); - void onPaletteDialogAccepted(); - void onPaletteDialogRejected(); - void onPaletteDialogChanged( ColorNode colorNode, bool isDefault ); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onButtonToggled( bool checked ); + void onPaletteDialogAccepted(); + void onPaletteDialogRejected(); + void onPaletteDialogChanged( ColorNode colorNode, bool isDefault ); - ///////////////////////////////// - // Private Methods - ///////////////////////////////// - private: + ///////////////////////////////// + // Private Methods + ///////////////////////////////// +private: - ///////////////////////////////// - // Private Members - ///////////////////////////////// - private: - QColor mDefaultColor; - bool mIsDefault; - ColorNode mColorNode; + ///////////////////////////////// + // Private Members + ///////////////////////////////// +private: + QColor mDefaultColor; + bool mIsDefault; + ColorNode mColorNode; - ColorPaletteDialog* mDialog; - }; - -} + ColorPaletteDialog* mDialog; +}; -#endif // glabels_ColorButton_h +#endif // ColorButton_h diff --git a/glabels/ColorHistory.cpp b/glabels/ColorHistory.cpp index 2c3d40d..33ca66f 100644 --- a/glabels/ColorHistory.cpp +++ b/glabels/ColorHistory.cpp @@ -23,99 +23,94 @@ #include -namespace glabels +ColorHistory::ColorHistory() { - - ColorHistory::ColorHistory() - { - } - - - ColorHistory* ColorHistory::instance() - { - static ColorHistory* singletonInstance = 0; - - if ( singletonInstance == 0 ) - { - singletonInstance = new ColorHistory(); - } - - return singletonInstance; - } - - - void ColorHistory::addColor( const QColor &color ) - { - QColor oldColors[MAX_COLORS]; - QColor newColors[MAX_COLORS]; - int n; - - readColorArray( oldColors, &n ); - - int i; - newColors[0] = color; - for ( i = 0; ( i < (MAX_COLORS-1) ) && (i < n); i++ ) - { - newColors[i+1] = oldColors[i]; - } - - writeColorArray( newColors, i+1 ); - emit changed(); - } - - - QColor ColorHistory::getColor( int i ) - { - QColor colors[MAX_COLORS]; - int n; - - readColorArray( colors, &n ); - - if ( (n > 0) && (i < n) ) - { - return colors[i]; - } - else - { - return QColor( 0, 0, 0, 0 ); - } - } - - - void ColorHistory::readColorArray( QColor array[MAX_COLORS], int* n ) - { - QSettings settings; - - settings.beginGroup( "ColorHistory" ); - - settings.beginReadArray( "history" ); - *n = settings.value( "history/size", 0 ).toInt(); - for ( int i = 0; i < *n; i++ ) - { - settings.setArrayIndex(i); - array[i] = settings.value( "color" ).value(); - } - settings.endArray(); - - settings.endGroup(); - } - - - void ColorHistory::writeColorArray( const QColor array[MAX_COLORS], int n ) - { - QSettings settings; - - settings.beginGroup( "ColorHistory" ); - - settings.beginWriteArray( "history" ); - for ( int i = 0; (i < n) && (i < MAX_COLORS); i++ ) - { - settings.setArrayIndex(i); - settings.setValue( "color", array[i] ); - } - settings.endArray(); - - settings.endGroup(); - } - +} + + +ColorHistory* ColorHistory::instance() +{ + static ColorHistory* singletonInstance = 0; + + if ( singletonInstance == 0 ) + { + singletonInstance = new ColorHistory(); + } + + return singletonInstance; +} + + +void ColorHistory::addColor( const QColor &color ) +{ + QColor oldColors[MAX_COLORS]; + QColor newColors[MAX_COLORS]; + int n; + + readColorArray( oldColors, &n ); + + int i; + newColors[0] = color; + for ( i = 0; ( i < (MAX_COLORS-1) ) && (i < n); i++ ) + { + newColors[i+1] = oldColors[i]; + } + + writeColorArray( newColors, i+1 ); + emit changed(); +} + + +QColor ColorHistory::getColor( int i ) +{ + QColor colors[MAX_COLORS]; + int n; + + readColorArray( colors, &n ); + + if ( (n > 0) && (i < n) ) + { + return colors[i]; + } + else + { + return QColor( 0, 0, 0, 0 ); + } +} + + +void ColorHistory::readColorArray( QColor array[MAX_COLORS], int* n ) +{ + QSettings settings; + + settings.beginGroup( "ColorHistory" ); + + settings.beginReadArray( "history" ); + *n = settings.value( "history/size", 0 ).toInt(); + for ( int i = 0; i < *n; i++ ) + { + settings.setArrayIndex(i); + array[i] = settings.value( "color" ).value(); + } + settings.endArray(); + + settings.endGroup(); +} + + +void ColorHistory::writeColorArray( const QColor array[MAX_COLORS], int n ) +{ + QSettings settings; + + settings.beginGroup( "ColorHistory" ); + + settings.beginWriteArray( "history" ); + for ( int i = 0; (i < n) && (i < MAX_COLORS); i++ ) + { + settings.setArrayIndex(i); + settings.setValue( "color", array[i] ); + } + settings.endArray(); + + settings.endGroup(); } diff --git a/glabels/ColorHistory.h b/glabels/ColorHistory.h index 0239dda..57d03fc 100644 --- a/glabels/ColorHistory.h +++ b/glabels/ColorHistory.h @@ -18,67 +18,62 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ColorHistory_h -#define glabels_ColorHistory_h +#ifndef ColorHistory_h +#define ColorHistory_h #include #include -namespace glabels +/// +/// Barcode Backends Database +/// +class ColorHistory : public QObject { + Q_OBJECT - /// - /// Barcode Backends Database - /// - class ColorHistory : public QObject - { - Q_OBJECT +public: + static const int MAX_COLORS = 10; - public: - static const int MAX_COLORS = 10; + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +private: + ColorHistory(); - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - private: - ColorHistory(); - - public: - static ColorHistory* instance(); +public: + static ColorHistory* instance(); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void changed(); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void changed(); - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - void addColor( const QColor &color ); - QColor getColor( int i ); + ///////////////////////////////// + // Public Methods + ///////////////////////////////// +public: + void addColor( const QColor &color ); + QColor getColor( int i ); - ///////////////////////////////// - // Private Methods - ///////////////////////////////// - private: - void readColorArray( QColor array[MAX_COLORS], int* n ); - void writeColorArray( const QColor array[MAX_COLORS], int n ); + ///////////////////////////////// + // Private Methods + ///////////////////////////////// +private: + void readColorArray( QColor array[MAX_COLORS], int* n ); + void writeColorArray( const QColor array[MAX_COLORS], int n ); - ///////////////////////////////// - // Private Members - ///////////////////////////////// - private: + ///////////////////////////////// + // Private Members + ///////////////////////////////// +private: - }; - -} +}; -#endif // glabels_ColorHistory_h +#endif // ColorHistory_h diff --git a/glabels/ColorNode.cpp b/glabels/ColorNode.cpp index 68ffd2e..839286d 100644 --- a/glabels/ColorNode.cpp +++ b/glabels/ColorNode.cpp @@ -21,183 +21,177 @@ #include "ColorNode.h" -namespace glabels +/// +/// Default Constructor +/// +ColorNode::ColorNode() + : mFieldFlag(false), mColor(QColor::fromRgba(0x00000000)), mKey("") { - - /// - /// Default Constructor - /// - ColorNode::ColorNode() - : mFieldFlag(false), mColor(QColor::fromRgba(0x00000000)), mKey("") - { - } +} - /// - /// Constructor From Data - /// - ColorNode::ColorNode( bool fieldFlag, const QColor& color, const QString& key ) - : mFieldFlag(fieldFlag), mColor(color), mKey(key) - { - } +/// +/// Constructor From Data +/// +ColorNode::ColorNode( bool fieldFlag, const QColor& color, const QString& key ) + : mFieldFlag(fieldFlag), mColor(color), mKey(key) +{ +} - /// - /// Constructor From Data - /// - ColorNode::ColorNode( bool fieldFlag, uint32_t rgba, const QString& key ) - : mFieldFlag(fieldFlag), mKey(key) - { - mColor = QColor( (rgba >> 24) & 0xFF, - (rgba >> 16) & 0xFF, - (rgba >> 8) & 0xFF, - (rgba ) & 0xFF ); - } +/// +/// Constructor From Data +/// +ColorNode::ColorNode( bool fieldFlag, uint32_t rgba, const QString& key ) + : mFieldFlag(fieldFlag), mKey(key) +{ + mColor = QColor( (rgba >> 24) & 0xFF, + (rgba >> 16) & 0xFF, + (rgba >> 8) & 0xFF, + (rgba ) & 0xFF ); +} - /// - /// Constructor From Color - /// - ColorNode::ColorNode( const QColor& color ) - : mFieldFlag(false), mColor(color), mKey("") - { - } +/// +/// Constructor From Color +/// +ColorNode::ColorNode( const QColor& color ) + : mFieldFlag(false), mColor(color), mKey("") +{ +} - /// - /// Constructor From Key - /// - ColorNode::ColorNode( const QString& key ) - : mFieldFlag(true), mColor(QColor::fromRgba(0x00000000)), mKey(key) - { - } +/// +/// Constructor From Key +/// +ColorNode::ColorNode( const QString& key ) + : mFieldFlag(true), mColor(QColor::fromRgba(0x00000000)), mKey(key) +{ +} - /// - /// == Operator - /// - bool ColorNode::operator==( const ColorNode& cn ) - { - return ( (mFieldFlag == cn.mFieldFlag) && - (mColor == cn.mColor) && - (mKey == cn.mKey) ); - } +/// +/// == Operator +/// +bool ColorNode::operator==( const ColorNode& cn ) +{ + return ( (mFieldFlag == cn.mFieldFlag) && + (mColor == cn.mColor) && + (mKey == cn.mKey) ); +} - /// - /// != Operator - /// - bool ColorNode::operator!=( const ColorNode& cn ) - { - return ( (mFieldFlag != cn.mFieldFlag) || - (mColor != cn.mColor) || - (mKey != cn.mKey) ); - } +/// +/// != Operator +/// +bool ColorNode::operator!=( const ColorNode& cn ) +{ + return ( (mFieldFlag != cn.mFieldFlag) || + (mColor != cn.mColor) || + (mKey != cn.mKey) ); +} - /// - /// Field Flag Property Getter - /// - bool ColorNode::fieldFlag( void ) const - { - return mFieldFlag; - } +/// +/// Field Flag Property Getter +/// +bool ColorNode::fieldFlag( void ) const +{ + return mFieldFlag; +} - /// - /// Field Flag Property Setter - /// - void ColorNode::setFieldFlag( bool fieldFlag ) - { - mFieldFlag = fieldFlag; - } +/// +/// Field Flag Property Setter +/// +void ColorNode::setFieldFlag( bool fieldFlag ) +{ + mFieldFlag = fieldFlag; +} - /// - /// Color Property Getter - /// - const QColor& ColorNode::color( void ) const - { - return mColor; - } +/// +/// Color Property Getter +/// +const QColor& ColorNode::color( void ) const +{ + return mColor; +} - /// - /// Color Property Setter - /// - void ColorNode::setColor( const QColor& color ) - { - mColor = color; - } +/// +/// Color Property Setter +/// +void ColorNode::setColor( const QColor& color ) +{ + mColor = color; +} - /// - /// Key Property Getter - /// - const QString& ColorNode::key( void ) const - { - return mKey; - } +/// +/// Key Property Getter +/// +const QString& ColorNode::key( void ) const +{ + return mKey; +} - /// - /// Key Property Setter - /// - void ColorNode::setKey( const QString& key ) - { - mKey = key; - } +/// +/// Key Property Setter +/// +void ColorNode::setKey( const QString& key ) +{ + mKey = key; +} - uint32_t ColorNode::rgba( void ) const - { - uint32_t c = - mColor.red() << 24 | - mColor.green() << 16 | - mColor.blue() << 8 | - mColor.alpha(); +uint32_t ColorNode::rgba( void ) const +{ + uint32_t c = + mColor.red() << 24 | + mColor.green() << 16 | + mColor.blue() << 8 | + mColor.alpha(); - return c; - } + return c; +} #if TODO - QColor ColorNode::expand( MergeRecord? record ) +QColor ColorNode::expand( MergeRecord? record ) +{ + if ( fieldFlag ) { - if ( fieldFlag ) + if ( record == null ) { - if ( record == null ) + return QColor.fromRgba(0x00000000); + } + else + { + string? text = record.evalKey( key ); + if ( text != null ) { - return QColor.fromRgba(0x00000000); - } - else - { - string? text = record.evalKey( key ); - if ( text != null ) + Gdk.Color gdkColor = Gdk.Color(); + if ( Gdk.Color.parse( text, out gdkColor ) ) { - Gdk.Color gdkColor = Gdk.Color(); - if ( Gdk.Color.parse( text, out gdkColor ) ) - { - Color color = Color.from_gdkColor( gdkColor ); - return color; - } - else - { - return Color.fromRgba(0x00000000); - } + Color color = Color.from_gdkColor( gdkColor ); + return color; } else { return Color.fromRgba(0x00000000); } } - } - else - { - return color; + else + { + return Color.fromRgba(0x00000000); + } } } -#endif - + else + { + return color; + } } - +#endif diff --git a/glabels/ColorNode.h b/glabels/ColorNode.h index ef06c19..4a74a8b 100644 --- a/glabels/ColorNode.h +++ b/glabels/ColorNode.h @@ -18,94 +18,90 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ColorNode_h -#define glabels_ColorNode_h +#ifndef ColorNode_h +#define ColorNode_h #include #include #include -namespace glabels +/// +/// Color Node Type +/// +struct ColorNode { - /// - /// Color Node Type - /// - struct ColorNode - { + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + ColorNode(); - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - ColorNode(); + ColorNode( bool fieldFlag, const QColor& color, const QString& key ); - ColorNode( bool fieldFlag, const QColor& color, const QString& key ); + ColorNode( bool fieldFlag, uint32_t rgba, const QString& key ); - ColorNode( bool fieldFlag, uint32_t rgba, const QString& key ); + ColorNode( const QColor& color ); - ColorNode( const QColor& color ); - - ColorNode( const QString& key ); + ColorNode( const QString& key ); - ///////////////////////////////// - // Operators - ///////////////////////////////// - public: - bool operator==( const ColorNode& cn ); + ///////////////////////////////// + // Operators + ///////////////////////////////// +public: + bool operator==( const ColorNode& cn ); - bool operator!=( const ColorNode& cn ); + bool operator!=( const ColorNode& cn ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - // - // Field Flag Property - // - bool fieldFlag( void ) const; - void setFieldFlag( bool fieldFlag ); + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + // + // Field Flag Property + // + bool fieldFlag( void ) const; + void setFieldFlag( bool fieldFlag ); - // - // Color Property - // - const QColor& color( void ) const; - void setColor( const QColor& color ); + // + // Color Property + // + const QColor& color( void ) const; + void setColor( const QColor& color ); - // - // Key Property - // - const QString& key( void ) const; - void setKey( const QString& key ); + // + // Key Property + // + const QString& key( void ) const; + void setKey( const QString& key ); - ///////////////////////////////// - // Methods - ///////////////////////////////// - public: - uint32_t rgba( void ) const; + ///////////////////////////////// + // Methods + ///////////////////////////////// +public: + uint32_t rgba( void ) const; #if TODO - QColor expand( MergeRecord? record ); + QColor expand( MergeRecord? record ); #endif - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - bool mFieldFlag; - QColor mColor; - QString mKey; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + bool mFieldFlag; + QColor mColor; + QString mKey; - }; +}; -} -#endif // glabels_ColorNode_h +#endif // ColorNode_h diff --git a/glabels/ColorPaletteButtonItem.cpp b/glabels/ColorPaletteButtonItem.cpp index cbbe7be..0f8cbe8 100644 --- a/glabels/ColorPaletteButtonItem.cpp +++ b/glabels/ColorPaletteButtonItem.cpp @@ -36,91 +36,85 @@ namespace } -namespace glabels +/// +/// Constructor From Data +/// +ColorPaletteButtonItem::ColorPaletteButtonItem( const QString& text, QWidget* parent ) + : QWidget(parent), mText(text), mHover(false) { - - /// - /// Constructor From Data - /// - ColorPaletteButtonItem::ColorPaletteButtonItem( const QString& text, QWidget* parent ) - : QWidget(parent), mText(text), mHover(false) - { - setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) ); - setMinimumSize( hBox+2*border+1, hBox+2*border+1 ); - } - - - /// - /// Paint Event - /// - void ColorPaletteButtonItem::paintEvent( QPaintEvent* event ) - { - QPainter painter(this); - - // - // Draw background - // - if ( mHover ) - { - QLinearGradient gradient( 0, 0, 0, height() ); - gradient.setColorAt( 0, palette().color( QPalette::Highlight ).lighter() ); - gradient.setColorAt( 1, palette().color( QPalette::Highlight ) ); - painter.setBrush( QBrush( gradient ) ); - - QPen pen( palette().color( QPalette::Text ) ); - pen.setWidth( outlineWidthPixels ); - painter.setPen( pen ); - - painter.drawRect( 0, 0, width()-1, height()-1 ); - } - - // - // Draw text - // - painter.setBrush( QBrush( Qt::NoBrush ) ); - - if ( mHover ) - { - painter.setPen( QPen( palette().color( QPalette::HighlightedText ) ) ); - } - else - { - painter.setPen( QPen( palette().color( QPalette::Text ) ) ); - } - - QRect textRect( border, border, width()-2*border, hBox ); - - painter.drawText( textRect, Qt::AlignLeft|Qt::AlignVCenter, mText ); - } - - - /// - /// Enter Event - /// - void ColorPaletteButtonItem::enterEvent( QEvent* event ) - { - mHover = true; - update(); - } - - - /// - /// Leave Event - /// - void ColorPaletteButtonItem::leaveEvent( QEvent* event ) - { - mHover = false; - update(); - } - - - /// - /// Mouse Press Event - /// - void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event ) - { - emit activated(); - } - + setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) ); + setMinimumSize( hBox+2*border+1, hBox+2*border+1 ); } + +/// +/// Paint Event +/// +void ColorPaletteButtonItem::paintEvent( QPaintEvent* event ) +{ + QPainter painter(this); + + // + // Draw background + // + if ( mHover ) + { + QLinearGradient gradient( 0, 0, 0, height() ); + gradient.setColorAt( 0, palette().color( QPalette::Highlight ).lighter() ); + gradient.setColorAt( 1, palette().color( QPalette::Highlight ) ); + painter.setBrush( QBrush( gradient ) ); + + QPen pen( palette().color( QPalette::Text ) ); + pen.setWidth( outlineWidthPixels ); + painter.setPen( pen ); + + painter.drawRect( 0, 0, width()-1, height()-1 ); + } + + // + // Draw text + // + painter.setBrush( QBrush( Qt::NoBrush ) ); + + if ( mHover ) + { + painter.setPen( QPen( palette().color( QPalette::HighlightedText ) ) ); + } + else + { + painter.setPen( QPen( palette().color( QPalette::Text ) ) ); + } + + QRect textRect( border, border, width()-2*border, hBox ); + + painter.drawText( textRect, Qt::AlignLeft|Qt::AlignVCenter, mText ); +} + + +/// +/// Enter Event +/// +void ColorPaletteButtonItem::enterEvent( QEvent* event ) +{ + mHover = true; + update(); +} + + +/// +/// Leave Event +/// +void ColorPaletteButtonItem::leaveEvent( QEvent* event ) +{ + mHover = false; + update(); +} + + +/// +/// Mouse Press Event +/// +void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event ) +{ + emit activated(); +} diff --git a/glabels/ColorPaletteButtonItem.h b/glabels/ColorPaletteButtonItem.h index 57769e6..3e7af47 100644 --- a/glabels/ColorPaletteButtonItem.h +++ b/glabels/ColorPaletteButtonItem.h @@ -18,57 +18,52 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ColorPaletteButtonItem_h -#define glabels_ColorPaletteButtonItem_h +#ifndef ColorPaletteButtonItem_h +#define ColorPaletteButtonItem_h #include #include -namespace glabels +/// +/// Color Palette Item +/// +class ColorPaletteButtonItem : public QWidget { + Q_OBJECT - /// - /// Color Palette Item - /// - class ColorPaletteButtonItem : public QWidget - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - ColorPaletteButtonItem( const QString& text, QWidget* parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + ColorPaletteButtonItem( const QString& text, QWidget* parent = 0 ); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void activated(); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void activated(); - ///////////////////////////////// - // Event handlers - ///////////////////////////////// - protected: - void paintEvent( QPaintEvent* event ); - void enterEvent( QEvent* event ); - void leaveEvent( QEvent* event ); - void mousePressEvent( QMouseEvent* event ); + ///////////////////////////////// + // Event handlers + ///////////////////////////////// +protected: + void paintEvent( QPaintEvent* event ); + void enterEvent( QEvent* event ); + void leaveEvent( QEvent* event ); + void mousePressEvent( QMouseEvent* event ); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - QString mText; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + QString mText; - bool mHover; - }; + bool mHover; +}; -} - -#endif // glabels_ColorPaletteButtonItem_h +#endif // ColorPaletteButtonItem_h diff --git a/glabels/ColorPaletteDialog.cpp b/glabels/ColorPaletteDialog.cpp index 89e2de1..ff31213 100644 --- a/glabels/ColorPaletteDialog.cpp +++ b/glabels/ColorPaletteDialog.cpp @@ -29,210 +29,205 @@ #include -namespace glabels +ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = { + + { "#ef2929", tr("Light Scarlet Red", "Color name") }, + { "#fcaf3e", tr("Light Orange", "Color name") }, + { "#fce94f", tr("Light Butter", "Color name") }, + { "#8ae234", tr("Light Chameleon", "Color name") }, + { "#729fcf", tr("Light Sky Blue", "Color name") }, + { "#ad7fa8", tr("Light Plum", "Color name") }, + { "#e9b96e", tr("Light Chocolate", "Color name") }, + { "#888a85", tr("Light Aluminum 1", "Color name") }, + { "#eeeeec", tr("Light Aluminum 2", "Color name") }, + + { "#cc0000", tr("Scarlet Red", "Color name") }, + { "#f57900", tr("Orange", "Color name") }, + { "#edd400", tr("Butter", "Color name") }, + { "#73d216", tr("Chameleon", "Color name") }, + { "#3465a4", tr("Sky Blue", "Color name") }, + { "#75507b", tr("Plum", "Color name") }, + { "#c17d11", tr("Chocolate", "Color name") }, + { "#555753", tr("Aluminum 1", "Color name") }, + { "#d3d7cf", tr("Aluminum 2", "Color name") }, + + { "#a40000", tr("Dark Scarlet Red", "Color name") }, + { "#ce5c00", tr("Dark Orange", "Color name") }, + { "#c4a000", tr("Dark Butter", "Color name") }, + { "#4e9a06", tr("Dark Chameleon", "Color name") }, + { "#204a87", tr("Dark Sky Blue", "Color name") }, + { "#5c3566", tr("Dark Plum", "Color name") }, + { "#8f5902", tr("Dark Chocolate", "Color name") }, + { "#2e3436", tr("Dark Aluminum 1", "Color name") }, + { "#babdb6", tr("Dark Aluminum 2", "Color name") }, + + { "#000000", tr("Black", "Color name") }, + { "#2e3436", tr("Very Dark Gray", "Color name") }, + { "#555753", tr("Darker Gray", "Color name") }, + { "#888a85", tr("Dark Gray", "Color name") }, + { "#babdb6", tr("Medium Gray", "Color name") }, + { "#d3d7cf", tr("Light Gray", "Color name") }, + { "#eeeeec", tr("Lighter Gray", "Color name") }, + { "#f3f3f3", tr("Very Light Gray", "Color name") }, + { "#ffffff", tr("White", "Color name") } +}; + + +ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel, + const QColor& defaultColor, + const QColor& color, + QWidget* parent ) + : QDialog( parent ) { + mColorHistory = ColorHistory::instance(); + connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) ); - ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = { + mDefaultColor = defaultColor; + mColorNode = ColorNode( color ); - { "#ef2929", tr("Light Scarlet Red", "Color name") }, - { "#fcaf3e", tr("Light Orange", "Color name") }, - { "#fce94f", tr("Light Butter", "Color name") }, - { "#8ae234", tr("Light Chameleon", "Color name") }, - { "#729fcf", tr("Light Sky Blue", "Color name") }, - { "#ad7fa8", tr("Light Plum", "Color name") }, - { "#e9b96e", tr("Light Chocolate", "Color name") }, - { "#888a85", tr("Light Aluminum 1", "Color name") }, - { "#eeeeec", tr("Light Aluminum 2", "Color name") }, + setStyleSheet( ".glabels--ColorPaletteDialog {background: white; border: 1px solid black}" ); + setWindowFlags( Qt::Popup | Qt::FramelessWindowHint ); - { "#cc0000", tr("Scarlet Red", "Color name") }, - { "#f57900", tr("Orange", "Color name") }, - { "#edd400", tr("Butter", "Color name") }, - { "#73d216", tr("Chameleon", "Color name") }, - { "#3465a4", tr("Sky Blue", "Color name") }, - { "#75507b", tr("Plum", "Color name") }, - { "#c17d11", tr("Chocolate", "Color name") }, - { "#555753", tr("Aluminum 1", "Color name") }, - { "#d3d7cf", tr("Aluminum 2", "Color name") }, + QVBoxLayout* vLayout = new QVBoxLayout(); + vLayout->setContentsMargins( 0, 0, 0, 0 ); + vLayout->setSpacing( 0 ); - { "#a40000", tr("Dark Scarlet Red", "Color name") }, - { "#ce5c00", tr("Dark Orange", "Color name") }, - { "#c4a000", tr("Dark Butter", "Color name") }, - { "#4e9a06", tr("Dark Chameleon", "Color name") }, - { "#204a87", tr("Dark Sky Blue", "Color name") }, - { "#5c3566", tr("Dark Plum", "Color name") }, - { "#8f5902", tr("Dark Chocolate", "Color name") }, - { "#2e3436", tr("Dark Aluminum 1", "Color name") }, - { "#babdb6", tr("Dark Aluminum 2", "Color name") }, - - { "#000000", tr("Black", "Color name") }, - { "#2e3436", tr("Very Dark Gray", "Color name") }, - { "#555753", tr("Darker Gray", "Color name") }, - { "#888a85", tr("Dark Gray", "Color name") }, - { "#babdb6", tr("Medium Gray", "Color name") }, - { "#d3d7cf", tr("Light Gray", "Color name") }, - { "#eeeeec", tr("Lighter Gray", "Color name") }, - { "#f3f3f3", tr("Very Light Gray", "Color name") }, - { "#ffffff", tr("White", "Color name") } - }; - - - ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel, - const QColor& defaultColor, - const QColor& color, - QWidget* parent ) - : QDialog( parent ) - { - mColorHistory = ColorHistory::instance(); - connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) ); - - mDefaultColor = defaultColor; - mColorNode = ColorNode( color ); - - setStyleSheet( ".glabels--ColorPaletteDialog {background: white; border: 1px solid black}" ); - setWindowFlags( Qt::Popup | Qt::FramelessWindowHint ); - - QVBoxLayout* vLayout = new QVBoxLayout(); - vLayout->setContentsMargins( 0, 0, 0, 0 ); - vLayout->setSpacing( 0 ); - - ColorPaletteButtonItem* defaultButton = new ColorPaletteButtonItem( defaultLabel ); - connect( defaultButton, SIGNAL(activated()), this, SLOT(onDefaultItemActivated()) ); - vLayout->addWidget( defaultButton ); + ColorPaletteButtonItem* defaultButton = new ColorPaletteButtonItem( defaultLabel ); + connect( defaultButton, SIGNAL(activated()), this, SLOT(onDefaultItemActivated()) ); + vLayout->addWidget( defaultButton ); - QFrame* hline1 = new QFrame; - hline1->setFrameStyle( QFrame::HLine | QFrame::Plain ); - hline1->setLineWidth( 1 ); - vLayout->addWidget( hline1 ); + QFrame* hline1 = new QFrame; + hline1->setFrameStyle( QFrame::HLine | QFrame::Plain ); + hline1->setLineWidth( 1 ); + vLayout->addWidget( hline1 ); - QGridLayout* mainPaletteLayout = new QGridLayout(); - mainPaletteLayout->setSpacing( 0 ); - for ( int iRow = 0; iRow < PALETTE_ROWS; iRow++ ) - { - for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ ) - { - int i = iRow*PALETTE_COLS + iCol; - - ColorPaletteItem* item = new ColorPaletteItem( i, - QColor( mColorTable[i].colorSpec ), - mColorTable[i].name ); - connect( item, SIGNAL(activated(int)), this, SLOT(onPaletteItemActivated(int)) ); - - mainPaletteLayout->addWidget( item, iRow, iCol ); - } - } - vLayout->addLayout( mainPaletteLayout ); - - QFrame* hline2 = new QFrame; - hline2->setFrameStyle( QFrame::HLine | QFrame::Plain ); - hline2->setLineWidth( 1 ); - vLayout->addWidget( hline2 ); - - QHBoxLayout* customPaletteLayout = new QHBoxLayout(); - customPaletteLayout->setSpacing( 0 ); + QGridLayout* mainPaletteLayout = new QGridLayout(); + mainPaletteLayout->setSpacing( 0 ); + for ( int iRow = 0; iRow < PALETTE_ROWS; iRow++ ) + { for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ ) { - mHistoryItem[iCol] = new ColorPaletteItem( iCol, QColor(0,0,0,0), "" ); - mHistoryItem[iCol]->setEnabled( false ); - connect( mHistoryItem[iCol], SIGNAL(activated(int)), this, SLOT(onHistoryItemActivated(int)) ); + int i = iRow*PALETTE_COLS + iCol; - customPaletteLayout->addWidget( mHistoryItem[iCol] ); - } - vLayout->addLayout( customPaletteLayout ); + ColorPaletteItem* item = new ColorPaletteItem( i, + QColor( mColorTable[i].colorSpec ), + mColorTable[i].name ); + connect( item, SIGNAL(activated(int)), this, SLOT(onPaletteItemActivated(int)) ); - - QFrame* hline3 = new QFrame; - hline3->setFrameStyle( QFrame::HLine | QFrame::Plain ); - hline3->setLineWidth( 1 ); - vLayout->addWidget( hline3 ); - - ColorPaletteButtonItem* customColorButton = new ColorPaletteButtonItem( tr("Custom color") ); - connect( customColorButton, SIGNAL(activated()), this, SLOT(onCustomColorItemActivated()) ); - vLayout->addWidget( customColorButton ); - - QFrame* hline4 = new QFrame; - hline4->setFrameStyle( QFrame::HLine | QFrame::Plain ); - hline4->setLineWidth( 1 ); - vLayout->addWidget( hline4 ); - - ColorPaletteButtonItem* mergeFieldButton = new ColorPaletteButtonItem( "TODO: Field Button" ); - vLayout->addWidget( mergeFieldButton ); - - setLayout( vLayout ); - - loadCustomColorHistory(); - } - - - void ColorPaletteDialog::setKeys( const QList keyList ) - { - // TODO - } - - - void ColorPaletteDialog::clearKeys() - { - // TODO - } - - - void ColorPaletteDialog::onDefaultItemActivated() - { - mColorNode.setFieldFlag( false ); - mColorNode.setColor( mDefaultColor ); - mColorNode.setKey( "" ); - - emit colorChanged( mColorNode, true ); - accept(); - } - - - void ColorPaletteDialog::onPaletteItemActivated( int id ) - { - mColorNode.setFieldFlag( false ); - mColorNode.setColor( QColor( mColorTable[id].colorSpec ) ); - mColorNode.setKey( "" ); - - emit colorChanged( mColorNode, false ); - accept(); - } - - - void ColorPaletteDialog::onHistoryItemActivated( int id ) - { - mColorNode.setFieldFlag( false ); - mColorNode.setColor( mColorHistory->getColor( id ) ); - mColorNode.setKey( "" ); - - emit colorChanged( mColorNode, false ); - accept(); - } - - - void ColorPaletteDialog::onCustomColorItemActivated() - { - // TODO - accept(); - } - - - void ColorPaletteDialog::onColorHistoryChanged() - { - loadCustomColorHistory(); - } - - - void ColorPaletteDialog::loadCustomColorHistory() - { - for ( int i = 0; i < PALETTE_COLS; i++ ) - { - QColor color = mColorHistory->getColor( i ); - - if ( color.alpha() != 0 ) - { - mHistoryItem[i]->setColor( i, color, QString(tr("Custom color #%d").arg(i) ) ); - mHistoryItem[i]->setEnabled( true ); - } + mainPaletteLayout->addWidget( item, iRow, iCol ); } } + vLayout->addLayout( mainPaletteLayout ); + QFrame* hline2 = new QFrame; + hline2->setFrameStyle( QFrame::HLine | QFrame::Plain ); + hline2->setLineWidth( 1 ); + vLayout->addWidget( hline2 ); + + QHBoxLayout* customPaletteLayout = new QHBoxLayout(); + customPaletteLayout->setSpacing( 0 ); + for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ ) + { + mHistoryItem[iCol] = new ColorPaletteItem( iCol, QColor(0,0,0,0), "" ); + mHistoryItem[iCol]->setEnabled( false ); + connect( mHistoryItem[iCol], SIGNAL(activated(int)), this, SLOT(onHistoryItemActivated(int)) ); + + customPaletteLayout->addWidget( mHistoryItem[iCol] ); + } + vLayout->addLayout( customPaletteLayout ); + + + QFrame* hline3 = new QFrame; + hline3->setFrameStyle( QFrame::HLine | QFrame::Plain ); + hline3->setLineWidth( 1 ); + vLayout->addWidget( hline3 ); + + ColorPaletteButtonItem* customColorButton = new ColorPaletteButtonItem( tr("Custom color") ); + connect( customColorButton, SIGNAL(activated()), this, SLOT(onCustomColorItemActivated()) ); + vLayout->addWidget( customColorButton ); + + QFrame* hline4 = new QFrame; + hline4->setFrameStyle( QFrame::HLine | QFrame::Plain ); + hline4->setLineWidth( 1 ); + vLayout->addWidget( hline4 ); + + ColorPaletteButtonItem* mergeFieldButton = new ColorPaletteButtonItem( "TODO: Field Button" ); + vLayout->addWidget( mergeFieldButton ); + + setLayout( vLayout ); + + loadCustomColorHistory(); +} + + +void ColorPaletteDialog::setKeys( const QList keyList ) +{ + // TODO +} + + +void ColorPaletteDialog::clearKeys() +{ + // TODO +} + + +void ColorPaletteDialog::onDefaultItemActivated() +{ + mColorNode.setFieldFlag( false ); + mColorNode.setColor( mDefaultColor ); + mColorNode.setKey( "" ); + + emit colorChanged( mColorNode, true ); + accept(); +} + + +void ColorPaletteDialog::onPaletteItemActivated( int id ) +{ + mColorNode.setFieldFlag( false ); + mColorNode.setColor( QColor( mColorTable[id].colorSpec ) ); + mColorNode.setKey( "" ); + + emit colorChanged( mColorNode, false ); + accept(); +} + + +void ColorPaletteDialog::onHistoryItemActivated( int id ) +{ + mColorNode.setFieldFlag( false ); + mColorNode.setColor( mColorHistory->getColor( id ) ); + mColorNode.setKey( "" ); + + emit colorChanged( mColorNode, false ); + accept(); +} + + +void ColorPaletteDialog::onCustomColorItemActivated() +{ + // TODO + accept(); +} + + +void ColorPaletteDialog::onColorHistoryChanged() +{ + loadCustomColorHistory(); +} + + +void ColorPaletteDialog::loadCustomColorHistory() +{ + for ( int i = 0; i < PALETTE_COLS; i++ ) + { + QColor color = mColorHistory->getColor( i ); + + if ( color.alpha() != 0 ) + { + mHistoryItem[i]->setColor( i, color, QString(tr("Custom color #%d").arg(i) ) ); + mHistoryItem[i]->setEnabled( true ); + } + } } diff --git a/glabels/ColorPaletteDialog.h b/glabels/ColorPaletteDialog.h index d63879c..bd039c8 100644 --- a/glabels/ColorPaletteDialog.h +++ b/glabels/ColorPaletteDialog.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ColorPaletteDialog_h -#define glabels_ColorPaletteDialog_h +#ifndef ColorPaletteDialog_h +#define ColorPaletteDialog_h #include #include @@ -29,83 +29,78 @@ #include "ColorPaletteItem.h" -namespace glabels +/// +/// Color Palette Dialog +/// +class ColorPaletteDialog : public QDialog { - - /// - /// Color Palette Dialog - /// - class ColorPaletteDialog : public QDialog - { - Q_OBJECT + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - ColorPaletteDialog( const QString& defaultLabel, - const QColor& defaultColor, - const QColor& color, - QWidget* parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + ColorPaletteDialog( const QString& defaultLabel, + const QColor& defaultColor, + const QColor& color, + QWidget* parent = 0 ); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void colorChanged( ColorNode colorNode, bool isDefault ); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void colorChanged( ColorNode colorNode, bool isDefault ); - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - void setKeys( const QList keyList ); - void clearKeys(); + ///////////////////////////////// + // Public Methods + ///////////////////////////////// +public: + void setKeys( const QList keyList ); + void clearKeys(); - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onDefaultItemActivated(); - void onPaletteItemActivated( int id ); - void onHistoryItemActivated( int id ); - void onCustomColorItemActivated(); - void onColorHistoryChanged(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onDefaultItemActivated(); + void onPaletteItemActivated( int id ); + void onHistoryItemActivated( int id ); + void onCustomColorItemActivated(); + void onColorHistoryChanged(); - ///////////////////////////////// - // Private Methods - ///////////////////////////////// - private: - void loadCustomColorHistory(); + ///////////////////////////////// + // Private Methods + ///////////////////////////////// +private: + void loadCustomColorHistory(); - ///////////////////////////////// - // Private Members - ///////////////////////////////// - private: - QColor mDefaultColor; - ColorNode mColorNode; + ///////////////////////////////// + // Private Members + ///////////////////////////////// +private: + QColor mDefaultColor; + ColorNode mColorNode; - static const int PALETTE_COLS = 9; - static const int PALETTE_ROWS = 4; + static const int PALETTE_COLS = 9; + static const int PALETTE_ROWS = 4; - typedef struct { - QString colorSpec; - QString name; - } ColorTableEntry; + typedef struct { + QString colorSpec; + QString name; + } ColorTableEntry; - static ColorTableEntry mColorTable[]; + static ColorTableEntry mColorTable[]; - ColorHistory* mColorHistory; - ColorPaletteItem* mHistoryItem[PALETTE_COLS]; + ColorHistory* mColorHistory; + ColorPaletteItem* mHistoryItem[PALETTE_COLS]; - }; - -} +}; -#endif // glabels_ColorPaletteDialog_h +#endif // ColorPaletteDialog_h diff --git a/glabels/ColorPaletteItem.cpp b/glabels/ColorPaletteItem.cpp index 7691d3d..5ea45b6 100644 --- a/glabels/ColorPaletteItem.cpp +++ b/glabels/ColorPaletteItem.cpp @@ -40,111 +40,105 @@ namespace } -namespace glabels +/// +/// Constructor From Data +/// +ColorPaletteItem::ColorPaletteItem( int id, + const QColor& color, + const QString& tip, + QWidget* parent ) + : QWidget(parent), mId(id), mColor(color), mTip(tip), mHover(false) { + setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); + setMinimumSize( wSwatch+2*border+1, hSwatch+2*border+1 ); + setToolTip( tip ); +} - /// - /// Constructor From Data - /// - ColorPaletteItem::ColorPaletteItem( int id, - const QColor& color, - const QString& tip, - QWidget* parent ) - : QWidget(parent), mId(id), mColor(color), mTip(tip), mHover(false) + +/// +/// Color Property Setter +/// +void ColorPaletteItem::setColor( int id, + const QColor& color, + const QString& tip ) +{ + mId = id; + mColor = color; + mTip = tip; + + setToolTip( tip ); + update(); +} + + +/// +/// Paint Event +/// +void ColorPaletteItem::paintEvent( QPaintEvent* event ) +{ + QPainter painter(this); + + // + // Draw swatch + // + if ( isEnabled() ) { - setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) ); - setMinimumSize( wSwatch+2*border+1, hSwatch+2*border+1 ); - setToolTip( tip ); - } - - - /// - /// Color Property Setter - /// - void ColorPaletteItem::setColor( int id, - const QColor& color, - const QString& tip ) - { - mId = id; - mColor = color; - mTip = tip; - - setToolTip( tip ); - update(); - } - - - /// - /// Paint Event - /// - void ColorPaletteItem::paintEvent( QPaintEvent* event ) - { - QPainter painter(this); - - // - // Draw swatch - // - if ( isEnabled() ) + if ( mHover ) { - if ( mHover ) - { - QPen pen( palette().color( QPalette::Text ) ); - pen.setWidth( 2*outlineWidthPixels ); - pen.setJoinStyle( Qt::MiterJoin ); - painter.setPen( pen ); - painter.setBrush( QBrush( mColor ) ); - painter.drawRect( 1, 1, width()-2, height()-2 ); - } - else - { - QPen pen( palette().color( QPalette::Text ) ); - pen.setWidth( outlineWidthPixels ); - painter.setPen( pen ); - painter.setBrush( QBrush( mColor ) ); - painter.drawRect( border, border, wSwatch, hSwatch ); - } - - + QPen pen( palette().color( QPalette::Text ) ); + pen.setWidth( 2*outlineWidthPixels ); + pen.setJoinStyle( Qt::MiterJoin ); + painter.setPen( pen ); + painter.setBrush( QBrush( mColor ) ); + painter.drawRect( 1, 1, width()-2, height()-2 ); } else { - QPen pen( palette().color( QPalette::Disabled, QPalette::Text ) ); + QPen pen( palette().color( QPalette::Text ) ); pen.setWidth( outlineWidthPixels ); painter.setPen( pen ); painter.setBrush( QBrush( mColor ) ); painter.drawRect( border, border, wSwatch, hSwatch ); } + } - - - /// - /// Enter Event - /// - void ColorPaletteItem::enterEvent( QEvent* event ) + else { - mHover = true; - update(); - } - - - /// - /// Leave Event - /// - void ColorPaletteItem::leaveEvent( QEvent* event ) - { - mHover = false; - update(); - } - - - /// - /// Mouse Press Event - /// - void ColorPaletteItem::mousePressEvent( QMouseEvent* event ) - { - emit activated( mId ); + QPen pen( palette().color( QPalette::Disabled, QPalette::Text ) ); + pen.setWidth( outlineWidthPixels ); + painter.setPen( pen ); + painter.setBrush( QBrush( mColor ) ); + painter.drawRect( border, border, wSwatch, hSwatch ); } } + +/// +/// Enter Event +/// +void ColorPaletteItem::enterEvent( QEvent* event ) +{ + mHover = true; + update(); +} + + +/// +/// Leave Event +/// +void ColorPaletteItem::leaveEvent( QEvent* event ) +{ + mHover = false; + update(); +} + + +/// +/// Mouse Press Event +/// +void ColorPaletteItem::mousePressEvent( QMouseEvent* event ) +{ + emit activated( mId ); +} diff --git a/glabels/ColorPaletteItem.h b/glabels/ColorPaletteItem.h index a8f961e..93c63de 100644 --- a/glabels/ColorPaletteItem.h +++ b/glabels/ColorPaletteItem.h @@ -18,71 +18,66 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ColorPaletteItem_h -#define glabels_ColorPaletteItem_h +#ifndef ColorPaletteItem_h +#define ColorPaletteItem_h #include #include -namespace glabels +/// +/// Color Palette Item +/// +class ColorPaletteItem : public QWidget { + Q_OBJECT - /// - /// Color Palette Item - /// - class ColorPaletteItem : public QWidget - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - ColorPaletteItem( int id, - const QColor& color, - const QString& tip, - QWidget* parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + ColorPaletteItem( int id, + const QColor& color, + const QString& tip, + QWidget* parent = 0 ); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void activated( int id ); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void activated( int id ); - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - void setColor( int id, - const QColor& color, - const QString& tip ); + ///////////////////////////////// + // Public Methods + ///////////////////////////////// +public: + void setColor( int id, + const QColor& color, + const QString& tip ); - ///////////////////////////////// - // Event handlers - ///////////////////////////////// - protected: - void paintEvent( QPaintEvent* event ); - void enterEvent( QEvent* event ); - void leaveEvent( QEvent* event ); - void mousePressEvent( QMouseEvent* event ); + ///////////////////////////////// + // Event handlers + ///////////////////////////////// +protected: + void paintEvent( QPaintEvent* event ); + void enterEvent( QEvent* event ); + void leaveEvent( QEvent* event ); + void mousePressEvent( QMouseEvent* event ); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - int mId; - QColor mColor; - QString mTip; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + int mId; + QColor mColor; + QString mTip; - bool mHover; - }; + bool mHover; +}; -} - -#endif // glabels_ColorPaletteItem_h +#endif // ColorPaletteItem_h diff --git a/glabels/ColorSwatch.cpp b/glabels/ColorSwatch.cpp index 4e20b42..dc2c75c 100644 --- a/glabels/ColorSwatch.cpp +++ b/glabels/ColorSwatch.cpp @@ -33,28 +33,23 @@ namespace } -namespace glabels +/// +/// Constructor +/// +ColorSwatch::ColorSwatch( int w, int h, const QColor& color ) + : QPixmap( w, h ) { + fill( Qt::transparent ); - /// - /// Constructor - /// - ColorSwatch::ColorSwatch( int w, int h, const QColor& color ) - : QPixmap( w, h ) - { - fill( Qt::transparent ); + QPainter painter(this ); - QPainter painter(this ); + painter.setBackgroundMode( Qt::TransparentMode ); - painter.setBackgroundMode( Qt::TransparentMode ); - - QBrush brush( color ); - QPen pen( outlineColor ); - pen.setWidth( outlineWidthPixels ); - - painter.setBrush( brush ); - painter.setPen( pen ); - painter.drawRect( 1, 1, w-2, h-2 ); - } + QBrush brush( color ); + QPen pen( outlineColor ); + pen.setWidth( outlineWidthPixels ); + painter.setBrush( brush ); + painter.setPen( pen ); + painter.drawRect( 1, 1, w-2, h-2 ); } diff --git a/glabels/ColorSwatch.h b/glabels/ColorSwatch.h index fadc2ff..19f42e0 100644 --- a/glabels/ColorSwatch.h +++ b/glabels/ColorSwatch.h @@ -18,29 +18,25 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ColorSwatch_h -#define glabels_ColorSwatch_h +#ifndef ColorSwatch_h +#define ColorSwatch_h #include -namespace glabels +/// +/// Simple Preview Widget +/// +class ColorSwatch : public QPixmap { - /// - /// Simple Preview Widget - /// - class ColorSwatch : public QPixmap - { + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + ColorSwatch( int w, int h, const QColor& color ); - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - ColorSwatch( int w, int h, const QColor& color ); +}; - }; -} - -#endif // glabels_ColorSwatch_h +#endif // ColorSwatch_h diff --git a/glabels/Cursors.cpp b/glabels/Cursors.cpp index 923adfb..34556d9 100644 --- a/glabels/Cursors.cpp +++ b/glabels/Cursors.cpp @@ -24,37 +24,37 @@ #include -glabels::Cursors::Barcode::Barcode() +Cursors::Barcode::Barcode() : QCursor( QPixmap(":cursors/32x32/cursor_barcode.png"), 7, 7 ) { } -glabels::Cursors::Box::Box() +Cursors::Box::Box() : QCursor( QPixmap(":cursors/32x32/cursor_box.png"), 7, 7 ) { } -glabels::Cursors::Ellipse::Ellipse() +Cursors::Ellipse::Ellipse() : QCursor( QPixmap(":cursors/32x32/cursor_ellipse.png"), 7, 7 ) { } -glabels::Cursors::Image::Image() +Cursors::Image::Image() : QCursor( QPixmap(":cursors/32x32/cursor_image.png"), 7, 7 ) { } -glabels::Cursors::Line::Line() +Cursors::Line::Line() : QCursor( QPixmap(":cursors/32x32/cursor_line.png"), 7, 7 ) { } -glabels::Cursors::Text::Text() +Cursors::Text::Text() : QCursor( QPixmap(":cursors/32x32/cursor_text.png"), 7, 7 ) { } diff --git a/glabels/Cursors.h b/glabels/Cursors.h index d3491dc..512159b 100644 --- a/glabels/Cursors.h +++ b/glabels/Cursors.h @@ -18,66 +18,62 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_Cursors_h -#define glabels_Cursors_h +#ifndef Cursors_h +#define Cursors_h #include -namespace glabels +/// +/// Glabels Cursors +/// +namespace Cursors { - /// - /// Glabels Cursors - /// - namespace Cursors - { - - class Barcode : public QCursor - { - public: - Barcode(); - }; + class Barcode : public QCursor + { + public: + Barcode(); + }; - class Box : public QCursor - { - public: - Box(); - }; + class Box : public QCursor + { + public: + Box(); + }; - class Ellipse : public QCursor - { - public: - Ellipse(); - }; + class Ellipse : public QCursor + { + public: + Ellipse(); + }; - class Image : public QCursor - { - public: - Image(); - }; + class Image : public QCursor + { + public: + Image(); + }; - class Line : public QCursor - { - public: - Line(); - }; + class Line : public QCursor + { + public: + Line(); + }; - class Text : public QCursor - { - public: - Text(); - }; + class Text : public QCursor + { + public: + Text(); + }; - - } } -#endif // glabels_Cursors_h + +#endif // Cursors_h diff --git a/glabels/FieldButton.cpp b/glabels/FieldButton.cpp index c2361ff..fc61aaf 100644 --- a/glabels/FieldButton.cpp +++ b/glabels/FieldButton.cpp @@ -21,101 +21,94 @@ #include "FieldButton.h" -namespace glabels +/// +/// Constructor +/// +FieldButton::FieldButton( QWidget* parent ) + : QPushButton(parent) { + setEnabled( false ); - /// - /// Constructor - /// - FieldButton::FieldButton( QWidget* parent ) - : QPushButton(parent) + mMenu = new FieldMenu(); + setMenu( mMenu ); + + connect( mMenu, SIGNAL(keySelected(const QString&)), this, SLOT(onMenuKeySelected(const QString&)) ); +} + + +void FieldButton::setName( const QString& name ) +{ + if ( name.isNull() || name.isEmpty() ) { - setEnabled( false ); - - mMenu = new FieldMenu(); - setMenu( mMenu ); - - connect( mMenu, SIGNAL(keySelected(const QString&)), this, SLOT(onMenuKeySelected(const QString&)) ); + setText( tr("(None)") ); + mLabelIsKey = false; } - - - void FieldButton::setName( const QString& name ) + else { - if ( name.isNull() || name.isEmpty() ) - { - setText( tr("(None)") ); - mLabelIsKey = false; - } - else - { - setText( name ); - mLabelIsKey = true; - } + setText( name ); + mLabelIsKey = true; } +} - void FieldButton::setKeys( const QList& keyList ) +void FieldButton::setKeys( const QList& keyList ) +{ + mMenu->setKeys( keyList ); + + if ( keyList.length() > 0 ) { - 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; + mKey = keyList.first(); if ( mLabelIsKey ) { - setText( key ); + setText( mKey ); + } + else + { + setText( tr("(None)") ); } - emit keySelected( key ); + 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 index 4e792ae..b05f2c8 100644 --- a/glabels/FieldButton.h +++ b/glabels/FieldButton.h @@ -18,72 +18,67 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_FieldButton_h -#define glabels_FieldButton_h +#ifndef FieldButton_h +#define FieldButton_h #include #include #include "FieldMenu.h" -namespace glabels +/// +/// Field Button +/// +class FieldButton : public QPushButton { + Q_OBJECT - /// - /// Field Button - /// - class FieldButton : public QPushButton - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - FieldButton( QWidget* parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + FieldButton( QWidget* parent = 0 ); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void keySelected( const QString& key ); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void keySelected( const QString& key ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - QString key() const; + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + QString key() const; - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - void setName( const QString& name = "" ); - void setKeys( const QList& keyList ); - void clearKeys(); + ///////////////////////////////// + // Public Methods + ///////////////////////////////// +public: + void setName( const QString& name = "" ); + void setKeys( const QList& keyList ); + void clearKeys(); - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onMenuKeySelected( const QString& key ); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onMenuKeySelected( const QString& key ); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - FieldMenu* mMenu; - QString mKey; - bool mLabelIsKey; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + FieldMenu* mMenu; + QString mKey; + bool mLabelIsKey; - }; +}; -} - -#endif // glabels_FieldButton_h +#endif // FieldButton_h diff --git a/glabels/FieldMenu.cpp b/glabels/FieldMenu.cpp index 60f3e02..296c4ec 100644 --- a/glabels/FieldMenu.cpp +++ b/glabels/FieldMenu.cpp @@ -23,42 +23,35 @@ #include "FieldMenuItem.h" -namespace glabels +/// +/// Constructor +/// +FieldMenu::FieldMenu() { - - /// - /// 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 ); - } - - } + +/// +/// 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 index d409885..d598a1b 100644 --- a/glabels/FieldMenu.h +++ b/glabels/FieldMenu.h @@ -18,59 +18,54 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_FieldMenu_h -#define glabels_FieldMenu_h +#ifndef FieldMenu_h +#define FieldMenu_h #include #include -namespace glabels +/// +/// Field Menu +/// +class FieldMenu : public QMenu { + Q_OBJECT - /// - /// Field Menu - /// - class FieldMenu : public QMenu - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - FieldMenu(); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + FieldMenu(); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void keySelected( const QString& key ); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void keySelected( const QString& key ); - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - void setKeys( const QList& keyList ); + ///////////////////////////////// + // Public Methods + ///////////////////////////////// +public: + void setKeys( const QList& keyList ); - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onMenuItemActivated( const QString& key ); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onMenuItemActivated( const QString& key ); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: - }; +}; -} - -#endif // glabels_FieldMenu_h +#endif // FieldMenu_h diff --git a/glabels/FieldMenuItem.cpp b/glabels/FieldMenuItem.cpp index 9ccae90..d1e342a 100644 --- a/glabels/FieldMenuItem.cpp +++ b/glabels/FieldMenuItem.cpp @@ -21,37 +21,31 @@ #include "FieldMenuItem.h" -namespace glabels +/// +/// Constructor From Data +/// +FieldMenuItem::FieldMenuItem( const QString& key, QObject* parent ) + : QAction(parent), mKey(key) { + setText( key ); - /// - /// 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 ); - } - + 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 index 47f73ca..90f671a 100644 --- a/glabels/FieldMenuItem.h +++ b/glabels/FieldMenuItem.h @@ -18,60 +18,55 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_FieldMenuItem_h -#define glabels_FieldMenuItem_h +#ifndef FieldMenuItem_h +#define FieldMenuItem_h #include #include -namespace glabels +/// +/// Field Menu Item +/// +class FieldMenuItem : public QAction { + Q_OBJECT - /// - /// Field Menu Item - /// - class FieldMenuItem : public QAction - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - FieldMenuItem( const QString& key, QObject* parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + FieldMenuItem( const QString& key, QObject* parent = 0 ); - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void activated( const QString& key ); + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void activated( const QString& key ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - QString key() const; + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + QString key() const; - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onTriggered(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onTriggered(); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - const QString mKey; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + const QString mKey; - }; +}; -} - -#endif // glabels_FieldMenuItem_h +#endif // FieldMenuItem_h diff --git a/glabels/File.cpp b/glabels/File.cpp index bf1d58f..8cbcc49 100644 --- a/glabels/File.cpp +++ b/glabels/File.cpp @@ -31,195 +31,189 @@ #include -namespace glabels +/// @TODO keep track of cwd between open/save dialogs + +/// +/// New Label Dialog +/// +void File::newLabel( MainWindow *window ) { - /// @TODO keep track of cwd between open/save dialogs + // @TODO lookup latest template, if none default based on locale + const glabels::Template* tmplate = glabels::Db::lookupTemplateFromBrandPart( "Avery", "5159" ); + LabelModel* label = new LabelModel(); + label->setTmplate( tmplate ); + label->setRotate( false ); - /// - /// New Label Dialog - /// - void File::newLabel( MainWindow *window ) + MainWindow *newWindow = new MainWindow(); + newWindow->setModel( label ); + newWindow->show(); +} + + +/// +/// Open File Dialog +/// +void File::open( MainWindow *window ) +{ + QString fileName = + QFileDialog::getOpenFileName( window, + tr("Open label"), + ".", + tr("glabels files (*.glabels);;All files (*)") + ); + if ( !fileName.isEmpty() ) { - // @TODO lookup latest template, if none default based on locale - const libglabels::Template* tmplate = libglabels::Db::lookupTemplateFromBrandPart( "Avery", "5159" ); - LabelModel* label = new LabelModel(); - label->setTmplate( tmplate ); - label->setRotate( false ); - - MainWindow *newWindow = new MainWindow(); - newWindow->setModel( label ); - newWindow->show(); - } - - - /// - /// Open File Dialog - /// - void File::open( MainWindow *window ) - { - QString fileName = - QFileDialog::getOpenFileName( window, - tr("Open label"), - ".", - tr("glabels files (*.glabels);;All files (*)") - ); - if ( !fileName.isEmpty() ) + LabelModel *label = XmlLabelParser::readFile( fileName ); + if ( label ) { - LabelModel *label = XmlLabelParser::readFile( fileName ); - if ( label ) - { - label->setFileName( fileName ); + label->setFileName( fileName ); - if ( window->isEmpty() ) - { - window->setModel( label ); - } - else - { - MainWindow *newWindow = new MainWindow(); - newWindow->setModel( label ); - newWindow->show(); - } + if ( window->isEmpty() ) + { + window->setModel( label ); } else { - QMessageBox msgBox; - msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") ); - msgBox.setStandardButtons( QMessageBox::Ok ); - msgBox.setDefaultButton( QMessageBox::Ok ); - msgBox.exec(); + MainWindow *newWindow = new MainWindow(); + newWindow->setModel( label ); + newWindow->show(); } } + else + { + QMessageBox msgBox; + msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") ); + msgBox.setStandardButtons( QMessageBox::Ok ); + msgBox.setDefaultButton( QMessageBox::Ok ); + msgBox.exec(); + } + } +} + + +/// +/// Save file +/// +bool File::save( MainWindow *window ) +{ + if ( window->model()->fileName().isEmpty() ) + { + return saveAs( window ); } - - /// - /// Save file - /// - bool File::save( MainWindow *window ) + if ( !window->model()->isModified() ) { - if ( window->model()->fileName().isEmpty() ) - { - return saveAs( window ); - } - - if ( !window->model()->isModified() ) - { - return true; - } - - XmlLabelCreator::writeFile( window->model(), window->model()->fileName() ); return true; } - - /// - /// Save file as - /// - bool File::saveAs( MainWindow *window ) - { - QString rawFileName = - QFileDialog::getSaveFileName( window, - tr("Save Label As"), - ".", - tr("glabels files (*.glabels);;All files (*)"), - 0, - QFileDialog::DontConfirmOverwrite - ); - if ( !rawFileName.isEmpty() ) - { - QString fileName = FileUtil::addExtension( rawFileName, ".glabels" ); - - - if ( QFileInfo(fileName).exists() ) - { - QMessageBox msgBox( window ); - msgBox.setWindowTitle( tr("Save Label As") ); - msgBox.setIcon( QMessageBox::Warning ); - msgBox.setText( tr("%1 already exists.").arg(fileName) ); - msgBox.setInformativeText( tr("Do you want to replace it?") ); - msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No ); - msgBox.setDefaultButton( QMessageBox::No ); - - if ( msgBox.exec() == QMessageBox::No ) - { - return saveAs( window ); - } - } - - XmlLabelCreator::writeFile( window->model(), fileName ); - window->model()->setFileName( fileName ); - return true; - } - - return false; - } - - - /// - /// Print file - /// - void File::print( MainWindow *window ) - { - qDebug() << "ACTION: file->print"; - } - - - /// - /// Close file - /// - void File::close( MainWindow *window ) - { - bool closeFlag = true; - - if ( !window->isEmpty() ) - { - QMessageBox msgBox; - msgBox.setText( tr("The document ") + window->model()->shortName() + tr(" has been modified.") ); - msgBox.setInformativeText( tr("Do you want to save your changes?") ); - msgBox.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel ); - msgBox.setDefaultButton( QMessageBox::Save ); - - int ret = msgBox.exec(); - - switch (ret) { - case QMessageBox::Save: - // Save was clicked - closeFlag = save( window ); - break; - case QMessageBox::Discard: - // Don't Save was clicked - closeFlag = true; - break; - case QMessageBox::Cancel: - // Cancel was clicked - closeFlag = false; - break; - default: - // should never be reached - closeFlag = false; - break; - } - } - - if ( closeFlag ) - { - window->close(); - } - } - - - /// - /// Exit, closing all windows - /// - void File::exit() - { - foreach ( MainWindow* window, MainWindow::windowList() ) - { - close( window ); - } - } - - + XmlLabelCreator::writeFile( window->model(), window->model()->fileName() ); + return true; } + +/// +/// Save file as +/// +bool File::saveAs( MainWindow *window ) +{ + QString rawFileName = + QFileDialog::getSaveFileName( window, + tr("Save Label As"), + ".", + tr("glabels files (*.glabels);;All files (*)"), + 0, + QFileDialog::DontConfirmOverwrite + ); + if ( !rawFileName.isEmpty() ) + { + QString fileName = FileUtil::addExtension( rawFileName, ".glabels" ); + + + if ( QFileInfo(fileName).exists() ) + { + QMessageBox msgBox( window ); + msgBox.setWindowTitle( tr("Save Label As") ); + msgBox.setIcon( QMessageBox::Warning ); + msgBox.setText( tr("%1 already exists.").arg(fileName) ); + msgBox.setInformativeText( tr("Do you want to replace it?") ); + msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No ); + msgBox.setDefaultButton( QMessageBox::No ); + + if ( msgBox.exec() == QMessageBox::No ) + { + return saveAs( window ); + } + } + + XmlLabelCreator::writeFile( window->model(), fileName ); + window->model()->setFileName( fileName ); + return true; + } + + return false; +} + + +/// +/// Print file +/// +void File::print( MainWindow *window ) +{ + qDebug() << "ACTION: file->print"; +} + + +/// +/// Close file +/// +void File::close( MainWindow *window ) +{ + bool closeFlag = true; + + if ( !window->isEmpty() ) + { + QMessageBox msgBox; + msgBox.setText( tr("The document ") + window->model()->shortName() + tr(" has been modified.") ); + msgBox.setInformativeText( tr("Do you want to save your changes?") ); + msgBox.setStandardButtons( QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel ); + msgBox.setDefaultButton( QMessageBox::Save ); + + int ret = msgBox.exec(); + + switch (ret) { + case QMessageBox::Save: + // Save was clicked + closeFlag = save( window ); + break; + case QMessageBox::Discard: + // Don't Save was clicked + closeFlag = true; + break; + case QMessageBox::Cancel: + // Cancel was clicked + closeFlag = false; + break; + default: + // should never be reached + closeFlag = false; + break; + } + } + + if ( closeFlag ) + { + window->close(); + } +} + + +/// +/// Exit, closing all windows +/// +void File::exit() +{ + foreach ( MainWindow* window, MainWindow::windowList() ) + { + close( window ); + } +} diff --git a/glabels/File.h b/glabels/File.h index 37e5055..e679191 100644 --- a/glabels/File.h +++ b/glabels/File.h @@ -18,34 +18,32 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_File_h -#define glabels_File_h +#ifndef File_h +#define File_h #include -namespace glabels +class MainWindow; + + +/// +/// File Actions +/// +class File : public QObject { - class MainWindow; + Q_OBJECT - /// - /// File Actions - /// - class File : public QObject - { - Q_OBJECT +public: + static void newLabel( MainWindow *window = 0 ); + static void open( MainWindow *window ); + static bool save( MainWindow *window ); + static bool saveAs( MainWindow *window ); + static void print( MainWindow *window ); + static void close( MainWindow *window ); + static void exit(); +}; - public: - static void newLabel( MainWindow *window = 0 ); - static void open( MainWindow *window ); - static bool save( MainWindow *window ); - static bool saveAs( MainWindow *window ); - static void print( MainWindow *window ); - static void close( MainWindow *window ); - static void exit(); - }; -} - -#endif // glabels_File_h +#endif // File_h diff --git a/glabels/FileUtil.cpp b/glabels/FileUtil.cpp index 78e0880..21d0dc1 100644 --- a/glabels/FileUtil.cpp +++ b/glabels/FileUtil.cpp @@ -21,24 +21,17 @@ #include "FileUtil.h" -namespace glabels +namespace FileUtil { - namespace FileUtil + QString addExtension( const QString& rawFilename, const QString& extension ) { - - QString addExtension( const QString& rawFilename, const QString& extension ) + if ( rawFilename.endsWith( extension ) ) { - if ( rawFilename.endsWith( extension ) ) - { - return rawFilename; - } - - return rawFilename + extension; + return rawFilename; } + return rawFilename + extension; } - } - diff --git a/glabels/FileUtil.h b/glabels/FileUtil.h index 9cbad64..e704f3e 100644 --- a/glabels/FileUtil.h +++ b/glabels/FileUtil.h @@ -18,21 +18,18 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_FileUtil_h -#define glabels_FileUtil_h +#ifndef FileUtil_h +#define FileUtil_h #include -namespace glabels +namespace FileUtil { - namespace FileUtil - { - - QString addExtension( const QString& rawFilename, const QString& extension ); - } + QString addExtension( const QString& rawFilename, const QString& extension ); } -#endif // glabels_FileUtil_h + +#endif // FileUtil_h diff --git a/glabels/Handles.cpp b/glabels/Handles.cpp index 5d0387c..6e55686 100644 --- a/glabels/Handles.cpp +++ b/glabels/Handles.cpp @@ -41,7 +41,7 @@ namespace /// /// Handle Constructor /// -glabels::Handle::Handle( LabelModelObject* owner, Location location ) +Handle::Handle( LabelModelObject* owner, Location location ) : mOwner(owner), mLocation(location) { } @@ -50,7 +50,7 @@ glabels::Handle::Handle( LabelModelObject* owner, Location location ) /// /// Handle Destructor /// -glabels::Handle::~Handle() +Handle::~Handle() { } @@ -58,7 +58,7 @@ glabels::Handle::~Handle() /// /// Handle owner /// -glabels::LabelModelObject* glabels::Handle::owner() const +LabelModelObject* Handle::owner() const { return mOwner; } @@ -67,7 +67,7 @@ glabels::LabelModelObject* glabels::Handle::owner() const /// /// Handle location /// -glabels::Handle::Location glabels::Handle::location() const +Handle::Location Handle::location() const { return mLocation; } @@ -76,11 +76,11 @@ glabels::Handle::Location glabels::Handle::location() const /// /// Draw Handle at x,y /// -void glabels::Handle::drawAt( QPainter* painter, - double scale, - const libglabels::Distance& x, - const libglabels::Distance& y, - QColor color ) const +void Handle::drawAt( QPainter* painter, + double scale, + const glabels::Distance& x, + const glabels::Distance& y, + QColor color ) const { painter->save(); @@ -104,9 +104,9 @@ void glabels::Handle::drawAt( QPainter* painter, /// /// Create Handle path at x,y /// -QPainterPath glabels::Handle::pathAt( double scale, - const libglabels::Distance& x, - const libglabels::Distance& y ) const +QPainterPath Handle::pathAt( double scale, + const glabels::Distance& x, + const glabels::Distance& y ) const { QPainterPath path; @@ -122,7 +122,7 @@ QPainterPath glabels::Handle::pathAt( double scale, /// /// HandleNorthWest Constructor /// -glabels::HandleNorthWest::HandleNorthWest( LabelModelObject* owner ) +HandleNorthWest::HandleNorthWest( LabelModelObject* owner ) : Handle( owner, NW ) { } @@ -131,7 +131,7 @@ glabels::HandleNorthWest::HandleNorthWest( LabelModelObject* owner ) /// /// HandleNorthWest Destructor /// -glabels::HandleNorthWest::~HandleNorthWest() +HandleNorthWest::~HandleNorthWest() { } @@ -139,7 +139,7 @@ glabels::HandleNorthWest::~HandleNorthWest() /// /// Draw HandleNorthWest /// -void glabels::HandleNorthWest::draw( QPainter* painter, double scale ) const +void HandleNorthWest::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, 0, 0, originHandleFillColor ); } @@ -148,7 +148,7 @@ void glabels::HandleNorthWest::draw( QPainter* painter, double scale ) const /// /// HandleNorthWest Path /// -QPainterPath glabels::HandleNorthWest::path( double scale ) const +QPainterPath HandleNorthWest::path( double scale ) const { return pathAt( scale, 0, 0 ); } @@ -157,7 +157,7 @@ QPainterPath glabels::HandleNorthWest::path( double scale ) const /// /// HandleNorth Constructor /// -glabels::HandleNorth::HandleNorth( LabelModelObject* owner ) +HandleNorth::HandleNorth( LabelModelObject* owner ) : Handle( owner, N ) { } @@ -166,7 +166,7 @@ glabels::HandleNorth::HandleNorth( LabelModelObject* owner ) /// /// HandleNorth Destructor /// -glabels::HandleNorth::~HandleNorth() +HandleNorth::~HandleNorth() { } @@ -174,7 +174,7 @@ glabels::HandleNorth::~HandleNorth() /// /// Draw HandleNorth /// -void glabels::HandleNorth::draw( QPainter* painter, double scale ) const +void HandleNorth::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, mOwner->w()/2, 0, handleFillColor ); } @@ -183,7 +183,7 @@ void glabels::HandleNorth::draw( QPainter* painter, double scale ) const /// /// HandleNorth Path /// -QPainterPath glabels::HandleNorth::path( double scale ) const +QPainterPath HandleNorth::path( double scale ) const { return pathAt( scale, mOwner->w()/2, 0 ); } @@ -192,7 +192,7 @@ QPainterPath glabels::HandleNorth::path( double scale ) const /// /// HandleNorthEast Constructor /// -glabels::HandleNorthEast::HandleNorthEast( LabelModelObject* owner ) +HandleNorthEast::HandleNorthEast( LabelModelObject* owner ) : Handle( owner, NE ) { } @@ -201,7 +201,7 @@ glabels::HandleNorthEast::HandleNorthEast( LabelModelObject* owner ) /// /// HandleNorthEast Destructor /// -glabels::HandleNorthEast::~HandleNorthEast() +HandleNorthEast::~HandleNorthEast() { } @@ -209,7 +209,7 @@ glabels::HandleNorthEast::~HandleNorthEast() /// /// Draw HandleNorthEast /// -void glabels::HandleNorthEast::draw( QPainter* painter, double scale ) const +void HandleNorthEast::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, mOwner->w(), 0, handleFillColor ); } @@ -218,7 +218,7 @@ void glabels::HandleNorthEast::draw( QPainter* painter, double scale ) const /// /// HandleNorthEast Path /// -QPainterPath glabels::HandleNorthEast::path( double scale ) const +QPainterPath HandleNorthEast::path( double scale ) const { return pathAt( scale, mOwner->w(), 0 ); } @@ -227,7 +227,7 @@ QPainterPath glabels::HandleNorthEast::path( double scale ) const /// /// HandleEast Constructor /// -glabels::HandleEast::HandleEast( LabelModelObject* owner ) +HandleEast::HandleEast( LabelModelObject* owner ) : Handle( owner, E ) { } @@ -236,7 +236,7 @@ glabels::HandleEast::HandleEast( LabelModelObject* owner ) /// /// HandleEast Destructor /// -glabels::HandleEast::~HandleEast() +HandleEast::~HandleEast() { } @@ -244,7 +244,7 @@ glabels::HandleEast::~HandleEast() /// /// Draw HandleEast /// -void glabels::HandleEast::draw( QPainter* painter, double scale ) const +void HandleEast::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, mOwner->w(), mOwner->h()/2, handleFillColor ); } @@ -253,7 +253,7 @@ void glabels::HandleEast::draw( QPainter* painter, double scale ) const /// /// HandleEast Path /// -QPainterPath glabels::HandleEast::path( double scale ) const +QPainterPath HandleEast::path( double scale ) const { return pathAt( scale, mOwner->w(), mOwner->h()/2 ); } @@ -262,7 +262,7 @@ QPainterPath glabels::HandleEast::path( double scale ) const /// /// HandleSouthEast Constructor /// -glabels::HandleSouthEast::HandleSouthEast( LabelModelObject* owner ) +HandleSouthEast::HandleSouthEast( LabelModelObject* owner ) : Handle( owner, SE ) { } @@ -271,7 +271,7 @@ glabels::HandleSouthEast::HandleSouthEast( LabelModelObject* owner ) /// /// HandleSouthEast Destructor /// -glabels::HandleSouthEast::~HandleSouthEast() +HandleSouthEast::~HandleSouthEast() { } @@ -279,7 +279,7 @@ glabels::HandleSouthEast::~HandleSouthEast() /// /// Draw HandleSouthEast /// -void glabels::HandleSouthEast::draw( QPainter* painter, double scale ) const +void HandleSouthEast::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor ); } @@ -288,7 +288,7 @@ void glabels::HandleSouthEast::draw( QPainter* painter, double scale ) const /// /// HandleSouthEast Path /// -QPainterPath glabels::HandleSouthEast::path( double scale ) const +QPainterPath HandleSouthEast::path( double scale ) const { return pathAt( scale, mOwner->w(), mOwner->h() ); } @@ -297,7 +297,7 @@ QPainterPath glabels::HandleSouthEast::path( double scale ) const /// /// HandleSouth Constructor /// -glabels::HandleSouth::HandleSouth( LabelModelObject* owner ) +HandleSouth::HandleSouth( LabelModelObject* owner ) : Handle( owner, S ) { } @@ -306,7 +306,7 @@ glabels::HandleSouth::HandleSouth( LabelModelObject* owner ) /// /// HandleSouth Destructor /// -glabels::HandleSouth::~HandleSouth() +HandleSouth::~HandleSouth() { } @@ -314,7 +314,7 @@ glabels::HandleSouth::~HandleSouth() /// /// Draw HandleSouth /// -void glabels::HandleSouth::draw( QPainter* painter, double scale ) const +void HandleSouth::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, mOwner->w()/2, mOwner->h(), handleFillColor ); } @@ -323,7 +323,7 @@ void glabels::HandleSouth::draw( QPainter* painter, double scale ) const /// /// HandleSouth Path /// -QPainterPath glabels::HandleSouth::path( double scale ) const +QPainterPath HandleSouth::path( double scale ) const { return pathAt( scale, mOwner->w()/2, mOwner->h() ); } @@ -332,7 +332,7 @@ QPainterPath glabels::HandleSouth::path( double scale ) const /// /// HandleSouthWest Constructor /// -glabels::HandleSouthWest::HandleSouthWest( LabelModelObject* owner ) +HandleSouthWest::HandleSouthWest( LabelModelObject* owner ) : Handle( owner, SW ) { } @@ -341,7 +341,7 @@ glabels::HandleSouthWest::HandleSouthWest( LabelModelObject* owner ) /// /// HandleSouthWest Destructor /// -glabels::HandleSouthWest::~HandleSouthWest() +HandleSouthWest::~HandleSouthWest() { } @@ -349,7 +349,7 @@ glabels::HandleSouthWest::~HandleSouthWest() /// /// Draw HandleSouthWest /// -void glabels::HandleSouthWest::draw( QPainter* painter, double scale ) const +void HandleSouthWest::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, 0, mOwner->h(), handleFillColor ); } @@ -358,7 +358,7 @@ void glabels::HandleSouthWest::draw( QPainter* painter, double scale ) const /// /// HandleSouthWest Path /// -QPainterPath glabels::HandleSouthWest::path( double scale ) const +QPainterPath HandleSouthWest::path( double scale ) const { return pathAt( scale, 0, mOwner->h() ); } @@ -367,7 +367,7 @@ QPainterPath glabels::HandleSouthWest::path( double scale ) const /// /// HandleWest Constructor /// -glabels::HandleWest::HandleWest( LabelModelObject* owner ) +HandleWest::HandleWest( LabelModelObject* owner ) : Handle( owner, W ) { } @@ -376,7 +376,7 @@ glabels::HandleWest::HandleWest( LabelModelObject* owner ) /// /// HandleWest Destructor /// -glabels::HandleWest::~HandleWest() +HandleWest::~HandleWest() { } @@ -384,7 +384,7 @@ glabels::HandleWest::~HandleWest() /// /// Draw HandleWest /// -void glabels::HandleWest::draw( QPainter* painter, double scale ) const +void HandleWest::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, 0, mOwner->h()/2, handleFillColor ); } @@ -393,7 +393,7 @@ void glabels::HandleWest::draw( QPainter* painter, double scale ) const /// /// HandleWest Path /// -QPainterPath glabels::HandleWest::path( double scale ) const +QPainterPath HandleWest::path( double scale ) const { return pathAt( scale, 0, mOwner->h()/2 ); } @@ -402,7 +402,7 @@ QPainterPath glabels::HandleWest::path( double scale ) const /// /// HandleP1 Constructor /// -glabels::HandleP1::HandleP1( LabelModelObject* owner ) +HandleP1::HandleP1( LabelModelObject* owner ) : Handle( owner, P1 ) { } @@ -411,7 +411,7 @@ glabels::HandleP1::HandleP1( LabelModelObject* owner ) /// /// HandleP1 Destructor /// -glabels::HandleP1::~HandleP1() +HandleP1::~HandleP1() { } @@ -419,7 +419,7 @@ glabels::HandleP1::~HandleP1() /// /// Draw HandleP1 /// -void glabels::HandleP1::draw( QPainter* painter, double scale ) const +void HandleP1::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, 0, 0, originHandleFillColor ); } @@ -428,7 +428,7 @@ void glabels::HandleP1::draw( QPainter* painter, double scale ) const /// /// HandleP1 Path /// -QPainterPath glabels::HandleP1::path( double scale ) const +QPainterPath HandleP1::path( double scale ) const { return pathAt( scale, 0, 0 ); } @@ -437,7 +437,7 @@ QPainterPath glabels::HandleP1::path( double scale ) const /// /// HandleP2 Constructor /// -glabels::HandleP2::HandleP2( LabelModelObject* owner ) +HandleP2::HandleP2( LabelModelObject* owner ) : Handle( owner, P2 ) { } @@ -446,7 +446,7 @@ glabels::HandleP2::HandleP2( LabelModelObject* owner ) /// /// HandleP2 Destructor /// -glabels::HandleP2::~HandleP2() +HandleP2::~HandleP2() { } @@ -454,7 +454,7 @@ glabels::HandleP2::~HandleP2() /// /// Draw HandleP2 /// -void glabels::HandleP2::draw( QPainter* painter, double scale ) const +void HandleP2::draw( QPainter* painter, double scale ) const { drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor ); } @@ -463,7 +463,7 @@ void glabels::HandleP2::draw( QPainter* painter, double scale ) const /// /// HandleP2 Path /// -QPainterPath glabels::HandleP2::path( double scale ) const +QPainterPath HandleP2::path( double scale ) const { return pathAt( scale, mOwner->w(), mOwner->h() ); } diff --git a/glabels/Handles.h b/glabels/Handles.h index f25f9c0..300fa64 100644 --- a/glabels/Handles.h +++ b/glabels/Handles.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_Handles_h -#define glabels_Handles_h +#ifndef Handles_h +#define Handles_h #include @@ -27,288 +27,283 @@ #include "libglabels/Distance.h" -namespace glabels +class LabelModelObject; + + +/// +/// Handle Base Class +/// +class Handle { - - class LabelModelObject; - - - /// - /// Handle Base Class - /// - class Handle - { - //////////////////////////// - // Location enumeration - //////////////////////////// - public: - enum Location { NW, N, NE, E, SE, S, SW, W, P1, P2 }; + //////////////////////////// + // Location enumeration + //////////////////////////// +public: + enum Location { NW, N, NE, E, SE, S, SW, W, P1, P2 }; - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - protected: - Handle( LabelModelObject* owner, Location location ); - public: - virtual ~Handle(); + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +protected: + Handle( LabelModelObject* owner, Location location ); +public: + virtual ~Handle(); - //////////////////////////// - // Attribue Methods - //////////////////////////// - LabelModelObject* owner() const; - Location location() const; + //////////////////////////// + // Attribue Methods + //////////////////////////// + LabelModelObject* owner() const; + Location location() const; - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const = 0; - virtual QPainterPath path( double scale ) const = 0; - protected: - void drawAt( QPainter* painter, - double scale, - const libglabels::Distance& x, - const libglabels::Distance& y, - QColor color ) const; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const = 0; + virtual QPainterPath path( double scale ) const = 0; +protected: + void drawAt( QPainter* painter, + double scale, + const glabels::Distance& x, + const glabels::Distance& y, + QColor color ) const; - QPainterPath pathAt( double scale, - const libglabels::Distance& x, - const libglabels::Distance& y ) const; + QPainterPath pathAt( double scale, + const glabels::Distance& x, + const glabels::Distance& y ) const; - //////////////////////////// - // Protected Data - //////////////////////////// - protected: - LabelModelObject* mOwner; - Location mLocation; + //////////////////////////// + // Protected Data + //////////////////////////// +protected: + LabelModelObject* mOwner; + Location mLocation; - }; +}; - /// - /// HandleNorth Class - /// - class HandleNorth : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleNorth( LabelModelObject* owner ); - virtual ~HandleNorth(); +/// +/// HandleNorth Class +/// +class HandleNorth : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleNorth( LabelModelObject* owner ); + virtual ~HandleNorth(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleNorthEast Class - /// - class HandleNorthEast : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleNorthEast( LabelModelObject* owner ); - virtual ~HandleNorthEast(); +/// +/// HandleNorthEast Class +/// +class HandleNorthEast : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleNorthEast( LabelModelObject* owner ); + virtual ~HandleNorthEast(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleEast Class - /// - class HandleEast : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleEast( LabelModelObject* owner ); - virtual ~HandleEast(); +/// +/// HandleEast Class +/// +class HandleEast : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleEast( LabelModelObject* owner ); + virtual ~HandleEast(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleSouthEast Class - /// - class HandleSouthEast : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleSouthEast( LabelModelObject* owner ); - virtual ~HandleSouthEast(); +/// +/// HandleSouthEast Class +/// +class HandleSouthEast : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleSouthEast( LabelModelObject* owner ); + virtual ~HandleSouthEast(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleSouth Class - /// - class HandleSouth : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleSouth( LabelModelObject* owner ); - virtual ~HandleSouth(); +/// +/// HandleSouth Class +/// +class HandleSouth : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleSouth( LabelModelObject* owner ); + virtual ~HandleSouth(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleSouthWest Class - /// - class HandleSouthWest : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleSouthWest( LabelModelObject* owner ); - virtual ~HandleSouthWest(); +/// +/// HandleSouthWest Class +/// +class HandleSouthWest : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleSouthWest( LabelModelObject* owner ); + virtual ~HandleSouthWest(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleWest Class - /// - class HandleWest : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleWest( LabelModelObject* owner ); - virtual ~HandleWest(); +/// +/// HandleWest Class +/// +class HandleWest : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleWest( LabelModelObject* owner ); + virtual ~HandleWest(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleNorthWest Class - /// - class HandleNorthWest : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleNorthWest( LabelModelObject* owner ); - virtual ~HandleNorthWest(); +/// +/// HandleNorthWest Class +/// +class HandleNorthWest : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleNorthWest( LabelModelObject* owner ); + virtual ~HandleNorthWest(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleP1 Class - /// - class HandleP1 : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleP1( LabelModelObject* owner ); - virtual ~HandleP1(); +/// +/// HandleP1 Class +/// +class HandleP1 : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleP1( LabelModelObject* owner ); + virtual ~HandleP1(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; - /// - /// HandleP2 Class - /// - class HandleP2 : public Handle - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - HandleP2( LabelModelObject* owner ); - virtual ~HandleP2(); +/// +/// HandleP2 Class +/// +class HandleP2 : public Handle +{ + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + HandleP2( LabelModelObject* owner ); + virtual ~HandleP2(); - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - virtual void draw( QPainter* painter, double scale ) const; - virtual QPainterPath path( double scale ) const; - }; + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + virtual void draw( QPainter* painter, double scale ) const; + virtual QPainterPath path( double scale ) const; +}; -} - -#endif // glabels_Handles_h +#endif // Handles_h diff --git a/glabels/Help.cpp b/glabels/Help.cpp index 98ae170..2889b44 100644 --- a/glabels/Help.cpp +++ b/glabels/Help.cpp @@ -25,38 +25,32 @@ #include -namespace glabels +/// +/// Display Help Contents +/// +void Help::displayContents( QWidget *parent ) { - - /// - /// Display Help Contents - /// - void Help::displayContents( QWidget *parent ) - { - std::cout << "TODO: Help::displayContents" << std::endl; - } - - - /// - /// Display Help->About Dialog - /// - void Help::displayAbout( QWidget *parent ) - { - QMessageBox aboutBox( QMessageBox::NoIcon, - QMessageBox::tr("About gLabels"), - QMessageBox::tr("

gLabels-qt

" - "

x.x.x

" - "

A label and business card creation program.

" - "" - "

Homepage

" - "

Copyright © 2013 Jim Evins

" - "
"), - QMessageBox::Ok, - parent ); - aboutBox.setIconPixmap( QPixmap( ":/images/glabels-logo.png" ) ); - - aboutBox.exec(); - } - + std::cout << "TODO: Help::displayContents" << std::endl; } + +/// +/// Display Help->About Dialog +/// +void Help::displayAbout( QWidget *parent ) +{ + QMessageBox aboutBox( QMessageBox::NoIcon, + QMessageBox::tr("About gLabels"), + QMessageBox::tr("

gLabels-qt

" + "

x.x.x

" + "

A label and business card creation program.

" + "" + "

Homepage

" + "

Copyright © 2013 Jim Evins

" + "
"), + QMessageBox::Ok, + parent ); + aboutBox.setIconPixmap( QPixmap( ":/images/glabels-logo.png" ) ); + + aboutBox.exec(); +} diff --git a/glabels/Help.h b/glabels/Help.h index 82439ac..db41330 100644 --- a/glabels/Help.h +++ b/glabels/Help.h @@ -18,25 +18,23 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_Help_h -#define glabels_Help_h +#ifndef Help_h +#define Help_h #include -namespace glabels +/// +/// Help Actions +/// +namespace Help { - /// - /// Help Actions - /// - namespace Help - { - void displayContents( QWidget *parent ); - void displayAbout( QWidget *parent ); - } + void displayContents( QWidget *parent ); + void displayAbout( QWidget *parent ); } -#endif // glabels_Help_h + +#endif // Help_h diff --git a/glabels/Icons.h b/glabels/Icons.h index 292d9d5..63c489d 100644 --- a/glabels/Icons.h +++ b/glabels/Icons.h @@ -18,456 +18,453 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_Icons_h -#define glabels_Icons_h +#ifndef Icons_h +#define Icons_h #include -namespace glabels +/// +/// Glabels Icons +/// +namespace Icons { + class Arrow : public QIcon + { + public: + Arrow() + { + addFile( ":icons/16x16/actions/glabels-arrow.png" ); + addFile( ":icons/24x24/actions/glabels-arrow.png" ); + } + }; + + + class Barcode : public QIcon + { + public: + Barcode() + { + addFile( ":icons/16x16/actions/glabels-barcode.png" ); + addFile( ":icons/24x24/actions/glabels-barcode.png" ); + } + }; + + + class Box : public QIcon + { + public: + Box() + { + addFile( ":icons/16x16/actions/glabels-box.png" ); + addFile( ":icons/24x24/actions/glabels-box.png" ); + } + }; + + + class Ellipse : public QIcon + { + public: + Ellipse() + { + addFile( ":icons/16x16/actions/glabels-ellipse.png" ); + addFile( ":icons/24x24/actions/glabels-ellipse.png" ); + } + }; + + + class Image : public QIcon + { + public: + Image() + { + addFile( ":icons/16x16/actions/glabels-image.png" ); + addFile( ":icons/24x24/actions/glabels-image.png" ); + } + }; + + + class Line : public QIcon + { + public: + Line() + { + addFile( ":icons/16x16/actions/glabels-line.png" ); + addFile( ":icons/24x24/actions/glabels-line.png" ); + } + }; + + + class Text : public QIcon + { + public: + Text() + { + addFile( ":icons/16x16/actions/glabels-text.png" ); + addFile( ":icons/24x24/actions/glabels-text.png" ); + } + }; + + + class Merge : public QIcon + { + public: + Merge() + { + addFile( ":icons/16x16/actions/glabels-merge.png" ); + addFile( ":icons/24x24/actions/glabels-merge.png" ); + } + }; + + + class ObjectProperties : public QIcon + { + public: + ObjectProperties() + { + addFile( ":icons/16x16/actions/glabels-object-properties.png" ); + addFile( ":icons/24x24/actions/glabels-object-properties.png" ); + } + }; + + + class AlignLeft : public QIcon + { + public: + AlignLeft() + { + addFile( ":icons/16x16/actions/glabels-align-left.png" ); + } + }; + + + class AlignHCenter : public QIcon + { + public: + AlignHCenter() + { + addFile( ":icons/16x16/actions/glabels-align-hcenter.png" ); + } + }; + + + class AlignRight : public QIcon + { + public: + AlignRight() + { + addFile( ":icons/16x16/actions/glabels-align-right.png" ); + } + }; + + + class AlignBottom : public QIcon + { + public: + AlignBottom() + { + addFile( ":icons/16x16/actions/glabels-align-bottom.png" ); + } + }; + + + class AlignVCenter : public QIcon + { + public: + AlignVCenter() + { + addFile( ":icons/16x16/actions/glabels-align-vcenter.png" ); + } + }; + + + class AlignTop : public QIcon + { + public: + AlignTop() + { + addFile( ":icons/16x16/actions/glabels-align-top.png" ); + } + }; + + + class CenterHoriz : public QIcon + { + public: + CenterHoriz() + { + addFile( ":icons/16x16/actions/glabels-center-horiz.png" ); + } + }; + + + class CenterVert : public QIcon + { + public: + CenterVert() + { + addFile( ":icons/16x16/actions/glabels-center-vert.png" ); + } + }; + + + class FlipHoriz : public QIcon + { + public: + FlipHoriz() + { + addFile( ":icons/16x16/actions/glabels-flip-horiz.png" ); + } + }; + + + class FlipVert : public QIcon + { + public: + FlipVert() + { + addFile( ":icons/16x16/actions/glabels-flip-vert.png" ); + } + }; + + + class RotateLeft : public QIcon + { + public: + RotateLeft() + { + addFile( ":icons/16x16/actions/glabels-rotate-left.png" ); + } + }; + + + class RotateRight : public QIcon + { + public: + RotateRight() + { + addFile( ":icons/16x16/actions/glabels-rotate-right.png" ); + } + }; + + + class OrderBottom : public QIcon + { + public: + OrderBottom() + { + addFile( ":icons/16x16/actions/glabels-order-bottom.png" ); + } + }; + + + class OrderTop : public QIcon + { + public: + OrderTop() + { + addFile( ":icons/16x16/actions/glabels-order-top.png" ); + } + }; + + + class AlignTextBottom : public QIcon + { + public: + AlignTextBottom() + { + addFile( ":icons/24x24/actions/glabels-align-text-bottom.png" ); + } + }; + + + class AlignTextMiddle : public QIcon + { + public: + AlignTextMiddle() + { + addFile( ":icons/24x24/actions/glabels-align-text-middle.png" ); + } + }; + + + class AlignTextTop : public QIcon + { + public: + AlignTextTop() + { + addFile( ":icons/24x24/actions/glabels-align-text-top.png" ); + } + }; + + + class BucketFill : public QIcon + { + public: + BucketFill() + { + addFile( ":icons/16x16/actions/glabels-bucket-fill.png" ); + addFile( ":icons/24x24/actions/glabels-bucket-fill.png" ); + } + }; + + + class Pencil : public QIcon + { + public: + Pencil() + { + addFile( ":icons/16x16/actions/glabels-pencil.png" ); + addFile( ":icons/24x24/actions/glabels-pencil.png" ); + } + }; + + + class Glabels : public QIcon + { + public: + Glabels() + { + addFile( ":icons/16x16/apps/glabels.png" ); + addFile( ":icons/24x24/apps/glabels.png" ); + addFile( ":icons/32x32/apps/glabels.png" ); + addFile( ":icons/48x48/apps/glabels.png" ); + addFile( ":icons/scalable/apps/glabels.svg" ); + } + }; + + /// - /// Glabels Icons + /// Fallback Icons. These are fallbacks for icons that would normally come from the current theme, + /// if supported. These icons are copied from the mate-icon-theme (GPL-v3 or CC-BY-SA-v3). /// - namespace Icons + namespace Fallback { - class Arrow : public QIcon + class EditCopy : public QIcon { public: - Arrow() + EditCopy() { - addFile( ":icons/16x16/actions/glabels-arrow.png" ); - addFile( ":icons/24x24/actions/glabels-arrow.png" ); + addFile( ":icons/24x24/actions/edit-copy.png" ); } }; - class Barcode : public QIcon + class EditCut : public QIcon { public: - Barcode() + EditCut() { - addFile( ":icons/16x16/actions/glabels-barcode.png" ); - addFile( ":icons/24x24/actions/glabels-barcode.png" ); + addFile( ":icons/24x24/actions/edit-cut.png" ); } }; - class Box : public QIcon + class EditPaste : public QIcon { public: - Box() + EditPaste() { - addFile( ":icons/16x16/actions/glabels-box.png" ); - addFile( ":icons/24x24/actions/glabels-box.png" ); + addFile( ":icons/24x24/actions/edit-paste.png" ); } }; - class Ellipse : public QIcon + class FileNew : public QIcon { public: - Ellipse() + FileNew() { - addFile( ":icons/16x16/actions/glabels-ellipse.png" ); - addFile( ":icons/24x24/actions/glabels-ellipse.png" ); + addFile( ":icons/24x24/actions/file-new.png" ); } }; - class Image : public QIcon + class FileOpen : public QIcon { public: - Image() + FileOpen() { - addFile( ":icons/16x16/actions/glabels-image.png" ); - addFile( ":icons/24x24/actions/glabels-image.png" ); + addFile( ":icons/24x24/actions/file-open.png" ); } }; - class Line : public QIcon + class FilePrint : public QIcon { public: - Line() + FilePrint() { - addFile( ":icons/16x16/actions/glabels-line.png" ); - addFile( ":icons/24x24/actions/glabels-line.png" ); + addFile( ":icons/24x24/actions/file-print.png" ); + addFile( ":icons/32x32/actions/file-print.png" ); } }; - class Text : public QIcon + class FileSave : public QIcon { public: - Text() + FileSave() { - addFile( ":icons/16x16/actions/glabels-text.png" ); - addFile( ":icons/24x24/actions/glabels-text.png" ); + addFile( ":icons/24x24/actions/file-save.png" ); } }; - class Merge : public QIcon + class FileSaveAs : public QIcon { public: - Merge() + FileSaveAs() { - addFile( ":icons/16x16/actions/glabels-merge.png" ); - addFile( ":icons/24x24/actions/glabels-merge.png" ); + addFile( ":icons/24x24/actions/file-save-as.png" ); } }; - class ObjectProperties : public QIcon + class ZoomBestFit : public QIcon { public: - ObjectProperties() + ZoomBestFit() { - addFile( ":icons/16x16/actions/glabels-object-properties.png" ); - addFile( ":icons/24x24/actions/glabels-object-properties.png" ); + addFile( ":icons/24x24/actions/zoom-best-fit.png" ); } }; - class AlignLeft : public QIcon + class ZoomIn : public QIcon { public: - AlignLeft() + ZoomIn() { - addFile( ":icons/16x16/actions/glabels-align-left.png" ); + addFile( ":icons/24x24/actions/zoom-in.png" ); } }; - class AlignHCenter : public QIcon + class ZoomOriginal : public QIcon { public: - AlignHCenter() + ZoomOriginal() { - addFile( ":icons/16x16/actions/glabels-align-hcenter.png" ); + addFile( ":icons/24x24/actions/zoom-original.png" ); } }; - class AlignRight : public QIcon + class ZoomOut : public QIcon { public: - AlignRight() + ZoomOut() { - addFile( ":icons/16x16/actions/glabels-align-right.png" ); + addFile( ":icons/24x24/actions/zoom-out.png" ); } }; - - class AlignBottom : public QIcon - { - public: - AlignBottom() - { - addFile( ":icons/16x16/actions/glabels-align-bottom.png" ); - } - }; - - - class AlignVCenter : public QIcon - { - public: - AlignVCenter() - { - addFile( ":icons/16x16/actions/glabels-align-vcenter.png" ); - } - }; - - - class AlignTop : public QIcon - { - public: - AlignTop() - { - addFile( ":icons/16x16/actions/glabels-align-top.png" ); - } - }; - - - class CenterHoriz : public QIcon - { - public: - CenterHoriz() - { - addFile( ":icons/16x16/actions/glabels-center-horiz.png" ); - } - }; - - - class CenterVert : public QIcon - { - public: - CenterVert() - { - addFile( ":icons/16x16/actions/glabels-center-vert.png" ); - } - }; - - - class FlipHoriz : public QIcon - { - public: - FlipHoriz() - { - addFile( ":icons/16x16/actions/glabels-flip-horiz.png" ); - } - }; - - - class FlipVert : public QIcon - { - public: - FlipVert() - { - addFile( ":icons/16x16/actions/glabels-flip-vert.png" ); - } - }; - - - class RotateLeft : public QIcon - { - public: - RotateLeft() - { - addFile( ":icons/16x16/actions/glabels-rotate-left.png" ); - } - }; - - - class RotateRight : public QIcon - { - public: - RotateRight() - { - addFile( ":icons/16x16/actions/glabels-rotate-right.png" ); - } - }; - - - class OrderBottom : public QIcon - { - public: - OrderBottom() - { - addFile( ":icons/16x16/actions/glabels-order-bottom.png" ); - } - }; - - - class OrderTop : public QIcon - { - public: - OrderTop() - { - addFile( ":icons/16x16/actions/glabels-order-top.png" ); - } - }; - - - class AlignTextBottom : public QIcon - { - public: - AlignTextBottom() - { - addFile( ":icons/24x24/actions/glabels-align-text-bottom.png" ); - } - }; - - - class AlignTextMiddle : public QIcon - { - public: - AlignTextMiddle() - { - addFile( ":icons/24x24/actions/glabels-align-text-middle.png" ); - } - }; - - - class AlignTextTop : public QIcon - { - public: - AlignTextTop() - { - addFile( ":icons/24x24/actions/glabels-align-text-top.png" ); - } - }; - - - class BucketFill : public QIcon - { - public: - BucketFill() - { - addFile( ":icons/16x16/actions/glabels-bucket-fill.png" ); - addFile( ":icons/24x24/actions/glabels-bucket-fill.png" ); - } - }; - - - class Pencil : public QIcon - { - public: - Pencil() - { - addFile( ":icons/16x16/actions/glabels-pencil.png" ); - addFile( ":icons/24x24/actions/glabels-pencil.png" ); - } - }; - - - class Glabels : public QIcon - { - public: - Glabels() - { - addFile( ":icons/16x16/apps/glabels.png" ); - addFile( ":icons/24x24/apps/glabels.png" ); - addFile( ":icons/32x32/apps/glabels.png" ); - addFile( ":icons/48x48/apps/glabels.png" ); - addFile( ":icons/scalable/apps/glabels.svg" ); - } - }; - - - /// - /// Fallback Icons. These are fallbacks for icons that would normally come from the current theme, - /// if supported. These icons are copied from the mate-icon-theme (GPL-v3 or CC-BY-SA-v3). - /// - namespace Fallback - { - - class EditCopy : public QIcon - { - public: - EditCopy() - { - addFile( ":icons/24x24/actions/edit-copy.png" ); - } - }; - - - class EditCut : public QIcon - { - public: - EditCut() - { - addFile( ":icons/24x24/actions/edit-cut.png" ); - } - }; - - - class EditPaste : public QIcon - { - public: - EditPaste() - { - addFile( ":icons/24x24/actions/edit-paste.png" ); - } - }; - - - class FileNew : public QIcon - { - public: - FileNew() - { - addFile( ":icons/24x24/actions/file-new.png" ); - } - }; - - - class FileOpen : public QIcon - { - public: - FileOpen() - { - addFile( ":icons/24x24/actions/file-open.png" ); - } - }; - - - class FilePrint : public QIcon - { - public: - FilePrint() - { - addFile( ":icons/24x24/actions/file-print.png" ); - addFile( ":icons/32x32/actions/file-print.png" ); - } - }; - - - class FileSave : public QIcon - { - public: - FileSave() - { - addFile( ":icons/24x24/actions/file-save.png" ); - } - }; - - - class FileSaveAs : public QIcon - { - public: - FileSaveAs() - { - addFile( ":icons/24x24/actions/file-save-as.png" ); - } - }; - - - class ZoomBestFit : public QIcon - { - public: - ZoomBestFit() - { - addFile( ":icons/24x24/actions/zoom-best-fit.png" ); - } - }; - - - class ZoomIn : public QIcon - { - public: - ZoomIn() - { - addFile( ":icons/24x24/actions/zoom-in.png" ); - } - }; - - - class ZoomOriginal : public QIcon - { - public: - ZoomOriginal() - { - addFile( ":icons/24x24/actions/zoom-original.png" ); - } - }; - - - class ZoomOut : public QIcon - { - public: - ZoomOut() - { - addFile( ":icons/24x24/actions/zoom-out.png" ); - } - }; - - } - } + } -#endif // glabels_Icons_h + +#endif // Icons_h diff --git a/glabels/LabelModel.cpp b/glabels/LabelModel.cpp index dba8611..7822847 100644 --- a/glabels/LabelModel.cpp +++ b/glabels/LabelModel.cpp @@ -29,1071 +29,1065 @@ #include "LabelRegion.h" -namespace glabels +/// +/// Default constructor. +/// +LabelModel::LabelModel() : mUntitledInstance(0), mModified(true), mTmplate(0), mRotate(false) { - - /// - /// Default constructor. - /// - LabelModel::LabelModel() : mUntitledInstance(0), mModified(true), mTmplate(0), mRotate(false) - { - } +} - /// - /// Short name. - /// - QString LabelModel::shortName() - { - static int untitledCount = 0; +/// +/// Short name. +/// +QString LabelModel::shortName() +{ + static int untitledCount = 0; - if ( mFileName.isEmpty() ) + if ( mFileName.isEmpty() ) + { + if ( mUntitledInstance == 0 ) { - if ( mUntitledInstance == 0 ) - { - mUntitledInstance = ++untitledCount; - } - QString numString; - numString.setNum(mUntitledInstance);; - - return tr("Untitled") + numString; + mUntitledInstance = ++untitledCount; } - else + QString numString; + numString.setNum(mUntitledInstance);; + + return tr("Untitled") + numString; + } + else + { + QFileInfo fileInfo( mFileName ); + return fileInfo.baseName(); + } +} + + +/// +/// Clear modified status +/// +void LabelModel::clearModified() +{ + mModified = false; + emit modifiedChanged(); +} + + +/// +/// Add object. +/// +void LabelModel::addObject( LabelModelObject* object ) +{ + object->setParent( this ); + mObjectList << object; + + connect( object, SIGNAL(changed()), this, SLOT(onObjectChanged()) ); + connect( object, SIGNAL(moved()), this, SLOT(onObjectMoved()) ); + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Delete Object +/// +void LabelModel::deleteObject( LabelModelObject* object ) +{ + object->unselect(); + mObjectList.removeOne( object ); + + disconnect( object, 0, this, 0 ); + + mModified = true; + + emit changed(); + emit modifiedChanged(); + + delete object; +} + + +/// +/// Object at x,y +/// +LabelModelObject* LabelModel::objectAt( double scale, + const glabels::Distance& x, + const glabels::Distance& y ) const +{ + /* Search object list in reverse order. I.e. from top to bottom. */ + QList::const_iterator it = mObjectList.end(); + while ( it != mObjectList.begin() ) + { + it--; + LabelModelObject* object = *it; + if ( object->isLocatedAt( scale, x, y ) ) { - QFileInfo fileInfo( mFileName ); - return fileInfo.baseName(); + return object; } } + return 0; +} - /// - /// Clear modified status - /// - void LabelModel::clearModified() + +/// +/// Handle at x,y +/// +Handle* LabelModel::handleAt( double scale, + const glabels::Distance& x, + const glabels::Distance& y ) const +{ + foreach( LabelModelObject* object, mObjectList ) { - mModified = false; - emit modifiedChanged(); - } - - - /// - /// Add object. - /// - void LabelModel::addObject( LabelModelObject* object ) - { - object->setParent( this ); - mObjectList << object; - - connect( object, SIGNAL(changed()), this, SLOT(onObjectChanged()) ); - connect( object, SIGNAL(moved()), this, SLOT(onObjectMoved()) ); - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Delete Object - /// - void LabelModel::deleteObject( LabelModelObject* object ) - { - object->unselect(); - mObjectList.removeOne( object ); - - disconnect( object, 0, this, 0 ); - - mModified = true; - - emit changed(); - emit modifiedChanged(); - - delete object; - } - - - /// - /// Object at x,y - /// - LabelModelObject* LabelModel::objectAt( double scale, - const libglabels::Distance& x, - const libglabels::Distance& y ) const - { - /* Search object list in reverse order. I.e. from top to bottom. */ - QList::const_iterator it = mObjectList.end(); - while ( it != mObjectList.begin() ) + Handle* handle = object->handleAt( scale, x, y ); + if ( handle ) { - it--; - LabelModelObject* object = *it; - if ( object->isLocatedAt( scale, x, y ) ) - { - return object; - } + return handle; } - - return 0; } - - /// - /// Handle at x,y - /// - Handle* LabelModel::handleAt( double scale, - const libglabels::Distance& x, - const libglabels::Distance& y ) const - { - foreach( LabelModelObject* object, mObjectList ) - { - Handle* handle = object->handleAt( scale, x, y ); - if ( handle ) - { - return handle; - } - } - - return 0; - } + return 0; +} - /// - /// Object Changed Slot - /// - void LabelModel::onObjectChanged() - { - mModified = true; +/// +/// Object Changed Slot +/// +void LabelModel::onObjectChanged() +{ + mModified = true; - emit changed(); - emit modifiedChanged(); - } + emit changed(); + emit modifiedChanged(); +} - /// - /// Object Moved Slot - /// - void LabelModel::onObjectMoved() - { - mModified = true; +/// +/// Object Moved Slot +/// +void LabelModel::onObjectMoved() +{ + mModified = true; - emit changed(); - emit modifiedChanged(); - } + emit changed(); + emit modifiedChanged(); +} - /// - /// Select Object - /// - void LabelModel::selectObject( LabelModelObject* object ) +/// +/// Select Object +/// +void LabelModel::selectObject( LabelModelObject* object ) +{ + object->select(); + + emit selectionChanged(); +} + + +/// +/// Unselect Object +/// +void LabelModel::unselectObject( LabelModelObject* object ) +{ + object->unselect(); + + emit selectionChanged(); +} + + +/// +/// Select All Objects +/// +void LabelModel::selectAll() +{ + foreach ( LabelModelObject* object, mObjectList ) { object->select(); - - emit selectionChanged(); } + emit selectionChanged(); +} - /// - /// Unselect Object - /// - void LabelModel::unselectObject( LabelModelObject* object ) + +/// +/// Unselect All Objects +/// +void LabelModel::unselectAll() +{ + foreach ( LabelModelObject* object, mObjectList ) { object->unselect(); - - emit selectionChanged(); } + emit selectionChanged(); +} - /// - /// Select All Objects - /// - void LabelModel::selectAll() + +/// +/// Select Region +/// +void LabelModel::selectRegion( const LabelRegion ®ion ) +{ + using std::min; + using std::max; + + glabels::Distance rX1 = min( region.x1(), region.x2() ); + glabels::Distance rY1 = min( region.y1(), region.y2() ); + glabels::Distance rX2 = max( region.x1(), region.x2() ); + glabels::Distance rY2 = max( region.y1(), region.y2() ); + + foreach ( LabelModelObject* object, mObjectList ) { - foreach ( LabelModelObject* object, mObjectList ) + LabelRegion objectExtent = object->getExtent(); + + if ( (objectExtent.x1() >= rX1) && + (objectExtent.x2() <= rX2) && + (objectExtent.y1() >= rY1) && + (objectExtent.y2() <= rY2) ) { object->select(); } - - emit selectionChanged(); } + emit selectionChanged(); +} - /// - /// Unselect All Objects - /// - void LabelModel::unselectAll() + +/// +/// Is Selection Empty? +/// +bool LabelModel::isSelectionEmpty() +{ + foreach ( LabelModelObject* object, mObjectList ) { - foreach ( LabelModelObject* object, mObjectList ) + if ( object->isSelected() ) { - object->unselect(); + return false; } - - emit selectionChanged(); } + return true; +} - /// - /// Select Region - /// - void LabelModel::selectRegion( const LabelRegion ®ion ) + +/// +/// Is Selection Atomic? +/// +bool LabelModel::isSelectionAtomic() +{ + int nSelected = 0; + + foreach ( LabelModelObject* object, mObjectList ) { - using std::min; - using std::max; - - libglabels::Distance rX1 = min( region.x1(), region.x2() ); - libglabels::Distance rY1 = min( region.y1(), region.y2() ); - libglabels::Distance rX2 = max( region.x1(), region.x2() ); - libglabels::Distance rY2 = max( region.y1(), region.y2() ); - - foreach ( LabelModelObject* object, mObjectList ) + if ( object->isSelected() ) { - LabelRegion objectExtent = object->getExtent(); - - if ( (objectExtent.x1() >= rX1) && - (objectExtent.x2() <= rX2) && - (objectExtent.y1() >= rY1) && - (objectExtent.y2() <= rY2) ) - { - object->select(); - } - } - - emit selectionChanged(); - } - - - /// - /// Is Selection Empty? - /// - bool LabelModel::isSelectionEmpty() - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) + nSelected++; + if ( nSelected > 1 ) { return false; } } - - return true; - } - - - /// - /// Is Selection Atomic? - /// - bool LabelModel::isSelectionAtomic() - { - int nSelected = 0; - - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - nSelected++; - if ( nSelected > 1 ) - { - return false; - } - } - } - - return (nSelected == 1); - } - - - /// - /// Get List of Selected Objects - /// - QList LabelModel::getSelection() - { - QList selectedList; - - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - selectedList << object; - } - } - - return selectedList; - } - - - /// - /// Get First Object in Selection List - /// - LabelModelObject* LabelModel::getFirstSelectedObject() - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - return object; - } - } - } - - - /// - /// Can Any Objects in Selection Accept Text Properties? - /// - bool LabelModel::canSelectionText() - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() && object->canText() ) - { - return true; - } - } - - return false; - } - - - /// - /// Can Any Objects in Selection Accept Fill Property? - /// - bool LabelModel::canSelectionFill() - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() && object->canFill() ) - { - return true; - } - } - - return false; - } - - - /// - /// Can Any Objects in Selection Accept Line Color Property? - /// - bool LabelModel::canSelectionLineColor() - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() && object->canLineColor() ) - { - return true; - } - } - - return false; - } - - - /// - /// Can Any Objects in Selection Accept Line Width Property? - /// - bool LabelModel::canSelectionLineWidth() - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() && object->canLineWidth() ) - { - return true; - } - } - - return false; - } - - - /// - /// Delete Selected Objects - /// - void LabelModel::deleteSelection() - { - QList selectedList = getSelection(); - - foreach ( LabelModelObject* object, selectedList ) - { - deleteObject( object ); - } - - mModified = true; - - emit changed(); - emit selectionChanged(); - emit modifiedChanged(); - } - - - /// - /// Raise Selected Objects To Top - /// - void LabelModel::raiseSelectionToTop() - { - QList selectedList = getSelection(); - - foreach ( LabelModelObject* object, selectedList ) - { - mObjectList.removeOne( object ); - } - - /// Move to end of list, representing top most object. - foreach ( LabelModelObject* object, selectedList ) - { - mObjectList.push_back( object ); - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Lower Selected Objects To Bottom - /// - void LabelModel::lowerSelectionToBottom() - { - QList selectedList = getSelection(); - - foreach ( LabelModelObject* object, selectedList ) - { - mObjectList.removeOne( object ); - } - - /// Move to front of list, representing bottom most object. - foreach ( LabelModelObject* object, selectedList ) - { - mObjectList.push_front( object ); - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Rotate Selected Objects - /// - void LabelModel::rotateSelection( double thetaDegs ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->rotate( thetaDegs ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Rotate Selected Objects Left 90 degrees - /// - void LabelModel::rotateSelectionLeft() - { - rotateSelection( -90.0 ); - } - - - /// - /// Rotate Selected Objects Right 90 degrees - /// - void LabelModel::rotateSelectionRight() - { - rotateSelection( 90.0 ); - } - - - /// - /// Flip Selected Objects Horizontally - /// - void LabelModel::flipSelectionHoriz() - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->flipHoriz(); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Flip Selected Objects Vertically - /// - void LabelModel::flipSelectionVert() - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->flipVert(); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Align Selected Objects To Their Left Edges - /// - void LabelModel::alignSelectionLeft() - { - if ( isSelectionEmpty() || isSelectionAtomic() ) - { - return; - } - - QList selectedList = getSelection(); - - /// Find left-most edge. - libglabels::Distance x1_min = 7200; /// Start with a very large value: 7200pts = 100in - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - if ( r.x1() < x1_min ) x1_min = r.x1(); - } - - /// Now adjust the object positions to line up the left edges at left-most edge. - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance dx = x1_min - r.x1(); - object->setPositionRelative( dx, 0 ); - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Align Selected Objects To Their Right Edges - /// - void LabelModel::alignSelectionRight() - { - if ( isSelectionEmpty() || isSelectionAtomic() ) - { - return; - } - - QList selectedList = getSelection(); - - /// Find right-most edge. - libglabels::Distance x1_max = -7200; /// Start with a very large negative value: 7200pts = 100in - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - if ( r.x1() > x1_max ) x1_max = r.x1(); - } - - /// Now adjust the object positions to line up the right edges at right-most edge. - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance dx = x1_max - r.x1(); - object->setPositionRelative( dx, 0 ); - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Align Selected Objects To Their Horizontal Centers - /// - void LabelModel::alignSelectionHCenter() - { - if ( isSelectionEmpty() || isSelectionAtomic() ) - { - return; - } - - QList selectedList = getSelection(); - - /// Find average center of objects. - libglabels::Distance xsum = 0; - int n = 0; - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - xsum += (r.x1() + r.x2()) / 2.0; - n++; - } - libglabels::Distance xavg = xsum / n; - - /// Find object closest to average center of objects. - libglabels::Distance xcenter = 7200; /// Start with very large value. - libglabels::Distance dxmin = fabs( xavg - xcenter ); - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance dx = fabs( xavg - (r.x1() + r.x2())/2.0 ); - if ( dx < dxmin ) - { - dxmin = dx; - xcenter = (r.x1() + r.x2()) / 2.0; - } - } - - /// Now adjust the object positions to line up with the center of this object. - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance dx = xcenter - (r.x1() + r.x2())/2.0; - object->setPositionRelative( dx, 0 ); - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Align Selected Objects To Their Top Edges - /// - void LabelModel::alignSelectionTop() - { - if ( isSelectionEmpty() || isSelectionAtomic() ) - { - return; - } - - QList selectedList = getSelection(); - - /// Find top-most edge. - libglabels::Distance y1_min = 7200; /// Start with a very large value: 7200pts = 100in - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - if ( r.y1() < y1_min ) y1_min = r.y1(); - } - - /// Now adjust the object positions to line up the top edges at top-most edge. - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance dy = y1_min - r.y1(); - object->setPositionRelative( 0, dy ); - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Align Selected Objects To Their Bottom Edges - /// - void LabelModel::alignSelectionBottom() - { - if ( isSelectionEmpty() || isSelectionAtomic() ) - { - return; - } - - QList selectedList = getSelection(); - - /// Find bottom-most edge. - libglabels::Distance y1_max = -7200; /// Start with a very large negative value: 7200pts = 100in - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - if ( r.y1() > y1_max ) y1_max = r.y1(); - } - - /// Now adjust the object positions to line up the bottom edges at bottom-most edge. - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance dy = y1_max - r.y1(); - object->setPositionRelative( 0, dy ); - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Align Selected Objects To Their Vertical Centers Edges - /// - void LabelModel::alignSelectionVCenter() - { - if ( isSelectionEmpty() || isSelectionAtomic() ) - { - return; - } - - QList selectedList = getSelection(); - - /// Find average center of objects. - libglabels::Distance ysum = 0; - int n = 0; - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - ysum += (r.y1() + r.y2()) / 2.0; - n++; - } - libglabels::Distance yavg = ysum / n; - - /// Find object closest to average center of objects. - libglabels::Distance ycenter = 7200; /// Start with very large value. - libglabels::Distance dymin = fabs( yavg - ycenter ); - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance dy = fabs( yavg - (r.y1() + r.y2())/2.0 ); - if ( dy < dymin ) - { - dymin = dy; - ycenter = (r.y1() + r.y2()) / 2.0; - } - } - - /// Now adjust the object positions to line up with the center of this object. - foreach ( LabelModelObject* object, selectedList ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance dy = ycenter - (r.y1() + r.y2())/2.0; - object->setPositionRelative( 0, dy ); - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Align Selected Objects To Center Of Label Horizontally - /// - void LabelModel::centerSelectionHoriz() - { - libglabels::Distance xLabelCenter = w() / 2.0; - - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance xObjectCenter = (r.x1() + r.x2()) / 2.0; - libglabels::Distance dx = xLabelCenter - xObjectCenter; - object->setPositionRelative( dx, 0 ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Align Selected Objects To Center Of Label Vertically - /// - void LabelModel::centerSelectionVert() - { - libglabels::Distance yLabelCenter = h() / 2.0; - - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - LabelRegion r = object->getExtent(); - libglabels::Distance yObjectCenter = (r.y1() + r.y2()) / 2.0; - libglabels::Distance dy = yLabelCenter - yObjectCenter; - object->setPositionRelative( 0, dy ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Move Selected Objects By dx,dy - /// - void LabelModel::moveSelection( const libglabels::Distance& dx, const libglabels::Distance& dy ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setPositionRelative( dx, dy ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Font Family Of Selected Objects - /// - void LabelModel::setSelectionFontFamily( const QString &fontFamily ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setFontFamily( fontFamily ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Font Size Of Selected Objects - /// - void LabelModel::setSelectionFontSize( double fontSize ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setFontSize( fontSize ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Font Weight Of Selected Objects - /// - void LabelModel::setSelectionFontWeight( QFont::Weight fontWeight ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setFontWeight( fontWeight ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Font Italic Flag Of Selected Objects - /// - void LabelModel::setSelectionFontItalicFlag( bool fontItalicFlag ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setFontItalicFlag( fontItalicFlag ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Text Horizontal Alignment Of Selected Objects - /// - void LabelModel::setSelectionTextHAlign( Qt::Alignment textHAlign ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setTextHAlign( textHAlign ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Text Vertical Alignment Of Selected Objects - /// - void LabelModel::setSelectionTextVAlign( Qt::Alignment textVAlign ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setTextVAlign( textVAlign ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Text Line Spacing Of Selected Objects - /// - void LabelModel::setSelectionTextLineSpacing( double textLineSpacing ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setTextLineSpacing( textLineSpacing ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Text Color Node Of Selected Objects - /// - void LabelModel::setSelectionTextColorNode( ColorNode textColorNode ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setTextColorNode( textColorNode ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Line Width Of Selected Objects - /// - void LabelModel::setSelectionLineWidth( const libglabels::Distance& lineWidth ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setLineWidth( lineWidth ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Line Color Node Of Selected Objects - /// - void LabelModel::setSelectionLineColorNode( ColorNode lineColorNode ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setLineColorNode( lineColorNode ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Set Fill Color Node Of Selected Objects - /// - void LabelModel::setSelectionFillColorNode( ColorNode fillColorNode ) - { - foreach ( LabelModelObject* object, mObjectList ) - { - if ( object->isSelected() ) - { - object->setFillColorNode( fillColorNode ); - } - } - - mModified = true; - - emit changed(); - emit modifiedChanged(); - } - - - /// - /// Draw label objects - /// - void LabelModel::draw( QPainter* painter, bool inEditor, MergeRecord* record ) const - { - foreach ( LabelModelObject* object, mObjectList ) - { - object->draw( painter, inEditor, record ); - } } + return (nSelected == 1); } + +/// +/// Get List of Selected Objects +/// +QList LabelModel::getSelection() +{ + QList selectedList; + + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + selectedList << object; + } + } + + return selectedList; +} + + +/// +/// Get First Object in Selection List +/// +LabelModelObject* LabelModel::getFirstSelectedObject() +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + return object; + } + } +} + + +/// +/// Can Any Objects in Selection Accept Text Properties? +/// +bool LabelModel::canSelectionText() +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() && object->canText() ) + { + return true; + } + } + + return false; +} + + +/// +/// Can Any Objects in Selection Accept Fill Property? +/// +bool LabelModel::canSelectionFill() +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() && object->canFill() ) + { + return true; + } + } + + return false; +} + + +/// +/// Can Any Objects in Selection Accept Line Color Property? +/// +bool LabelModel::canSelectionLineColor() +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() && object->canLineColor() ) + { + return true; + } + } + + return false; +} + + +/// +/// Can Any Objects in Selection Accept Line Width Property? +/// +bool LabelModel::canSelectionLineWidth() +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() && object->canLineWidth() ) + { + return true; + } + } + + return false; +} + + +/// +/// Delete Selected Objects +/// +void LabelModel::deleteSelection() +{ + QList selectedList = getSelection(); + + foreach ( LabelModelObject* object, selectedList ) + { + deleteObject( object ); + } + + mModified = true; + + emit changed(); + emit selectionChanged(); + emit modifiedChanged(); +} + + +/// +/// Raise Selected Objects To Top +/// +void LabelModel::raiseSelectionToTop() +{ + QList selectedList = getSelection(); + + foreach ( LabelModelObject* object, selectedList ) + { + mObjectList.removeOne( object ); + } + + /// Move to end of list, representing top most object. + foreach ( LabelModelObject* object, selectedList ) + { + mObjectList.push_back( object ); + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Lower Selected Objects To Bottom +/// +void LabelModel::lowerSelectionToBottom() +{ + QList selectedList = getSelection(); + + foreach ( LabelModelObject* object, selectedList ) + { + mObjectList.removeOne( object ); + } + + /// Move to front of list, representing bottom most object. + foreach ( LabelModelObject* object, selectedList ) + { + mObjectList.push_front( object ); + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Rotate Selected Objects +/// +void LabelModel::rotateSelection( double thetaDegs ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->rotate( thetaDegs ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Rotate Selected Objects Left 90 degrees +/// +void LabelModel::rotateSelectionLeft() +{ + rotateSelection( -90.0 ); +} + + +/// +/// Rotate Selected Objects Right 90 degrees +/// +void LabelModel::rotateSelectionRight() +{ + rotateSelection( 90.0 ); +} + + +/// +/// Flip Selected Objects Horizontally +/// +void LabelModel::flipSelectionHoriz() +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->flipHoriz(); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Flip Selected Objects Vertically +/// +void LabelModel::flipSelectionVert() +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->flipVert(); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Align Selected Objects To Their Left Edges +/// +void LabelModel::alignSelectionLeft() +{ + if ( isSelectionEmpty() || isSelectionAtomic() ) + { + return; + } + + QList selectedList = getSelection(); + + /// Find left-most edge. + glabels::Distance x1_min = 7200; /// Start with a very large value: 7200pts = 100in + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + if ( r.x1() < x1_min ) x1_min = r.x1(); + } + + /// Now adjust the object positions to line up the left edges at left-most edge. + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + glabels::Distance dx = x1_min - r.x1(); + object->setPositionRelative( dx, 0 ); + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Align Selected Objects To Their Right Edges +/// +void LabelModel::alignSelectionRight() +{ + if ( isSelectionEmpty() || isSelectionAtomic() ) + { + return; + } + + QList selectedList = getSelection(); + + /// Find right-most edge. + glabels::Distance x1_max = -7200; /// Start with a very large negative value: 7200pts = 100in + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + if ( r.x1() > x1_max ) x1_max = r.x1(); + } + + /// Now adjust the object positions to line up the right edges at right-most edge. + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + glabels::Distance dx = x1_max - r.x1(); + object->setPositionRelative( dx, 0 ); + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Align Selected Objects To Their Horizontal Centers +/// +void LabelModel::alignSelectionHCenter() +{ + if ( isSelectionEmpty() || isSelectionAtomic() ) + { + return; + } + + QList selectedList = getSelection(); + + /// Find average center of objects. + glabels::Distance xsum = 0; + int n = 0; + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + xsum += (r.x1() + r.x2()) / 2.0; + n++; + } + glabels::Distance xavg = xsum / n; + + /// Find object closest to average center of objects. + glabels::Distance xcenter = 7200; /// Start with very large value. + glabels::Distance dxmin = fabs( xavg - xcenter ); + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + glabels::Distance dx = fabs( xavg - (r.x1() + r.x2())/2.0 ); + if ( dx < dxmin ) + { + dxmin = dx; + xcenter = (r.x1() + r.x2()) / 2.0; + } + } + + /// Now adjust the object positions to line up with the center of this object. + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + glabels::Distance dx = xcenter - (r.x1() + r.x2())/2.0; + object->setPositionRelative( dx, 0 ); + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Align Selected Objects To Their Top Edges +/// +void LabelModel::alignSelectionTop() +{ + if ( isSelectionEmpty() || isSelectionAtomic() ) + { + return; + } + + QList selectedList = getSelection(); + + /// Find top-most edge. + glabels::Distance y1_min = 7200; /// Start with a very large value: 7200pts = 100in + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + if ( r.y1() < y1_min ) y1_min = r.y1(); + } + + /// Now adjust the object positions to line up the top edges at top-most edge. + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + glabels::Distance dy = y1_min - r.y1(); + object->setPositionRelative( 0, dy ); + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Align Selected Objects To Their Bottom Edges +/// +void LabelModel::alignSelectionBottom() +{ + if ( isSelectionEmpty() || isSelectionAtomic() ) + { + return; + } + + QList selectedList = getSelection(); + + /// Find bottom-most edge. + glabels::Distance y1_max = -7200; /// Start with a very large negative value: 7200pts = 100in + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + if ( r.y1() > y1_max ) y1_max = r.y1(); + } + + /// Now adjust the object positions to line up the bottom edges at bottom-most edge. + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + glabels::Distance dy = y1_max - r.y1(); + object->setPositionRelative( 0, dy ); + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Align Selected Objects To Their Vertical Centers Edges +/// +void LabelModel::alignSelectionVCenter() +{ + if ( isSelectionEmpty() || isSelectionAtomic() ) + { + return; + } + + QList selectedList = getSelection(); + + /// Find average center of objects. + glabels::Distance ysum = 0; + int n = 0; + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + ysum += (r.y1() + r.y2()) / 2.0; + n++; + } + glabels::Distance yavg = ysum / n; + + /// Find object closest to average center of objects. + glabels::Distance ycenter = 7200; /// Start with very large value. + glabels::Distance dymin = fabs( yavg - ycenter ); + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + glabels::Distance dy = fabs( yavg - (r.y1() + r.y2())/2.0 ); + if ( dy < dymin ) + { + dymin = dy; + ycenter = (r.y1() + r.y2()) / 2.0; + } + } + + /// Now adjust the object positions to line up with the center of this object. + foreach ( LabelModelObject* object, selectedList ) + { + LabelRegion r = object->getExtent(); + glabels::Distance dy = ycenter - (r.y1() + r.y2())/2.0; + object->setPositionRelative( 0, dy ); + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Align Selected Objects To Center Of Label Horizontally +/// +void LabelModel::centerSelectionHoriz() +{ + glabels::Distance xLabelCenter = w() / 2.0; + + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + LabelRegion r = object->getExtent(); + glabels::Distance xObjectCenter = (r.x1() + r.x2()) / 2.0; + glabels::Distance dx = xLabelCenter - xObjectCenter; + object->setPositionRelative( dx, 0 ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Align Selected Objects To Center Of Label Vertically +/// +void LabelModel::centerSelectionVert() +{ + glabels::Distance yLabelCenter = h() / 2.0; + + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + LabelRegion r = object->getExtent(); + glabels::Distance yObjectCenter = (r.y1() + r.y2()) / 2.0; + glabels::Distance dy = yLabelCenter - yObjectCenter; + object->setPositionRelative( 0, dy ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Move Selected Objects By dx,dy +/// +void LabelModel::moveSelection( const glabels::Distance& dx, const glabels::Distance& dy ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setPositionRelative( dx, dy ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Font Family Of Selected Objects +/// +void LabelModel::setSelectionFontFamily( const QString &fontFamily ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setFontFamily( fontFamily ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Font Size Of Selected Objects +/// +void LabelModel::setSelectionFontSize( double fontSize ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setFontSize( fontSize ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Font Weight Of Selected Objects +/// +void LabelModel::setSelectionFontWeight( QFont::Weight fontWeight ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setFontWeight( fontWeight ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Font Italic Flag Of Selected Objects +/// +void LabelModel::setSelectionFontItalicFlag( bool fontItalicFlag ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setFontItalicFlag( fontItalicFlag ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Text Horizontal Alignment Of Selected Objects +/// +void LabelModel::setSelectionTextHAlign( Qt::Alignment textHAlign ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setTextHAlign( textHAlign ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Text Vertical Alignment Of Selected Objects +/// +void LabelModel::setSelectionTextVAlign( Qt::Alignment textVAlign ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setTextVAlign( textVAlign ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Text Line Spacing Of Selected Objects +/// +void LabelModel::setSelectionTextLineSpacing( double textLineSpacing ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setTextLineSpacing( textLineSpacing ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Text Color Node Of Selected Objects +/// +void LabelModel::setSelectionTextColorNode( ColorNode textColorNode ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setTextColorNode( textColorNode ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Line Width Of Selected Objects +/// +void LabelModel::setSelectionLineWidth( const glabels::Distance& lineWidth ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setLineWidth( lineWidth ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Line Color Node Of Selected Objects +/// +void LabelModel::setSelectionLineColorNode( ColorNode lineColorNode ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setLineColorNode( lineColorNode ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Set Fill Color Node Of Selected Objects +/// +void LabelModel::setSelectionFillColorNode( ColorNode fillColorNode ) +{ + foreach ( LabelModelObject* object, mObjectList ) + { + if ( object->isSelected() ) + { + object->setFillColorNode( fillColorNode ); + } + } + + mModified = true; + + emit changed(); + emit modifiedChanged(); +} + + +/// +/// Draw label objects +/// +void LabelModel::draw( QPainter* painter, bool inEditor, MergeRecord* record ) const +{ + foreach ( LabelModelObject* object, mObjectList ) + { + object->draw( painter, inEditor, record ); + } +} diff --git a/glabels/LabelModel.h b/glabels/LabelModel.h index acb853d..3b2806a 100644 --- a/glabels/LabelModel.h +++ b/glabels/LabelModel.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_LabelModel_h -#define glabels_LabelModel_h +#ifndef LabelModel_h +#define LabelModel_h #include #include @@ -29,284 +29,280 @@ #include "libglabels/Template.h" -namespace glabels +// Forward References +class LabelModelObject; +class Handle; +class LabelRegion; +class ColorNode; + + +////////////////////////////////////////////// +////////////////////////////////////////////// +// LabelModel +////////////////////////////////////////////// +////////////////////////////////////////////// +class LabelModel : public QObject { - // Forward References - class LabelModelObject; - class Handle; - class LabelRegion; - class ColorNode; - - - ////////////////////////////////////////////// - ////////////////////////////////////////////// - // LabelModel - ////////////////////////////////////////////// - ////////////////////////////////////////////// - class LabelModel : public QObject - { - Q_OBJECT - - - ///////////////////////////////// - // Lifecycle - ///////////////////////////////// - public: - LabelModel(); - virtual ~LabelModel() {} - - - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void changed(); - void nameChanged(); - void sizeChanged(); - void selectionChanged(); - void modifiedChanged(); - - - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - inline bool isModified() const; - void clearModified(); - - QString shortName(); - inline const QString& fileName() const; - inline void setFileName( const QString &fileName ); - - inline int compressionLevel() const; - inline void setCompressionLevel( int compressionLevel ); - - inline const libglabels::Template* tmplate() const; - inline const libglabels::Frame* frame() const; - inline void setTmplate( const libglabels::Template* tmplate ); - - inline bool rotate() const; - inline void setRotate( bool rotate ); - - inline libglabels::Distance w() const; - inline libglabels::Distance h() const; - - inline const QList& objectList() const; - - - ///////////////////////////////// - // Manage objects - ///////////////////////////////// - public: - void addObject( LabelModelObject* object ); - void deleteObject( LabelModelObject* object ); - - LabelModelObject* objectAt( double scale, - const libglabels::Distance& x, - const libglabels::Distance& y ) const; - - Handle* handleAt( double scale, - const libglabels::Distance& x, - const libglabels::Distance& y ) const; - - - ///////////////////////////////// - // Manipulate selection - ///////////////////////////////// - public: - void selectObject( LabelModelObject* object ); - void unselectObject( LabelModelObject* object ); - void selectAll(); - void unselectAll(); - void selectRegion( const LabelRegion& region ); - bool isSelectionEmpty(); - bool isSelectionAtomic(); - - - ///////////////////////////////// - // Get selected objects - ///////////////////////////////// - public: - QList getSelection(); - LabelModelObject* getFirstSelectedObject(); - - - ///////////////////////////////// - // Query selection capabilities - ///////////////////////////////// - public: - bool canSelectionText(); - bool canSelectionFill(); - bool canSelectionLineColor(); - bool canSelectionLineWidth(); - - - ///////////////////////////////// - // Operations on selections - ///////////////////////////////// - public: - void deleteSelection(); - void raiseSelectionToTop(); - void lowerSelectionToBottom(); - void rotateSelection( double thetaDegs ); - void rotateSelectionLeft(); - void rotateSelectionRight(); - void flipSelectionHoriz(); - void flipSelectionVert(); - void alignSelectionLeft(); - void alignSelectionRight(); - void alignSelectionHCenter(); - void alignSelectionTop(); - void alignSelectionBottom(); - void alignSelectionVCenter(); - void centerSelectionHoriz(); - void centerSelectionVert(); - void moveSelection( const libglabels::Distance& dx, const libglabels::Distance& dy ); - void setSelectionFontFamily( const QString& fontFamily ); - void setSelectionFontSize( double fontSize ); - void setSelectionFontWeight( QFont::Weight fontWeight ); - void setSelectionFontItalicFlag( bool fontItalicFlag ); - void setSelectionTextHAlign( Qt::Alignment textHAlign ); - void setSelectionTextVAlign( Qt::Alignment textVAlign ); - void setSelectionTextLineSpacing( double textLineSpacing ); - void setSelectionTextColorNode( ColorNode textColorNode ); - void setSelectionLineWidth( const libglabels::Distance& lineWidth ); - void setSelectionLineColorNode( ColorNode lineColorNode ); - void setSelectionFillColorNode( ColorNode fillColorNode ); - - - ///////////////////////////////// - // Drawing operations - ///////////////////////////////// - public: - void draw( QPainter* painter, bool inEditor = true, MergeRecord* record = 0 ) const; - - - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onObjectChanged(); - void onObjectMoved(); - - - ///////////////////////////////// - // Private data - ///////////////////////////////// - private: - int mUntitledInstance; - bool mModified; - QString mFileName; - int mCompressionLevel; - const libglabels::Template* mTmplate; - const libglabels::Frame* mFrame; - bool mRotate; - - QList mObjectList; - - }; - + Q_OBJECT ///////////////////////////////// - // INLINE METHODS + // Lifecycle ///////////////////////////////// - - inline bool LabelModel::isModified() const - { - return mModified; - } +public: + LabelModel(); + virtual ~LabelModel() {} - inline const QString& LabelModel::fileName() const - { - return mFileName; - } + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void changed(); + void nameChanged(); + void sizeChanged(); + void selectionChanged(); + void modifiedChanged(); - inline void LabelModel::setFileName( const QString &fileName ) - { - if ( mFileName != fileName ) - { - mFileName = fileName; - emit nameChanged(); - } - } + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + inline bool isModified() const; + void clearModified(); + + QString shortName(); + inline const QString& fileName() const; + inline void setFileName( const QString &fileName ); + + inline int compressionLevel() const; + inline void setCompressionLevel( int compressionLevel ); + + inline const glabels::Template* tmplate() const; + inline const glabels::Frame* frame() const; + inline void setTmplate( const glabels::Template* tmplate ); + + inline bool rotate() const; + inline void setRotate( bool rotate ); + + inline glabels::Distance w() const; + inline glabels::Distance h() const; + + inline const QList& objectList() const; + + + ///////////////////////////////// + // Manage objects + ///////////////////////////////// +public: + void addObject( LabelModelObject* object ); + void deleteObject( LabelModelObject* object ); + + LabelModelObject* objectAt( double scale, + const glabels::Distance& x, + const glabels::Distance& y ) const; + + Handle* handleAt( double scale, + const glabels::Distance& x, + const glabels::Distance& y ) const; - inline int LabelModel::compressionLevel() const - { - return mCompressionLevel; - } + ///////////////////////////////// + // Manipulate selection + ///////////////////////////////// +public: + void selectObject( LabelModelObject* object ); + void unselectObject( LabelModelObject* object ); + void selectAll(); + void unselectAll(); + void selectRegion( const LabelRegion& region ); + bool isSelectionEmpty(); + bool isSelectionAtomic(); - inline void LabelModel::setCompressionLevel( int compressionLevel ) - { - mCompressionLevel = compressionLevel; - } + ///////////////////////////////// + // Get selected objects + ///////////////////////////////// +public: + QList getSelection(); + LabelModelObject* getFirstSelectedObject(); - inline const libglabels::Template* LabelModel::tmplate() const - { - return mTmplate; - } + ///////////////////////////////// + // Query selection capabilities + ///////////////////////////////// +public: + bool canSelectionText(); + bool canSelectionFill(); + bool canSelectionLineColor(); + bool canSelectionLineWidth(); - inline const libglabels::Frame* LabelModel::frame() const - { - return mFrame; - } + ///////////////////////////////// + // Operations on selections + ///////////////////////////////// +public: + void deleteSelection(); + void raiseSelectionToTop(); + void lowerSelectionToBottom(); + void rotateSelection( double thetaDegs ); + void rotateSelectionLeft(); + void rotateSelectionRight(); + void flipSelectionHoriz(); + void flipSelectionVert(); + void alignSelectionLeft(); + void alignSelectionRight(); + void alignSelectionHCenter(); + void alignSelectionTop(); + void alignSelectionBottom(); + void alignSelectionVCenter(); + void centerSelectionHoriz(); + void centerSelectionVert(); + void moveSelection( const glabels::Distance& dx, const glabels::Distance& dy ); + void setSelectionFontFamily( const QString& fontFamily ); + void setSelectionFontSize( double fontSize ); + void setSelectionFontWeight( QFont::Weight fontWeight ); + void setSelectionFontItalicFlag( bool fontItalicFlag ); + void setSelectionTextHAlign( Qt::Alignment textHAlign ); + void setSelectionTextVAlign( Qt::Alignment textVAlign ); + void setSelectionTextLineSpacing( double textLineSpacing ); + void setSelectionTextColorNode( ColorNode textColorNode ); + void setSelectionLineWidth( const glabels::Distance& lineWidth ); + void setSelectionLineColorNode( ColorNode lineColorNode ); + void setSelectionFillColorNode( ColorNode fillColorNode ); - inline void LabelModel::setTmplate( const libglabels::Template* tmplate ) - { - if (mTmplate != tmplate) - { - mTmplate = tmplate; - mFrame = tmplate->frames().first(); - mModified = true; - emit changed(); - emit sizeChanged(); - } - } + ///////////////////////////////// + // Drawing operations + ///////////////////////////////// +public: + void draw( QPainter* painter, bool inEditor = true, MergeRecord* record = 0 ) const; + + + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onObjectChanged(); + void onObjectMoved(); - inline bool LabelModel::rotate() const - { - return mRotate; - } + ///////////////////////////////// + // Private data + ///////////////////////////////// +private: + int mUntitledInstance; + bool mModified; + QString mFileName; + int mCompressionLevel; + const glabels::Template* mTmplate; + const glabels::Frame* mFrame; + bool mRotate; + + QList mObjectList; + +}; - inline void LabelModel::setRotate( bool rotate ) - { - if (mRotate != rotate) - { - mRotate = rotate; - mModified = true; - emit changed(); - emit sizeChanged(); - } - } - - - inline libglabels::Distance LabelModel::w() const - { - return mRotate ? mFrame->h() : mFrame->w(); - } - - - inline libglabels::Distance LabelModel::h() const - { - return mRotate ? mFrame->w() : mFrame->h(); - } - - - inline const QList& LabelModel::objectList() const - { - return mObjectList; - } +///////////////////////////////// +// INLINE METHODS +///////////////////////////////// +inline bool LabelModel::isModified() const +{ + return mModified; } -#endif // glabels_LabelModel_h + +inline const QString& LabelModel::fileName() const +{ + return mFileName; +} + + +inline void LabelModel::setFileName( const QString &fileName ) +{ + if ( mFileName != fileName ) + { + mFileName = fileName; + emit nameChanged(); + } +} + + +inline int LabelModel::compressionLevel() const +{ + return mCompressionLevel; +} + + +inline void LabelModel::setCompressionLevel( int compressionLevel ) +{ + mCompressionLevel = compressionLevel; +} + + +inline const glabels::Template* LabelModel::tmplate() const +{ + return mTmplate; +} + + +inline const glabels::Frame* LabelModel::frame() const +{ + return mFrame; +} + + +inline void LabelModel::setTmplate( const glabels::Template* tmplate ) +{ + if (mTmplate != tmplate) + { + mTmplate = tmplate; + mFrame = tmplate->frames().first(); + mModified = true; + emit changed(); + emit sizeChanged(); + } +} + + +inline bool LabelModel::rotate() const +{ + return mRotate; +} + + +inline void LabelModel::setRotate( bool rotate ) +{ + if (mRotate != rotate) + { + mRotate = rotate; + mModified = true; + emit changed(); + emit sizeChanged(); + } +} + + +inline glabels::Distance LabelModel::w() const +{ + return mRotate ? mFrame->h() : mFrame->w(); +} + + +inline glabels::Distance LabelModel::h() const +{ + return mRotate ? mFrame->w() : mFrame->h(); +} + + +inline const QList& LabelModel::objectList() const +{ + return mObjectList; +} + + +#endif // LabelModel_h diff --git a/glabels/LabelModelBoxObject.cpp b/glabels/LabelModelBoxObject.cpp index 99e1b89..818cc4f 100644 --- a/glabels/LabelModelBoxObject.cpp +++ b/glabels/LabelModelBoxObject.cpp @@ -30,120 +30,115 @@ namespace } -namespace glabels +/// +/// Constructor +/// +LabelModelBoxObject::LabelModelBoxObject( QObject* parent ) : LabelModelShapeObject(parent) { - - /// - /// Constructor - /// - LabelModelBoxObject::LabelModelBoxObject( QObject* parent ) : LabelModelShapeObject(parent) - { - } +} - /// - /// Destructor - /// - LabelModelBoxObject::~LabelModelBoxObject() - { - } +/// +/// Destructor +/// +LabelModelBoxObject::~LabelModelBoxObject() +{ +} - /// - /// Draw shadow of object - /// - void LabelModelBoxObject::drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const - { - /// TODO expand colors based on record +/// +/// Draw shadow of object +/// +void LabelModelBoxObject::drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const +{ + /// TODO expand colors based on record - QColor lineColor = mLineColorNode.color(); - QColor fillColor = mFillColorNode.color(); - QColor shadowColor = mShadowColorNode.color(); + QColor lineColor = mLineColorNode.color(); + QColor fillColor = mFillColorNode.color(); + QColor shadowColor = mShadowColorNode.color(); - shadowColor.setAlphaF( mShadowOpacity ); + shadowColor.setAlphaF( mShadowOpacity ); - if ( fillColor.alpha() ) + if ( fillColor.alpha() ) + { + painter->setPen( Qt::NoPen ); + painter->setBrush( shadowColor ); + + if ( lineColor.alpha() ) { - painter->setPen( Qt::NoPen ); - painter->setBrush( shadowColor ); - - if ( lineColor.alpha() ) - { - /* Has FILL and OUTLINE: adjust size to account for line width. */ - painter->drawRect( QRectF( -mLineWidth.pt()/2, - -mLineWidth.pt()/2, - (mW + mLineWidth).pt(), - (mH + mLineWidth).pt() ) ); - } - else - { - /* Has FILL, but no OUTLINE. */ - painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) ); - } + /* Has FILL and OUTLINE: adjust size to account for line width. */ + painter->drawRect( QRectF( -mLineWidth.pt()/2, + -mLineWidth.pt()/2, + (mW + mLineWidth).pt(), + (mH + mLineWidth).pt() ) ); } else { - if ( lineColor.alpha() ) - { - /* Has only OUTLINE. */ - painter->setPen( QPen( shadowColor, mLineWidth.pt() ) ); - painter->setBrush( Qt::NoBrush ); - - painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) ); - } + /* Has FILL, but no OUTLINE. */ + painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) ); } - } - - - /// - /// Draw object itself - /// - void LabelModelBoxObject::drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const + else { - /// TODO expand colors based on record + if ( lineColor.alpha() ) + { + /* Has only OUTLINE. */ + painter->setPen( QPen( shadowColor, mLineWidth.pt() ) ); + painter->setBrush( Qt::NoBrush ); + + painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) ); + } + } - QColor lineColor = mLineColorNode.color(); - QColor fillColor = mFillColorNode.color(); - - painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); - painter->setBrush( fillColor ); - - painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) ); - } - - - /// - /// Path to test for hover condition - /// - QPainterPath LabelModelBoxObject::hoverPath( double scale ) const - { - double s = 1 / scale; - - QPainterPath path; - - if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() ) - { - path.addRect( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() ); - } - else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) ) - { - path.addRect( 0, 0, mW.pt(), mH.pt() ); - } - else if ( mLineColorNode.color().alpha() ) - { - path.addRect( (-mLineWidth.pt()/2) - s*slopPixels, - (-mLineWidth.pt()/2) - s*slopPixels, - (mW + mLineWidth).pt() + s*2*slopPixels, - (mH + mLineWidth).pt() + s*2*slopPixels ); - path.closeSubpath(); - path.addRect( mLineWidth.pt()/2 + s*slopPixels, - mLineWidth.pt()/2 + s*slopPixels, - (mW - mLineWidth).pt() - s*2*slopPixels, - (mH - mLineWidth).pt() - s*2*slopPixels ); - } - - return path; - } - +} + + +/// +/// Draw object itself +/// +void LabelModelBoxObject::drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const +{ + /// TODO expand colors based on record + + QColor lineColor = mLineColorNode.color(); + QColor fillColor = mFillColorNode.color(); + + painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); + painter->setBrush( fillColor ); + + painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) ); +} + + +/// +/// Path to test for hover condition +/// +QPainterPath LabelModelBoxObject::hoverPath( double scale ) const +{ + double s = 1 / scale; + + QPainterPath path; + + if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() ) + { + path.addRect( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() ); + } + else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) ) + { + path.addRect( 0, 0, mW.pt(), mH.pt() ); + } + else if ( mLineColorNode.color().alpha() ) + { + path.addRect( (-mLineWidth.pt()/2) - s*slopPixels, + (-mLineWidth.pt()/2) - s*slopPixels, + (mW + mLineWidth).pt() + s*2*slopPixels, + (mH + mLineWidth).pt() + s*2*slopPixels ); + path.closeSubpath(); + path.addRect( mLineWidth.pt()/2 + s*slopPixels, + mLineWidth.pt()/2 + s*slopPixels, + (mW - mLineWidth).pt() - s*2*slopPixels, + (mH - mLineWidth).pt() - s*2*slopPixels ); + } + + return path; } diff --git a/glabels/LabelModelBoxObject.h b/glabels/LabelModelBoxObject.h index b744996..588f362 100644 --- a/glabels/LabelModelBoxObject.h +++ b/glabels/LabelModelBoxObject.h @@ -18,41 +18,37 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_LabelModelBoxObject_h -#define glabels_LabelModelBoxObject_h +#ifndef LabelModelBoxObject_h +#define LabelModelBoxObject_h #include "LabelModelShapeObject.h" -namespace glabels +/// +/// Label Model Box Object +/// +class LabelModelBoxObject : public LabelModelShapeObject { + Q_OBJECT - /// - /// Label Model Box Object - /// - class LabelModelBoxObject : public LabelModelShapeObject - { - Q_OBJECT - - /////////////////////////////////////////////////////////////// - // Lifecycle Methods - /////////////////////////////////////////////////////////////// - public: - LabelModelBoxObject( QObject* parent = 0 ); - virtual ~LabelModelBoxObject(); + /////////////////////////////////////////////////////////////// + // Lifecycle Methods + /////////////////////////////////////////////////////////////// +public: + LabelModelBoxObject( QObject* parent = 0 ); + virtual ~LabelModelBoxObject(); - /////////////////////////////////////////////////////////////// - // Drawing operations - /////////////////////////////////////////////////////////////// - protected: - virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const; - virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const; - virtual QPainterPath hoverPath( double scale ) const; + /////////////////////////////////////////////////////////////// + // Drawing operations + /////////////////////////////////////////////////////////////// +protected: + virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const; + virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const; + virtual QPainterPath hoverPath( double scale ) const; - }; +}; -} -#endif // glabels_LabelModelBoxObject_h +#endif // LabelModelBoxObject_h diff --git a/glabels/LabelModelObject.cpp b/glabels/LabelModelObject.cpp index c5c1533..6450ecb 100644 --- a/glabels/LabelModelObject.cpp +++ b/glabels/LabelModelObject.cpp @@ -32,983 +32,976 @@ #include "MergeRecord.h" -namespace glabels +/// +/// Next Object ID +/// +int LabelModelObject::msNextId = 0; + + +/// +/// Constructor +/// +LabelModelObject::LabelModelObject( QObject *parent = 0 ) : QObject(parent) { + mId = msNextId++; - /// - /// Next Object ID - /// - int LabelModelObject::msNextId = 0; + mX0 = 0; + mY0 = 0; + mW = 0; + mH = 0; + mMatrix = QMatrix(); + + mShadowState = false; + mShadowX = 1.3; + mShadowY = 1.3; + mShadowColorNode = ColorNode( QColor( 0, 0, 0 ) ); + mShadowOpacity = 0.5; + + mSelectedFlag = false; + + mOutline = 0; +} - /// - /// Constructor - /// - LabelModelObject::LabelModelObject( QObject *parent = 0 ) : QObject(parent) +/// +/// Destructor +/// +LabelModelObject::~LabelModelObject() +{ +} + + +/// +/// ID Property Getter +/// +int LabelModelObject::id() const +{ + return mId; +} + + +/// +/// Selected Property Getter +/// +bool LabelModelObject::isSelected() const +{ + return mSelectedFlag; +} + + +/// +/// Selected Property Setter +/// +void LabelModelObject::select( bool value ) +{ + mSelectedFlag = value; +} + + +/// +/// Clear Selected Property Setter +/// +void LabelModelObject::unselect() +{ + mSelectedFlag = false; +} + + +/// +/// X0 Property Getter +/// +glabels::Distance LabelModelObject::x0() const +{ + return mX0; +} + + +/// +/// X0 Property Setter +/// +void LabelModelObject::setX0( const glabels::Distance& value ) +{ + if ( mX0 != value ) { - mId = msNextId++; - - mX0 = 0; - mY0 = 0; - mW = 0; - mH = 0; - mMatrix = QMatrix(); - - mShadowState = false; - mShadowX = 1.3; - mShadowY = 1.3; - mShadowColorNode = ColorNode( QColor( 0, 0, 0 ) ); - mShadowOpacity = 0.5; - - mSelectedFlag = false; - - mOutline = 0; - } - - - /// - /// Destructor - /// - LabelModelObject::~LabelModelObject() - { - } - - - /// - /// ID Property Getter - /// - int LabelModelObject::id() const - { - return mId; - } - - - /// - /// Selected Property Getter - /// - bool LabelModelObject::isSelected() const - { - return mSelectedFlag; - } - - - /// - /// Selected Property Setter - /// - void LabelModelObject::select( bool value ) - { - mSelectedFlag = value; - } - - - /// - /// Clear Selected Property Setter - /// - void LabelModelObject::unselect() - { - mSelectedFlag = false; - } - - - /// - /// X0 Property Getter - /// - libglabels::Distance LabelModelObject::x0() const - { - return mX0; - } - - - /// - /// X0 Property Setter - /// - void LabelModelObject::setX0( const libglabels::Distance& value ) - { - if ( mX0 != value ) - { - mX0 = value; - emit moved(); - } + mX0 = value; + emit moved(); } +} - /// - /// Y0 Property Getter - /// - libglabels::Distance LabelModelObject::y0() const - { - return mY0; - } +/// +/// Y0 Property Getter +/// +glabels::Distance LabelModelObject::y0() const +{ + return mY0; +} - /// - /// Y0 Property Setter - /// - void LabelModelObject::setY0( const libglabels::Distance& value ) +/// +/// Y0 Property Setter +/// +void LabelModelObject::setY0( const glabels::Distance& value ) +{ + if ( mY0 != value ) { - if ( mY0 != value ) - { - mY0 = value; - emit moved(); - } + mY0 = value; + emit moved(); } +} - /// - /// W (Width) Property Getter - /// - libglabels::Distance LabelModelObject::w() const - { - return mW; - } +/// +/// W (Width) Property Getter +/// +glabels::Distance LabelModelObject::w() const +{ + return mW; +} - /// - /// W (Width) Property Setter - /// - void LabelModelObject::setW( const libglabels::Distance& value ) +/// +/// W (Width) Property Setter +/// +void LabelModelObject::setW( const glabels::Distance& value ) +{ + if ( mW != value ) { - if ( mW != value ) - { - mW = value; - emit changed(); - } + mW = value; + emit changed(); } +} - /// - /// H (Height) Property Getter - /// - libglabels::Distance LabelModelObject::h() const +/// +/// H (Height) Property Getter +/// +glabels::Distance LabelModelObject::h() const +{ + return mH; +} + + +/// +/// H (Height) Property Setter +/// +void LabelModelObject::setH( const glabels::Distance& value ) +{ + if ( mH != value ) { - return mH; + mH = value; + emit changed(); } +} - /// - /// H (Height) Property Setter - /// - void LabelModelObject::setH( const libglabels::Distance& value ) +/// +/// Matrix Property Getter +/// +QMatrix LabelModelObject::matrix() const +{ + return mMatrix; +} + + +/// +/// Matrix Property Setter +/// +void LabelModelObject::setMatrix( const QMatrix& value ) +{ + if ( mMatrix != value ) { - if ( mH != value ) - { - mH = value; - emit changed(); - } + mMatrix = value; + emit changed(); } +} - /// - /// Matrix Property Getter - /// - QMatrix LabelModelObject::matrix() const +/// +/// Shadow State Property Getter +/// +bool LabelModelObject::shadow() const +{ + return mShadowState; +} + + +/// +/// Shadow State Property Setter +/// +void LabelModelObject::setShadow( bool value ) +{ + if ( mShadowState != value ) { - return mMatrix; + mShadowState = value; + emit changed(); } +} - /// - /// Matrix Property Setter - /// - void LabelModelObject::setMatrix( const QMatrix& value ) +/// +/// Shadow X Property Getter +/// +glabels::Distance LabelModelObject::shadowX() const +{ + return mShadowX; +} + + +/// +/// Shadow X Property Setter +/// +void LabelModelObject::setShadowX( const glabels::Distance& value ) +{ + if ( mShadowX != value ) { - if ( mMatrix != value ) - { - mMatrix = value; - emit changed(); - } - } - - - /// - /// Shadow State Property Getter - /// - bool LabelModelObject::shadow() const - { - return mShadowState; - } - - - /// - /// Shadow State Property Setter - /// - void LabelModelObject::setShadow( bool value ) - { - if ( mShadowState != value ) - { - mShadowState = value; - emit changed(); - } - } - - - /// - /// Shadow X Property Getter - /// - libglabels::Distance LabelModelObject::shadowX() const - { - return mShadowX; - } - - - /// - /// Shadow X Property Setter - /// - void LabelModelObject::setShadowX( const libglabels::Distance& value ) - { - if ( mShadowX != value ) - { - mShadowX = value; - emit changed(); - } + mShadowX = value; + emit changed(); } +} - /// - /// Shadow Y Property Getter - /// - libglabels::Distance LabelModelObject::shadowY() const - { - return mShadowY; - } +/// +/// Shadow Y Property Getter +/// +glabels::Distance LabelModelObject::shadowY() const +{ + return mShadowY; +} - /// - /// Shadow Y Property Setter - /// - void LabelModelObject::setShadowY( const libglabels::Distance& value ) +/// +/// Shadow Y Property Setter +/// +void LabelModelObject::setShadowY( const glabels::Distance& value ) +{ + if ( mShadowY != value ) { - if ( mShadowY != value ) - { - mShadowY = value; - emit changed(); - } + mShadowY = value; + emit changed(); } +} - /// - /// Shadow Opacity Property Getter - /// - double LabelModelObject::shadowOpacity() const - { - return mShadowOpacity; - } +/// +/// Shadow Opacity Property Getter +/// +double LabelModelObject::shadowOpacity() const +{ + return mShadowOpacity; +} - /// - /// Shadow Opacity Property Setter - /// - void LabelModelObject::setShadowOpacity( double value ) +/// +/// Shadow Opacity Property Setter +/// +void LabelModelObject::setShadowOpacity( double value ) +{ + if ( mShadowOpacity != value ) { - if ( mShadowOpacity != value ) - { - mShadowOpacity = value; - emit changed(); - } + mShadowOpacity = value; + emit changed(); } +} - /// - /// Shadow Color Node Property Getter - /// - ColorNode LabelModelObject::shadowColorNode() const - { - return mShadowColorNode; - } +/// +/// Shadow Color Node Property Getter +/// +ColorNode LabelModelObject::shadowColorNode() const +{ + return mShadowColorNode; +} - /// - /// Shadow Color Node Property Setter - /// - void LabelModelObject::setShadowColorNode( const ColorNode& value ) +/// +/// Shadow Color Node Property Setter +/// +void LabelModelObject::setShadowColorNode( const ColorNode& value ) +{ + if ( mShadowColorNode != value ) { - if ( mShadowColorNode != value ) - { - mShadowColorNode = value; - emit changed(); - } + mShadowColorNode = value; + emit changed(); } +} - /// - /// Virtual Font Family Property Default Getter - /// (Overridden by concrete class) - /// - QString LabelModelObject::fontFamily() const - { - return ""; - } +/// +/// Virtual Font Family Property Default Getter +/// (Overridden by concrete class) +/// +QString LabelModelObject::fontFamily() const +{ + return ""; +} - /// - /// Virtual Font Family Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setFontFamily( const QString& value ) - { - } +/// +/// Virtual Font Family Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setFontFamily( const QString& value ) +{ +} - /// - /// Virtual Font Size Property Default Getter - /// (Overridden by concrete class) - /// - double LabelModelObject::fontSize() const - { - return 0; - } +/// +/// Virtual Font Size Property Default Getter +/// (Overridden by concrete class) +/// +double LabelModelObject::fontSize() const +{ + return 0; +} - /// - /// Virtual Font Size Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setFontSize( double value ) - { - } +/// +/// Virtual Font Size Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setFontSize( double value ) +{ +} - /// - /// Virtual Font Weight Property Default Getter - /// (Overridden by concrete class) - /// - QFont::Weight LabelModelObject::fontWeight() const - { - return QFont::Normal; - } +/// +/// Virtual Font Weight Property Default Getter +/// (Overridden by concrete class) +/// +QFont::Weight LabelModelObject::fontWeight() const +{ + return QFont::Normal; +} - /// - /// Virtual Font Weight Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setFontWeight( QFont::Weight value ) - { - } +/// +/// Virtual Font Weight Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setFontWeight( QFont::Weight value ) +{ +} - /// - /// Virtual Font Italic Flag Property Default Getter - /// (Overridden by concrete class) - /// - bool LabelModelObject::fontItalicFlag() const - { - return false; - } +/// +/// Virtual Font Italic Flag Property Default Getter +/// (Overridden by concrete class) +/// +bool LabelModelObject::fontItalicFlag() const +{ + return false; +} - /// - /// Virtual Font Italic Flag Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setFontItalicFlag( bool value ) - { - } +/// +/// Virtual Font Italic Flag Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setFontItalicFlag( bool value ) +{ +} - /// - /// Virtual Font Underline Flag Property Default Getter - /// (Overridden by concrete class) - /// - bool LabelModelObject::fontUnderlineFlag() const - { - return false; - } +/// +/// Virtual Font Underline Flag Property Default Getter +/// (Overridden by concrete class) +/// +bool LabelModelObject::fontUnderlineFlag() const +{ + return false; +} - /// - /// Virtual Font Underline Flag Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setFontUnderlineFlag( bool value ) - { - } +/// +/// Virtual Font Underline Flag Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setFontUnderlineFlag( bool value ) +{ +} - /// - /// Virtual Text Color Node Property Default Getter - /// (Overridden by concrete class) - /// - ColorNode LabelModelObject::textColorNode() const - { - return ColorNode( QColor::fromRgba(0x00000000) ); - } +/// +/// Virtual Text Color Node Property Default Getter +/// (Overridden by concrete class) +/// +ColorNode LabelModelObject::textColorNode() const +{ + return ColorNode( QColor::fromRgba(0x00000000) ); +} - /// - /// Virtual Text Color Node Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setTextColorNode( const ColorNode &value ) - { - } +/// +/// Virtual Text Color Node Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setTextColorNode( const ColorNode &value ) +{ +} - /// - /// Virtual Text Horizontal Alignment Property Default Getter - /// (Overridden by concrete class) - /// - Qt::Alignment LabelModelObject::textHAlign() const - { - return Qt::AlignLeft; - } +/// +/// Virtual Text Horizontal Alignment Property Default Getter +/// (Overridden by concrete class) +/// +Qt::Alignment LabelModelObject::textHAlign() const +{ + return Qt::AlignLeft; +} - /// - /// Virtual Text Horizontal Alignment Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setTextHAlign( Qt::Alignment value ) - { - } +/// +/// Virtual Text Horizontal Alignment Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setTextHAlign( Qt::Alignment value ) +{ +} - /// - /// Virtual Text Vertical Alignment Property Default Getter - /// (Overridden by concrete class) - /// - Qt::Alignment LabelModelObject::textVAlign() const - { - return Qt::AlignTop; - } +/// +/// Virtual Text Vertical Alignment Property Default Getter +/// (Overridden by concrete class) +/// +Qt::Alignment LabelModelObject::textVAlign() const +{ + return Qt::AlignTop; +} - /// - /// Virtual Text Vertical Alignment Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setTextVAlign( Qt::Alignment value ) - { - } +/// +/// Virtual Text Vertical Alignment Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setTextVAlign( Qt::Alignment value ) +{ +} - /// - /// Virtual Text Line Spacing Property Default Getter - /// (Overridden by concrete class) - /// - double LabelModelObject::textLineSpacing() const - { - return 0; - } +/// +/// Virtual Text Line Spacing Property Default Getter +/// (Overridden by concrete class) +/// +double LabelModelObject::textLineSpacing() const +{ + return 0; +} - /// - /// Virtual Text Line Spacing Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setTextLineSpacing( double value ) - { - } +/// +/// Virtual Text Line Spacing Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setTextLineSpacing( double value ) +{ +} - /// - /// Virtual Filename Node Property Default Getter - /// (Overridden by concrete class) - /// - TextNode LabelModelObject::filenameNode() const - { - return TextNode(); - } +/// +/// Virtual Filename Node Property Default Getter +/// (Overridden by concrete class) +/// +TextNode LabelModelObject::filenameNode() const +{ + return TextNode(); +} - /// - /// Virtual Filename Node Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setFilenameNode( const TextNode& value ) - { - } +/// +/// Virtual Filename Node Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setFilenameNode( const TextNode& value ) +{ +} - /// - /// Virtual Line Width Property Default Getter - /// (Overridden by concrete class) - /// - libglabels::Distance LabelModelObject::lineWidth() const - { - return 0; - } +/// +/// Virtual Line Width Property Default Getter +/// (Overridden by concrete class) +/// +glabels::Distance LabelModelObject::lineWidth() const +{ + return 0; +} - /// - /// Virtual Line Width Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setLineWidth( const libglabels::Distance& value ) - { - } +/// +/// Virtual Line Width Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setLineWidth( const glabels::Distance& value ) +{ +} - /// - /// Virtual Line Color Node Property Default Getter - /// (Overridden by concrete class) - /// - ColorNode LabelModelObject::lineColorNode() const - { - return ColorNode( QColor::fromRgba(0x00000000) ); - } +/// +/// Virtual Line Color Node Property Default Getter +/// (Overridden by concrete class) +/// +ColorNode LabelModelObject::lineColorNode() const +{ + return ColorNode( QColor::fromRgba(0x00000000) ); +} - /// - /// Virtual Line Color Node Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setLineColorNode( const ColorNode &value ) - { - } +/// +/// Virtual Line Color Node Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setLineColorNode( const ColorNode &value ) +{ +} - /// - /// Virtual Fill Color Node Property Default Getter - /// (Overridden by concrete class) - /// - ColorNode LabelModelObject::fillColorNode() const - { - return ColorNode( QColor::fromRgba(0x00000000) ); - } +/// +/// Virtual Fill Color Node Property Default Getter +/// (Overridden by concrete class) +/// +ColorNode LabelModelObject::fillColorNode() const +{ + return ColorNode( QColor::fromRgba(0x00000000) ); +} - /// - /// Virtual Fill Color Node Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setFillColorNode( const ColorNode &value ) - { - } +/// +/// Virtual Fill Color Node Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setFillColorNode( const ColorNode &value ) +{ +} - /// - /// Virtual Barcode Data Node Property Default Getter - /// (Overridden by concrete class) - /// - TextNode LabelModelObject::bcDataNode() const - { - return TextNode(); - } +/// +/// Virtual Barcode Data Node Property Default Getter +/// (Overridden by concrete class) +/// +TextNode LabelModelObject::bcDataNode() const +{ + return TextNode(); +} - /// - /// Virtual Barcode Data Node Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setBcDataNode( const TextNode &value ) - { - } +/// +/// Virtual Barcode Data Node Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setBcDataNode( const TextNode &value ) +{ +} - /// - /// Virtual Barcode Text Flag Property Default Getter - /// (Overridden by concrete class) - /// - bool LabelModelObject::bcTextFlag() const - { - return false; - } +/// +/// Virtual Barcode Text Flag Property Default Getter +/// (Overridden by concrete class) +/// +bool LabelModelObject::bcTextFlag() const +{ + return false; +} - /// - /// Virtual Barcode Text Flag Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setBcTextFlag( bool value ) - { - } +/// +/// Virtual Barcode Text Flag Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setBcTextFlag( bool value ) +{ +} - /// - /// Virtual Barcode Checksum Flag Property Default Getter - /// (Overridden by concrete class) - /// - bool LabelModelObject::bcChecksumFlag() const - { - return false; - } +/// +/// Virtual Barcode Checksum Flag Property Default Getter +/// (Overridden by concrete class) +/// +bool LabelModelObject::bcChecksumFlag() const +{ + return false; +} - /// - /// Virtual Barcode Checksum Flag Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setBcChecksumFlag( bool value ) - { - } +/// +/// Virtual Barcode Checksum Flag Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setBcChecksumFlag( bool value ) +{ +} - /// - /// Virtual Barcode Color Node Property Default Getter - /// (Overridden by concrete class) - /// - ColorNode LabelModelObject::bcColorNode() const - { - return ColorNode( QColor::fromRgba(0x00000000) ); - } +/// +/// Virtual Barcode Color Node Property Default Getter +/// (Overridden by concrete class) +/// +ColorNode LabelModelObject::bcColorNode() const +{ + return ColorNode( QColor::fromRgba(0x00000000) ); +} - /// - /// Virtual Barcode Color Node Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setBcColorNode( const ColorNode &value ) - { - } +/// +/// Virtual Barcode Color Node Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setBcColorNode( const ColorNode &value ) +{ +} - /// - /// Virtual Barcode Style Property Default Getter - /// (Overridden by concrete class) - /// - BarcodeStyle LabelModelObject::bcStyle() const - { - return BarcodeStyle(); - } +/// +/// Virtual Barcode Style Property Default Getter +/// (Overridden by concrete class) +/// +BarcodeStyle LabelModelObject::bcStyle() const +{ + return BarcodeStyle(); +} - /// - /// Virtual Barcode Style Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setBcStyle( const BarcodeStyle &value ) - { - } +/// +/// Virtual Barcode Style Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setBcStyle( const BarcodeStyle &value ) +{ +} - /// - /// Virtual Barcode Format Digits Property Default Getter - /// (Overridden by concrete class) - /// - int LabelModelObject::bcFormatDigits() const +/// +/// Virtual Barcode Format Digits Property Default Getter +/// (Overridden by concrete class) +/// +int LabelModelObject::bcFormatDigits() const +{ + return 0; +} + + +/// +/// Virtual Barcode Format Digits Property Default Setter +/// (Overridden by concrete class) +/// +void LabelModelObject::setBcFormatDigits( int value ) +{ +} + + +/// +/// Virtual Can Text Capability Read-Only Property Default Getter +/// (Overridden by concrete class) +/// +bool LabelModelObject::canText() const +{ + return false; +} + + +/// +/// Virtual Can Fill Capability Read-Only Property Default Getter +/// (Overridden by concrete class) +/// +bool LabelModelObject::canFill() const +{ + return false; +} + + +/// +/// Virtual Can Line Color Capability Read-Only Property Default Getter +/// (Overridden by concrete class) +/// +bool LabelModelObject::canLineColor() const +{ + return false; +} + + +/// +/// Virtual Can Line Width Capability Read-Only Property Default Getter +/// (Overridden by concrete class) +/// +bool LabelModelObject::canLineWidth() const +{ + return false; +} + + +/// +/// Set Absolute Position +/// +void LabelModelObject::setPosition( const glabels::Distance& x0, + const glabels::Distance& y0 ) +{ + if ( ( mX0 != x0 ) || ( mY0 != y0 ) ) { - return 0; + mX0 = x0; + mY0 = y0; + + emit moved(); } +} - /// - /// Virtual Barcode Format Digits Property Default Setter - /// (Overridden by concrete class) - /// - void LabelModelObject::setBcFormatDigits( int value ) +/// +/// Set Relative Position +/// +void LabelModelObject::setPositionRelative( const glabels::Distance& dx, + const glabels::Distance& dy ) +{ + if ( ( dx != 0 ) || ( dy != 0 ) ) { + mX0 += dx; + mY0 += dy; + + emit moved(); } +} - /// - /// Virtual Can Text Capability Read-Only Property Default Getter - /// (Overridden by concrete class) - /// - bool LabelModelObject::canText() const +/// +/// Set Size +/// +void LabelModelObject::setSize( const glabels::Distance& w, + const glabels::Distance& h ) +{ + mW = w; + mH = h; + + emit changed(); +} + + +/// +/// Set Size (But Maintain Current Aspect Ratio) +/// +void LabelModelObject::setSizeHonorAspect( const glabels::Distance& w, + const glabels::Distance& h ) +{ + double aspectRatio = mH / mW; + glabels::Distance wNew = w; + glabels::Distance hNew = h; + + if ( h > (w*aspectRatio) ) { - return false; + hNew = w*aspectRatio; } - - - /// - /// Virtual Can Fill Capability Read-Only Property Default Getter - /// (Overridden by concrete class) - /// - bool LabelModelObject::canFill() const + else { - return false; + wNew = h/aspectRatio; } - - /// - /// Virtual Can Line Color Capability Read-Only Property Default Getter - /// (Overridden by concrete class) - /// - bool LabelModelObject::canLineColor() const - { - return false; - } + setSize( wNew, hNew ); +} - /// - /// Virtual Can Line Width Capability Read-Only Property Default Getter - /// (Overridden by concrete class) - /// - bool LabelModelObject::canLineWidth() const - { - return false; - } +/// +/// Set Width (But Maintain Current Aspect Ratio) +/// +void LabelModelObject::setWHonorAspect( const glabels::Distance& w ) +{ + double aspectRatio = mH / mW; + glabels::Distance h = w * aspectRatio; - - /// - /// Set Absolute Position - /// - void LabelModelObject::setPosition( const libglabels::Distance& x0, - const libglabels::Distance& y0 ) - { - if ( ( mX0 != x0 ) || ( mY0 != y0 ) ) - { - mX0 = x0; - mY0 = y0; - - emit moved(); - } - } - - - /// - /// Set Relative Position - /// - void LabelModelObject::setPositionRelative( const libglabels::Distance& dx, - const libglabels::Distance& dy ) - { - if ( ( dx != 0 ) || ( dy != 0 ) ) - { - mX0 += dx; - mY0 += dy; - - emit moved(); - } - } - - - /// - /// Set Size - /// - void LabelModelObject::setSize( const libglabels::Distance& w, - const libglabels::Distance& h ) + if ( ( mW != w ) || ( mH != h ) ) { mW = w; mH = h; emit changed(); } +} - /// - /// Set Size (But Maintain Current Aspect Ratio) - /// - void LabelModelObject::setSizeHonorAspect( const libglabels::Distance& w, - const libglabels::Distance& h ) +/// +/// Set Height (But Maintain Current Aspect Ratio) +/// +void LabelModelObject::setHHonorAspect( const glabels::Distance& h ) +{ + double aspectRatio = mH / mW; + glabels::Distance w = h / aspectRatio; + + if ( ( mW != w ) || ( mH != h ) ) { - double aspectRatio = mH / mW; - libglabels::Distance wNew = w; - libglabels::Distance hNew = h; - - if ( h > (w*aspectRatio) ) - { - hNew = w*aspectRatio; - } - else - { - wNew = h/aspectRatio; - } + mW = w; + mH = h; - setSize( wNew, hNew ); + emit changed(); } +} - /// - /// Set Width (But Maintain Current Aspect Ratio) - /// - void LabelModelObject::setWHonorAspect( const libglabels::Distance& w ) - { - double aspectRatio = mH / mW; - libglabels::Distance h = w * aspectRatio; +/// +/// Get Extent of Bounding Box +/// +LabelRegion LabelModelObject::getExtent() +{ + using std::min; + using std::max; - if ( ( mW != w ) || ( mH != h ) ) - { - mW = w; - mH = h; + QPointF a1( ( - lineWidth()/2).pt(), ( - lineWidth()/2).pt() ); + QPointF a2( (mW + lineWidth()/2).pt(), ( - lineWidth()/2).pt() ); + QPointF a3( (mW + lineWidth()/2).pt(), (mH + lineWidth()/2).pt() ); + QPointF a4( ( - lineWidth()/2).pt(), (mH + lineWidth()/2).pt() ); - emit changed(); - } - } + a1 = mMatrix.map( a1 ); + a2 = mMatrix.map( a2 ); + a3 = mMatrix.map( a3 ); + a4 = mMatrix.map( a4 ); + + LabelRegion region; + region.setX1( glabels::Distance(min( a1.x(), min( a2.x(), min( a3.x(), a4.x() ) ) )) + mX0 ); + region.setY1( glabels::Distance(min( a1.y(), min( a2.y(), min( a3.y(), a4.y() ) ) )) + mY0 ); + region.setX2( glabels::Distance(max( a1.x(), max( a2.x(), max( a3.x(), a4.x() ) ) )) + mX0 ); + region.setY2( glabels::Distance(max( a1.y(), max( a2.y(), max( a3.y(), a4.y() ) ) )) + mY0 ); + + return region; +} - /// - /// Set Height (But Maintain Current Aspect Ratio) - /// - void LabelModelObject::setHHonorAspect( const libglabels::Distance& h ) - { - double aspectRatio = mH / mW; - libglabels::Distance w = h / aspectRatio; - - if ( ( mW != w ) || ( mH != h ) ) - { - mW = w; - mH = h; - - emit changed(); - } - } - - - /// - /// Get Extent of Bounding Box - /// - LabelRegion LabelModelObject::getExtent() - { - using std::min; - using std::max; - - QPointF a1( ( - lineWidth()/2).pt(), ( - lineWidth()/2).pt() ); - QPointF a2( (mW + lineWidth()/2).pt(), ( - lineWidth()/2).pt() ); - QPointF a3( (mW + lineWidth()/2).pt(), (mH + lineWidth()/2).pt() ); - QPointF a4( ( - lineWidth()/2).pt(), (mH + lineWidth()/2).pt() ); - - a1 = mMatrix.map( a1 ); - a2 = mMatrix.map( a2 ); - a3 = mMatrix.map( a3 ); - a4 = mMatrix.map( a4 ); - - LabelRegion region; - region.setX1( libglabels::Distance(min( a1.x(), min( a2.x(), min( a3.x(), a4.x() ) ) )) + mX0 ); - region.setY1( libglabels::Distance(min( a1.y(), min( a2.y(), min( a3.y(), a4.y() ) ) )) + mY0 ); - region.setX2( libglabels::Distance(max( a1.x(), max( a2.x(), max( a3.x(), a4.x() ) ) )) + mX0 ); - region.setY2( libglabels::Distance(max( a1.y(), max( a2.y(), max( a3.y(), a4.y() ) ) )) + mY0 ); - - return region; - } - - - /// - /// Rotate Object - /// - void LabelModelObject::rotate( double thetaDegs ) - { - if ( thetaDegs != 0 ) - { - QMatrix m; - m.rotate( thetaDegs ); - mMatrix *= m; - - emit changed(); - } - } - - - /// - /// Flip Object Horizontally - /// - void LabelModelObject::flipHoriz() +/// +/// Rotate Object +/// +void LabelModelObject::rotate( double thetaDegs ) +{ + if ( thetaDegs != 0 ) { QMatrix m; - m.scale( -1, 1 ); + m.rotate( thetaDegs ); mMatrix *= m; emit changed(); } +} - /// - /// Flip Object Vertically - /// - void LabelModelObject::flipVert() +/// +/// Flip Object Horizontally +/// +void LabelModelObject::flipHoriz() +{ + QMatrix m; + m.scale( -1, 1 ); + mMatrix *= m; + + emit changed(); +} + + +/// +/// Flip Object Vertically +/// +void LabelModelObject::flipVert() +{ + QMatrix m; + m.scale( 1, -1 ); + mMatrix *= m; + + emit changed(); +} + + +/// +/// Is this object located at x,y? +/// +bool LabelModelObject::isLocatedAt( double scale, + const glabels::Distance& x, + const glabels::Distance& y ) const +{ + QPointF p( x.pt(), y.pt() ); + + /* + * Change point to object relative coordinates + */ + p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0 + p = mMatrix.inverted().map( p ); + + if ( hoverPath( scale ).contains( p ) ) { - QMatrix m; - m.scale( 1, -1 ); - mMatrix *= m; - - emit changed(); + return true; } - - - /// - /// Is this object located at x,y? - /// - bool LabelModelObject::isLocatedAt( double scale, - const libglabels::Distance& x, - const libglabels::Distance& y ) const + else if ( isSelected() && mOutline ) { - QPointF p( x.pt(), y.pt() ); - - /* - * Change point to object relative coordinates - */ - p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0 - p = mMatrix.inverted().map( p ); - - if ( hoverPath( scale ).contains( p ) ) + if ( mOutline->hoverPath( scale ).contains( p ) ) { return true; } - else if ( isSelected() && mOutline ) - { - if ( mOutline->hoverPath( scale ).contains( p ) ) - { - return true; - } - } - - return false; } - - /// - /// Is one of this object's handles locate at x,y? If so, return it. - /// - Handle* LabelModelObject::handleAt( double scale, - const libglabels::Distance& x, - const libglabels::Distance& y ) const - { - if ( mSelectedFlag ) - { - QPointF p( x.pt(), y.pt() ); - p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0 - - foreach ( Handle* handle, mHandles ) - { - QPainterPath handlePath = mMatrix.map( handle->path( scale ) ); - if ( handlePath.contains( p ) ) - { - return handle; - } - } - } - - return 0; - } - - - /// - /// Draw object + shadow - /// - void LabelModelObject::draw( QPainter* painter, bool inEditor, MergeRecord* record ) const - { - painter->save(); - painter->translate( mX0.pt(), mY0.pt() ); - - if ( mShadowState ) - { - painter->save(); - painter->translate( mShadowX.pt(), mShadowY.pt() ); - painter->setMatrix( mMatrix, true ); - drawShadow( painter, inEditor, record ); - painter->restore(); - } - - painter->setMatrix( mMatrix, true ); - drawObject( painter, inEditor, record ); - - painter->restore(); - } - - - /// - /// Draw selection highlights - /// - void LabelModelObject::drawSelectionHighlight( QPainter* painter, double scale ) const - { - painter->save(); - - painter->translate( mX0.pt(), mY0.pt() ); - painter->setMatrix( mMatrix, true ); - - if ( mOutline ) - { - mOutline->draw( painter ); - } - - foreach( Handle* handle, mHandles ) - { - handle->draw( painter, scale ); - } - - painter->restore(); - } - - + return false; } + +/// +/// Is one of this object's handles locate at x,y? If so, return it. +/// +Handle* LabelModelObject::handleAt( double scale, + const glabels::Distance& x, + const glabels::Distance& y ) const +{ + if ( mSelectedFlag ) + { + QPointF p( x.pt(), y.pt() ); + p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0 + + foreach ( Handle* handle, mHandles ) + { + QPainterPath handlePath = mMatrix.map( handle->path( scale ) ); + if ( handlePath.contains( p ) ) + { + return handle; + } + } + } + + return 0; +} + + +/// +/// Draw object + shadow +/// +void LabelModelObject::draw( QPainter* painter, bool inEditor, MergeRecord* record ) const +{ + painter->save(); + painter->translate( mX0.pt(), mY0.pt() ); + + if ( mShadowState ) + { + painter->save(); + painter->translate( mShadowX.pt(), mShadowY.pt() ); + painter->setMatrix( mMatrix, true ); + drawShadow( painter, inEditor, record ); + painter->restore(); + } + + painter->setMatrix( mMatrix, true ); + drawObject( painter, inEditor, record ); + + painter->restore(); +} + + +/// +/// Draw selection highlights +/// +void LabelModelObject::drawSelectionHighlight( QPainter* painter, double scale ) const +{ + painter->save(); + + painter->translate( mX0.pt(), mY0.pt() ); + painter->setMatrix( mMatrix, true ); + + if ( mOutline ) + { + mOutline->draw( painter ); + } + + foreach( Handle* handle, mHandles ) + { + handle->draw( painter, scale ); + } + + painter->restore(); +} diff --git a/glabels/LabelModelObject.h b/glabels/LabelModelObject.h index bf6ff66..27573a1 100644 --- a/glabels/LabelModelObject.h +++ b/glabels/LabelModelObject.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_LabelModelObject_h -#define glabels_LabelModelObject_h +#ifndef LabelModelObject_h +#define LabelModelObject_h #include #include @@ -34,345 +34,342 @@ #include "Outline.h" -namespace glabels +// Forward References +class LabelRegion; +class MergeRecord; + + +/// +/// Label Model Object Base Class +/// +class LabelModelObject : public QObject { - // Forward References - class LabelRegion; - class MergeRecord; + Q_OBJECT + + /////////////////////////////////////////////////////////////// + // Lifecycle Methods + /////////////////////////////////////////////////////////////// +public: + LabelModelObject( QObject *parent ); + virtual ~LabelModelObject(); - /// - /// Label Model Object Base Class - /// - class LabelModelObject : public QObject - { - Q_OBJECT - - /////////////////////////////////////////////////////////////// - // Lifecycle Methods - /////////////////////////////////////////////////////////////// - public: - LabelModelObject( QObject *parent ); - virtual ~LabelModelObject(); + /////////////////////////////////////////////////////////////// + // Signals + /////////////////////////////////////////////////////////////// +signals: + void moved(); + void changed(); - /////////////////////////////////////////////////////////////// - // Signals - /////////////////////////////////////////////////////////////// - signals: - void moved(); - void changed(); + /////////////////////////////////////////////////////////////// + // Common Properties + /////////////////////////////////////////////////////////////// +public: + // + // ID Property. + // + int id() const; + + // + // Selected Property. + // + bool isSelected() const; + void select( bool value = true ); + void unselect(); - /////////////////////////////////////////////////////////////// - // Common Properties - /////////////////////////////////////////////////////////////// - public: - // - // ID Property. - // - int id() const; - - // - // Selected Property. - // - bool isSelected() const; - void select( bool value = true ); - void unselect(); - - - // - // x0 Property ( x coordinate of origin ) - // - libglabels::Distance x0() const; - void setX0( const libglabels::Distance& value ); + // + // x0 Property ( x coordinate of origin ) + // + glabels::Distance x0() const; + void setX0( const glabels::Distance& value ); - // - // y0 Property ( y coordinate of origin ) - // - libglabels::Distance y0() const; - void setY0( const libglabels::Distance& value ); + // + // y0 Property ( y coordinate of origin ) + // + glabels::Distance y0() const; + void setY0( const glabels::Distance& value ); - // - // w Property ( width of bounding box ) - // - libglabels::Distance w() const; - void setW( const libglabels::Distance& value ); + // + // w Property ( width of bounding box ) + // + glabels::Distance w() const; + void setW( const glabels::Distance& value ); - // - // h Property ( height of bounding box ) - // - libglabels::Distance h() const; - void setH( const libglabels::Distance& value ); + // + // h Property ( height of bounding box ) + // + glabels::Distance h() const; + void setH( const glabels::Distance& value ); - // - // Transformation Matrix Property - // - QMatrix matrix() const; - void setMatrix( const QMatrix& value ); + // + // Transformation Matrix Property + // + QMatrix matrix() const; + void setMatrix( const QMatrix& value ); - // - // Shadow State Property - // - bool shadow() const; - void setShadow( bool value ); + // + // Shadow State Property + // + bool shadow() const; + void setShadow( bool value ); - // - // Shadow x Offset Property - // - libglabels::Distance shadowX() const; - void setShadowX( const libglabels::Distance& value ); + // + // Shadow x Offset Property + // + glabels::Distance shadowX() const; + void setShadowX( const glabels::Distance& value ); - // - // Shadow y Offset Property - // - libglabels::Distance shadowY() const; - void setShadowY( const libglabels::Distance& value ); + // + // Shadow y Offset Property + // + glabels::Distance shadowY() const; + void setShadowY( const glabels::Distance& value ); - // - // Shadow opacity Property - // - double shadowOpacity() const; - void setShadowOpacity( double value ); + // + // Shadow opacity Property + // + double shadowOpacity() const; + void setShadowOpacity( double value ); - // - // Shadow Color Property - // - ColorNode shadowColorNode() const; - void setShadowColorNode( const ColorNode& value ); + // + // Shadow Color Property + // + ColorNode shadowColorNode() const; + void setShadowColorNode( const ColorNode& value ); - /////////////////////////////////////////////////////////////// - // Text Properties Virtual Interface - /////////////////////////////////////////////////////////////// - public: - // - // Virtual Text Property: fontFamily - // - virtual QString fontFamily() const; - virtual void setFontFamily( const QString &value ); + /////////////////////////////////////////////////////////////// + // Text Properties Virtual Interface + /////////////////////////////////////////////////////////////// +public: + // + // Virtual Text Property: fontFamily + // + virtual QString fontFamily() const; + virtual void setFontFamily( const QString &value ); - // - // Virtual Text Property: fontSize - // - virtual double fontSize() const; - virtual void setFontSize( double value ); + // + // Virtual Text Property: fontSize + // + virtual double fontSize() const; + virtual void setFontSize( double value ); - // - // Virtual Text Property: fontWeight - // - virtual QFont::Weight fontWeight() const; - virtual void setFontWeight( QFont::Weight value ); + // + // Virtual Text Property: fontWeight + // + virtual QFont::Weight fontWeight() const; + virtual void setFontWeight( QFont::Weight value ); - // - // Virtual Text Property: fontItalicFlag - // - virtual bool fontItalicFlag() const; - virtual void setFontItalicFlag( bool value ); + // + // Virtual Text Property: fontItalicFlag + // + virtual bool fontItalicFlag() const; + virtual void setFontItalicFlag( bool value ); - // - // Virtual Text Property: fontUnderlineFlag - // - virtual bool fontUnderlineFlag() const; - virtual void setFontUnderlineFlag( bool value ); + // + // Virtual Text Property: fontUnderlineFlag + // + virtual bool fontUnderlineFlag() const; + virtual void setFontUnderlineFlag( bool value ); - // - // Virtual Text Property: textColorNode - // - virtual ColorNode textColorNode() const; - virtual void setTextColorNode( const ColorNode &value ); + // + // Virtual Text Property: textColorNode + // + virtual ColorNode textColorNode() const; + virtual void setTextColorNode( const ColorNode &value ); - // - // Virtual Text Property: textHAlign - // - virtual Qt::Alignment textHAlign() const; - virtual void setTextHAlign( Qt::Alignment value ); + // + // Virtual Text Property: textHAlign + // + virtual Qt::Alignment textHAlign() const; + virtual void setTextHAlign( Qt::Alignment value ); - // - // Virtual Text Property: textVAlign - // - virtual Qt::Alignment textVAlign() const; - virtual void setTextVAlign( Qt::Alignment value ); + // + // Virtual Text Property: textVAlign + // + virtual Qt::Alignment textVAlign() const; + virtual void setTextVAlign( Qt::Alignment value ); - // - // Virtual Text Property: textLineSpacing - // - virtual double textLineSpacing() const; - virtual void setTextLineSpacing( double value ); + // + // Virtual Text Property: textLineSpacing + // + virtual double textLineSpacing() const; + virtual void setTextLineSpacing( double value ); - /////////////////////////////////////////////////////////////// - // Image Properties Virtual Interface - /////////////////////////////////////////////////////////////// - public: - // - // Virtual Image Property: filenameNode - // - virtual TextNode filenameNode() const; - virtual void setFilenameNode( const TextNode &value ); + /////////////////////////////////////////////////////////////// + // Image Properties Virtual Interface + /////////////////////////////////////////////////////////////// +public: + // + // Virtual Image Property: filenameNode + // + virtual TextNode filenameNode() const; + virtual void setFilenameNode( const TextNode &value ); - /////////////////////////////////////////////////////////////// - // Shape Properties Virtual Interface - /////////////////////////////////////////////////////////////// - public: - // - // Virtual Shape Property: lineWidth - // - virtual libglabels::Distance lineWidth() const; - virtual void setLineWidth( const libglabels::Distance& value ); + /////////////////////////////////////////////////////////////// + // Shape Properties Virtual Interface + /////////////////////////////////////////////////////////////// +public: + // + // Virtual Shape Property: lineWidth + // + virtual glabels::Distance lineWidth() const; + virtual void setLineWidth( const glabels::Distance& value ); - // - // Virtual Shape Property: lineColorNode - // - virtual ColorNode lineColorNode() const; - virtual void setLineColorNode( const ColorNode &value ); + // + // Virtual Shape Property: lineColorNode + // + virtual ColorNode lineColorNode() const; + virtual void setLineColorNode( const ColorNode &value ); - // - // Virtual Shape Property: fillColorNode - // - virtual ColorNode fillColorNode() const; - virtual void setFillColorNode( const ColorNode &value ); + // + // Virtual Shape Property: fillColorNode + // + virtual ColorNode fillColorNode() const; + virtual void setFillColorNode( const ColorNode &value ); - /////////////////////////////////////////////////////////////// - // Barcode Properties Virtual Interface - /////////////////////////////////////////////////////////////// - public: - // - // Virtual Barcode Property: bcDataNode - // - virtual TextNode bcDataNode() const; - virtual void setBcDataNode( const TextNode &value ); + /////////////////////////////////////////////////////////////// + // Barcode Properties Virtual Interface + /////////////////////////////////////////////////////////////// +public: + // + // Virtual Barcode Property: bcDataNode + // + virtual TextNode bcDataNode() const; + virtual void setBcDataNode( const TextNode &value ); - // - // Virtual Barcode Property: bcTextFlag - // - virtual bool bcTextFlag() const; - virtual void setBcTextFlag( bool value ); + // + // Virtual Barcode Property: bcTextFlag + // + virtual bool bcTextFlag() const; + virtual void setBcTextFlag( bool value ); - // - // Virtual Barcode Property: bcChecksumFlag - // - virtual bool bcChecksumFlag() const; - virtual void setBcChecksumFlag( bool value ); + // + // Virtual Barcode Property: bcChecksumFlag + // + virtual bool bcChecksumFlag() const; + virtual void setBcChecksumFlag( bool value ); - // - // Virtual Barcode Property: bcColorNode - // - virtual ColorNode bcColorNode() const; - virtual void setBcColorNode( const ColorNode &value ); + // + // Virtual Barcode Property: bcColorNode + // + virtual ColorNode bcColorNode() const; + virtual void setBcColorNode( const ColorNode &value ); - // - // Virtual Barcode Property: bcStyle - // - virtual BarcodeStyle bcStyle() const; - virtual void setBcStyle( const BarcodeStyle &value ); + // + // Virtual Barcode Property: bcStyle + // + virtual BarcodeStyle bcStyle() const; + virtual void setBcStyle( const BarcodeStyle &value ); - // - // Virtual Barcode Property: bcFormatDigits - // - virtual int bcFormatDigits() const; - virtual void setBcFormatDigits( int value ); + // + // Virtual Barcode Property: bcFormatDigits + // + virtual int bcFormatDigits() const; + virtual void setBcFormatDigits( int value ); - /////////////////////////////////////////////////////////////// - // Capabilities (Overridden by concrete classes.) - /////////////////////////////////////////////////////////////// - public: - virtual bool canText() const; - virtual bool canFill() const; - virtual bool canLineColor() const; - virtual bool canLineWidth() const; + /////////////////////////////////////////////////////////////// + // Capabilities (Overridden by concrete classes.) + /////////////////////////////////////////////////////////////// +public: + virtual bool canText() const; + virtual bool canFill() const; + virtual bool canLineColor() const; + virtual bool canLineWidth() const; - /////////////////////////////////////////////////////////////// - // Position and Size methods - /////////////////////////////////////////////////////////////// - public: - void setPosition( const libglabels::Distance& x0, const libglabels::Distance& y0 ); - void setPositionRelative( const libglabels::Distance& dx, const libglabels::Distance& dy ); - void setSize( const libglabels::Distance& w, const libglabels::Distance& h ); - void setSizeHonorAspect( const libglabels::Distance& w, const libglabels::Distance& h ); - void setWHonorAspect( const libglabels::Distance& w ); - void setHHonorAspect( const libglabels::Distance& h ); - LabelRegion getExtent(); - void rotate( double thetaDegs ); - void flipHoriz(); - void flipVert(); - bool isLocatedAt( double scale, const libglabels::Distance& x, const libglabels::Distance& y ) const; - Handle* handleAt( double scale, const libglabels::Distance& x, const libglabels::Distance& y ) const; + /////////////////////////////////////////////////////////////// + // Position and Size methods + /////////////////////////////////////////////////////////////// +public: + void setPosition( const glabels::Distance& x0, const glabels::Distance& y0 ); + void setPositionRelative( const glabels::Distance& dx, const glabels::Distance& dy ); + void setSize( const glabels::Distance& w, const glabels::Distance& h ); + void setSizeHonorAspect( const glabels::Distance& w, const glabels::Distance& h ); + void setWHonorAspect( const glabels::Distance& w ); + void setHHonorAspect( const glabels::Distance& h ); + LabelRegion getExtent(); + void rotate( double thetaDegs ); + void flipHoriz(); + void flipVert(); + bool isLocatedAt( double scale, const glabels::Distance& x, const glabels::Distance& y ) const; + Handle* handleAt( double scale, const glabels::Distance& x, const glabels::Distance& y ) const; - /////////////////////////////////////////////////////////////// - // Drawing operations - /////////////////////////////////////////////////////////////// - public: - void draw( QPainter* painter, bool inEditor, MergeRecord* record ) const; - void drawSelectionHighlight( QPainter* painter, double scale ) const; + /////////////////////////////////////////////////////////////// + // Drawing operations + /////////////////////////////////////////////////////////////// +public: + void draw( QPainter* painter, bool inEditor, MergeRecord* record ) const; + void drawSelectionHighlight( QPainter* painter, double scale ) const; - protected: - virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0; - virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0; - virtual QPainterPath hoverPath( double scale ) const = 0; +protected: + virtual void drawShadow( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0; + virtual void drawObject( QPainter* painter, bool inEditor, MergeRecord* record ) const = 0; + virtual QPainterPath hoverPath( double scale ) const = 0; - /////////////////////////////////////////////////////////////// - // Protected Members - /////////////////////////////////////////////////////////////// - protected: - bool mSelectedFlag; + /////////////////////////////////////////////////////////////// + // Protected Members + /////////////////////////////////////////////////////////////// +protected: + bool mSelectedFlag; - libglabels::Distance mX0; - libglabels::Distance mY0; - libglabels::Distance mW; - libglabels::Distance mH; + glabels::Distance mX0; + glabels::Distance mY0; + glabels::Distance mW; + glabels::Distance mH; - bool mShadowState; - libglabels::Distance mShadowX; - libglabels::Distance mShadowY; - double mShadowOpacity; - ColorNode mShadowColorNode; + bool mShadowState; + glabels::Distance mShadowX; + glabels::Distance mShadowY; + double mShadowOpacity; + ColorNode mShadowColorNode; - QList mHandles; - Outline* mOutline; + QList mHandles; + Outline* mOutline; - /////////////////////////////////////////////////////////////// - // Private Members - /////////////////////////////////////////////////////////////// - private: - static int msNextId; - int mId; + /////////////////////////////////////////////////////////////// + // Private Members + /////////////////////////////////////////////////////////////// +private: + static int msNextId; + int mId; - QMatrix mMatrix; + QMatrix mMatrix; - }; +}; -} -#endif // glabels_LabelModelObject_h +#endif // LabelModelObject_h diff --git a/glabels/LabelModelShapeObject.cpp b/glabels/LabelModelShapeObject.cpp index dfc3832..017db99 100644 --- a/glabels/LabelModelShapeObject.cpp +++ b/glabels/LabelModelShapeObject.cpp @@ -24,137 +24,131 @@ #include -namespace glabels +/// +/// Constructor +/// +LabelModelShapeObject::LabelModelShapeObject( QObject* parent ) : LabelModelObject(parent) { + mOutline = new Outline( this ); - /// - /// Constructor - /// - LabelModelShapeObject::LabelModelShapeObject( QObject* parent ) : LabelModelObject(parent) - { - mOutline = new Outline( this ); - - mHandles << new HandleNorthWest( this ); - mHandles << new HandleNorth( this ); - mHandles << new HandleNorthEast( this ); - mHandles << new HandleEast( this ); - mHandles << new HandleSouthEast( this ); - mHandles << new HandleSouth( this ); - mHandles << new HandleSouthWest( this ); - mHandles << new HandleWest( this ); - - mLineWidth = 1.0; - mLineColorNode = ColorNode( QColor( 0, 0, 0 ) ); - mFillColorNode = ColorNode( QColor( 0, 255, 0 ) ); - } - - - /// - /// Destructor - /// - LabelModelShapeObject::~LabelModelShapeObject() - { - delete mOutline; - - foreach( Handle* handle, mHandles ) - { - delete handle; - } - mHandles.clear(); - } - - - /// - /// Line Width Property Getter - /// - libglabels::Distance LabelModelShapeObject::lineWidth( void ) const - { - return mLineWidth; - } - - - /// - /// Line Width Property Setter - /// - void LabelModelShapeObject::setLineWidth( const libglabels::Distance& value ) - { - if ( mLineWidth != value ) - { - mLineWidth = value; - emit changed(); - } - } - - - /// - /// Line Color Node Property Getter - /// - ColorNode LabelModelShapeObject::lineColorNode( void ) const - { - return mLineColorNode; - } - - - /// - /// Line Color Node Property Setter - /// - void LabelModelShapeObject::setLineColorNode( const ColorNode& value ) - { - if ( mLineColorNode != value ) - { - mLineColorNode = value; - emit changed(); - } - } - - - /// - /// Fill Color Node Property Getter - /// - ColorNode LabelModelShapeObject::fillColorNode( void ) const - { - return mFillColorNode; - } - - - /// - /// Fill Color Node Property Setter - /// - void LabelModelShapeObject::setFillColorNode( const ColorNode& value ) - { - if ( mFillColorNode != value ) - { - mFillColorNode = value; - emit changed(); - } - } - - - /// - /// Can Fill Capability Implementation - /// - bool LabelModelShapeObject::canFill() - { - return true; - } - - - /// - /// Can Line Color Capability Implementation - /// - bool LabelModelShapeObject::canLineColor() - { - return true; - } - - - /// - /// Can Line Width Capability Implementation - /// - bool LabelModelShapeObject::canLineWidth() - { - return true; - } - + mHandles << new HandleNorthWest( this ); + mHandles << new HandleNorth( this ); + mHandles << new HandleNorthEast( this ); + mHandles << new HandleEast( this ); + mHandles << new HandleSouthEast( this ); + mHandles << new HandleSouth( this ); + mHandles << new HandleSouthWest( this ); + mHandles << new HandleWest( this ); + mLineWidth = 1.0; + mLineColorNode = ColorNode( QColor( 0, 0, 0 ) ); + mFillColorNode = ColorNode( QColor( 0, 255, 0 ) ); +} + + +/// +/// Destructor +/// +LabelModelShapeObject::~LabelModelShapeObject() +{ + delete mOutline; + + foreach( Handle* handle, mHandles ) + { + delete handle; + } + mHandles.clear(); +} + + +/// +/// Line Width Property Getter +/// +glabels::Distance LabelModelShapeObject::lineWidth( void ) const +{ + return mLineWidth; +} + + +/// +/// Line Width Property Setter +/// +void LabelModelShapeObject::setLineWidth( const glabels::Distance& value ) +{ + if ( mLineWidth != value ) + { + mLineWidth = value; + emit changed(); + } +} + + +/// +/// Line Color Node Property Getter +/// +ColorNode LabelModelShapeObject::lineColorNode( void ) const +{ + return mLineColorNode; +} + + +/// +/// Line Color Node Property Setter +/// +void LabelModelShapeObject::setLineColorNode( const ColorNode& value ) +{ + if ( mLineColorNode != value ) + { + mLineColorNode = value; + emit changed(); + } +} + + +/// +/// Fill Color Node Property Getter +/// +ColorNode LabelModelShapeObject::fillColorNode( void ) const +{ + return mFillColorNode; +} + + +/// +/// Fill Color Node Property Setter +/// +void LabelModelShapeObject::setFillColorNode( const ColorNode& value ) +{ + if ( mFillColorNode != value ) + { + mFillColorNode = value; + emit changed(); + } +} + + +/// +/// Can Fill Capability Implementation +/// +bool LabelModelShapeObject::canFill() +{ + return true; +} + + +/// +/// Can Line Color Capability Implementation +/// +bool LabelModelShapeObject::canLineColor() +{ + return true; +} + + +/// +/// Can Line Width Capability Implementation +/// +bool LabelModelShapeObject::canLineWidth() +{ + return true; } diff --git a/glabels/LabelModelShapeObject.h b/glabels/LabelModelShapeObject.h index 63012a6..486c1a2 100644 --- a/glabels/LabelModelShapeObject.h +++ b/glabels/LabelModelShapeObject.h @@ -18,75 +18,71 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_LabelModelShapeObject_h -#define glabels_LabelModelShapeObject_h +#ifndef LabelModelShapeObject_h +#define LabelModelShapeObject_h #include "LabelModelObject.h" -namespace glabels +/// +/// Label Model Shape Object (Box or Ellipse) +/// +class LabelModelShapeObject : public LabelModelObject { + Q_OBJECT - /// - /// Label Model Shape Object (Box or Ellipse) - /// - class LabelModelShapeObject : public LabelModelObject - { - Q_OBJECT - - /////////////////////////////////////////////////////////////// - // Lifecycle Methods - /////////////////////////////////////////////////////////////// - protected: - LabelModelShapeObject( QObject* parent = 0 ); - public: - virtual ~LabelModelShapeObject(); + /////////////////////////////////////////////////////////////// + // Lifecycle Methods + /////////////////////////////////////////////////////////////// +protected: + LabelModelShapeObject( QObject* parent = 0 ); +public: + virtual ~LabelModelShapeObject(); - /////////////////////////////////////////////////////////////// - // Property Implementations - /////////////////////////////////////////////////////////////// - public: - // - // Shape Property: lineWidth - // - virtual libglabels::Distance lineWidth( void ) const; - virtual void setLineWidth( const libglabels::Distance& value ); + /////////////////////////////////////////////////////////////// + // Property Implementations + /////////////////////////////////////////////////////////////// +public: + // + // Shape Property: lineWidth + // + virtual glabels::Distance lineWidth( void ) const; + virtual void setLineWidth( const glabels::Distance& value ); - // - // Shape Property: lineColorNode - // - virtual ColorNode lineColorNode( void ) const; - virtual void setLineColorNode( const ColorNode& value ); + // + // Shape Property: lineColorNode + // + virtual ColorNode lineColorNode( void ) const; + virtual void setLineColorNode( const ColorNode& value ); - // - // Shape Property: fillColorNode - // - virtual ColorNode fillColorNode( void ) const; - virtual void setFillColorNode( const ColorNode& value ); + // + // Shape Property: fillColorNode + // + virtual ColorNode fillColorNode( void ) const; + virtual void setFillColorNode( const ColorNode& value ); - /////////////////////////////////////////////////////////////// - // Capability Implementations - /////////////////////////////////////////////////////////////// - public: - virtual bool canFill(); - virtual bool canLineColor(); - virtual bool canLineWidth(); + /////////////////////////////////////////////////////////////// + // Capability Implementations + /////////////////////////////////////////////////////////////// +public: + virtual bool canFill(); + virtual bool canLineColor(); + virtual bool canLineWidth(); - /////////////////////////////////////////////////////////////// - // Private Members - /////////////////////////////////////////////////////////////// - protected: - libglabels::Distance mLineWidth; - ColorNode mLineColorNode; - ColorNode mFillColorNode; + /////////////////////////////////////////////////////////////// + // Private Members + /////////////////////////////////////////////////////////////// +protected: + glabels::Distance mLineWidth; + ColorNode mLineColorNode; + ColorNode mFillColorNode; - }; +}; -} -#endif // glabels_LabelModelShapeObject_h +#endif // LabelModelShapeObject_h diff --git a/glabels/LabelRegion.cpp b/glabels/LabelRegion.cpp index dd17b11..a1d211e 100644 --- a/glabels/LabelRegion.cpp +++ b/glabels/LabelRegion.cpp @@ -24,22 +24,17 @@ #include -namespace glabels +QRectF LabelRegion::rect() const { + using std::min; + using std::fabs; - QRectF LabelRegion::rect() const - { - using std::min; - using std::fabs; + QRectF r; - QRectF r; - - r.setX( min( mX1, mX2 ).pt() ); - r.setY( min( mY1, mY2 ).pt() ); - r.setWidth( fabs( mX2 - mX1 ).pt() ); - r.setHeight( fabs( mY2 - mY1 ).pt() ); - - return r; - } + r.setX( min( mX1, mX2 ).pt() ); + r.setY( min( mY1, mY2 ).pt() ); + r.setWidth( fabs( mX2 - mX1 ).pt() ); + r.setHeight( fabs( mY2 - mY1 ).pt() ); + return r; } diff --git a/glabels/LabelRegion.h b/glabels/LabelRegion.h index 0d7cc55..04ad4a0 100644 --- a/glabels/LabelRegion.h +++ b/glabels/LabelRegion.h @@ -18,123 +18,119 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_LabelRegion_h -#define glabels_LabelRegion_h +#ifndef LabelRegion_h +#define LabelRegion_h #include #include "libglabels/Distance.h" -namespace glabels +/// +/// Label Region Type +/// +struct LabelRegion { - /// - /// Label Region Type - /// - struct LabelRegion - { - - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - // - // X1 Property - // - libglabels::Distance x1( void ) const; - void setX1( const libglabels::Distance& value ); + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + // + // X1 Property + // + glabels::Distance x1( void ) const; + void setX1( const glabels::Distance& value ); - // - // Y1 Property - // - libglabels::Distance y1( void ) const; - void setY1( const libglabels::Distance& value ); + // + // Y1 Property + // + glabels::Distance y1( void ) const; + void setY1( const glabels::Distance& value ); - // - // X2 Property - // - libglabels::Distance x2( void ) const; - void setX2( const libglabels::Distance& value ); + // + // X2 Property + // + glabels::Distance x2( void ) const; + void setX2( const glabels::Distance& value ); - // - // Y2 Property - // - libglabels::Distance y2( void ) const; - void setY2( const libglabels::Distance& value ); - - - ///////////////////////////////// - // Methods - ///////////////////////////////// - public: - QRectF rect() const; - - - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - libglabels::Distance mX1; - libglabels::Distance mY1; - libglabels::Distance mX2; - libglabels::Distance mY2; - }; + // + // Y2 Property + // + glabels::Distance y2( void ) const; + void setY2( const glabels::Distance& value ); ///////////////////////////////// - // INLINE METHODS + // Methods ///////////////////////////////// - inline libglabels::Distance LabelRegion::x1( void ) const - { - return mX1; - } +public: + QRectF rect() const; - inline void LabelRegion::setX1( const libglabels::Distance& value ) - { - mX1 = value; - } + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + glabels::Distance mX1; + glabels::Distance mY1; + glabels::Distance mX2; + glabels::Distance mY2; +}; - inline libglabels::Distance LabelRegion::y1( void ) const - { - return mY1; - } - - - inline void LabelRegion::setY1( const libglabels::Distance& value ) - { - mY1 = value; - } - - - inline libglabels::Distance LabelRegion::x2( void ) const - { - return mX2; - } - - - inline void LabelRegion::setX2( const libglabels::Distance& value ) - { - mX2 = value; - } - - - inline libglabels::Distance LabelRegion::y2( void ) const - { - return mY2; - } - - - inline void LabelRegion::setY2( const libglabels::Distance& value ) - { - mY2 = value; - } - +///////////////////////////////// +// INLINE METHODS +///////////////////////////////// +inline glabels::Distance LabelRegion::x1( void ) const +{ + return mX1; } -#endif // glabels_LabelRegion_h + +inline void LabelRegion::setX1( const glabels::Distance& value ) +{ + mX1 = value; +} + + +inline glabels::Distance LabelRegion::y1( void ) const +{ + return mY1; +} + + +inline void LabelRegion::setY1( const glabels::Distance& value ) +{ + mY1 = value; +} + + +inline glabels::Distance LabelRegion::x2( void ) const +{ + return mX2; +} + + +inline void LabelRegion::setX2( const glabels::Distance& value ) +{ + mX2 = value; +} + + +inline glabels::Distance LabelRegion::y2( void ) const +{ + return mY2; +} + + +inline void LabelRegion::setY2( const glabels::Distance& value ) +{ + mY2 = value; +} + + +#endif // LabelRegion_h diff --git a/glabels/MainWindow.cpp b/glabels/MainWindow.cpp index 7789e01..450277f 100644 --- a/glabels/MainWindow.cpp +++ b/glabels/MainWindow.cpp @@ -45,1335 +45,1328 @@ #include "Help.h" -namespace glabels +/// +/// Static window list +/// +QList MainWindow::smWindowList; + + +/// +/// Constructor +/// +MainWindow::MainWindow() + : mModel(0) { + createActions(); + createMenus(); + createToolBars(); - /// - /// Static window list - /// - QList MainWindow::smWindowList; + QWidget* propertiesPage = createPropertiesPage(); + QWidget* editorPage = createEditorPage(); + QWidget* mergePage = createMergePage(); + QWidget* printPage = createPrintPage(); + mNotebook = new QTabWidget(); + mNotebook->addTab( propertiesPage, "Properties" ); + mNotebook->addTab( editorPage, "Editor" ); + mNotebook->addTab( mergePage, "Merge" ); + mNotebook->addTab( printPage, "Print" ); + mNotebook->setEnabled( false ); - /// - /// Constructor - /// - MainWindow::MainWindow() - : mModel(0) - { - createActions(); - createMenus(); - createToolBars(); + setCentralWidget( mNotebook ); - QWidget* propertiesPage = createPropertiesPage(); - QWidget* editorPage = createEditorPage(); - QWidget* mergePage = createMergePage(); - QWidget* printPage = createPrintPage(); + createStatusBar(); - mNotebook = new QTabWidget(); - mNotebook->addTab( propertiesPage, "Properties" ); - mNotebook->addTab( editorPage, "Editor" ); - mNotebook->addTab( mergePage, "Merge" ); - mNotebook->addTab( printPage, "Print" ); - mNotebook->setEnabled( false ); - - setCentralWidget( mNotebook ); - - createStatusBar(); - - setDocVerbsEnabled( false ); - setPasteVerbsEnabled( false ); - setTitle(); - - readSettings(); - - smWindowList.push_back( this ); - } - - - /// - /// Destructor - /// - MainWindow::~MainWindow() - { - smWindowList.removeOne( this ); - } - - - /// - /// Get model accessor - /// - LabelModel* MainWindow::model() const - { - return mModel; - } - - - /// - /// Set model accessor - /// - void MainWindow::setModel( LabelModel *label ) - { - mModel = label; - mPropertiesView->setModel( mModel ); - mView->setModel( mModel ); - mObjectEditor->setModel( mModel ); - mPrintView->setModel( mModel ); - - mNotebook->setEnabled( true ); - setDocVerbsEnabled( true ); - setSelectionVerbsEnabled( false ); - setMultiSelectionVerbsEnabled( false ); - setTitle(); - - connect( mView, SIGNAL(contextMenuActivate()), this, SLOT(onContextMenuActivate()) ); - connect( mModel, SIGNAL(nameChanged()), this, SLOT(onNameChanged()) ); - connect( mModel, SIGNAL(modifiedChanged()), this, SLOT(onModifiedChanged()) ); - connect( mModel, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()) ); - connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) ); - } - - - /// - /// Is window empty? - /// - bool MainWindow::isEmpty() const - { - return mModel == 0; - } - - /// - /// Get window list - /// - QList MainWindow::windowList() - { - return smWindowList; - } - - - /// - /// Close Event Handler - /// - void MainWindow::closeEvent( QCloseEvent *event ) - { - writeSettings(); - event->accept(); - } - - - /// - /// Create Actions - /// - void MainWindow::createActions() - { - /* File actions */ - fileNewAction = new QAction( tr("&New..."), this ); - fileNewAction->setIcon( QIcon::fromTheme( "document-new", Icons::Fallback::FileNew() ) ); - fileNewAction->setShortcut( QKeySequence::New ); - fileNewAction->setStatusTip( tr("Create a new file") ); - connect( fileNewAction, SIGNAL(triggered()), this, SLOT(fileNew()) ); - - fileOpenAction = new QAction( tr("&Open..."), this ); - fileOpenAction->setIcon( QIcon::fromTheme( "document-open", Icons::Fallback::FileOpen() ) ); - fileOpenAction->setShortcut( QKeySequence::Open ); - fileOpenAction->setStatusTip( tr("Open a file") ); - connect( fileOpenAction, SIGNAL(triggered()), this, SLOT(fileOpen()) ); - - fileSaveAction = new QAction( tr("&Save"), this ); - fileSaveAction->setIcon( QIcon::fromTheme( "document-save", Icons::Fallback::FileSave() ) ); - fileSaveAction->setShortcut( QKeySequence::Save ); - fileSaveAction->setStatusTip( tr("Save current file") ); - connect( fileSaveAction, SIGNAL(triggered()), this, SLOT(fileSave()) ); - - fileSaveAsAction = new QAction( tr("Save &As..."), this ); - fileSaveAsAction->setIcon( QIcon::fromTheme( "document-save-as", Icons::Fallback::FileSaveAs() ) ); - fileSaveAsAction->setShortcut( QKeySequence::SaveAs ); - fileSaveAsAction->setStatusTip( tr("Save current file to a different name") ); - connect( fileSaveAsAction, SIGNAL(triggered()), this, SLOT(fileSaveAs()) ); - - filePropertiesAction = new QAction( tr("Properties..."), this ); - filePropertiesAction->setIcon( QIcon::fromTheme( "document-properties" ) ); - filePropertiesAction->setStatusTip( tr("Modify document properties") ); - connect( filePropertiesAction, SIGNAL(triggered()), this, SLOT(fileProperties()) ); - - fileTemplateDesignerAction = new QAction( tr("Template &Designer..."), this ); - fileTemplateDesignerAction->setStatusTip( tr("Create custom templates") ); - connect( fileTemplateDesignerAction, SIGNAL(triggered()), this, SLOT(fileTemplateDesigner()) ); - - fileCloseAction = new QAction( tr("&Close"), this ); - fileCloseAction->setIcon( QIcon::fromTheme( "window-close" ) ); - fileCloseAction->setShortcut( QKeySequence::Close ); - fileCloseAction->setStatusTip( tr("Close the current window") ); - connect( fileCloseAction, SIGNAL(triggered()), this, SLOT(fileClose()) ); - - fileExitAction = new QAction( tr("E&xit"), this ); - fileExitAction->setIcon( QIcon::fromTheme( "application-exit" ) ); - fileExitAction->setShortcut( QKeySequence::Quit ); - fileExitAction->setStatusTip( tr("Exit glabels") ); - connect( fileExitAction, SIGNAL(triggered()), this, SLOT(fileExit()) ); - - - /* Edit actions */ - editUndoAction = new QAction( tr("Undo"), this ); - editUndoAction->setIcon( QIcon::fromTheme( "edit-undo" ) ); - editUndoAction->setShortcut( QKeySequence::Undo ); - editUndoAction->setStatusTip( tr("Undo") ); - connect( editUndoAction, SIGNAL(triggered()), this, SLOT(editUndo()) ); - - editRedoAction = new QAction( tr("Redo"), this ); - editRedoAction->setIcon( QIcon::fromTheme( "edit-redo" ) ); - editRedoAction->setShortcut( QKeySequence::Redo ); - editRedoAction->setStatusTip( tr("Redo") ); - connect( editRedoAction, SIGNAL(triggered()), this, SLOT(editRedo()) ); - - editCutAction = new QAction( tr("Cut"), this ); - editCutAction->setIcon( QIcon::fromTheme( "edit-cut", Icons::Fallback::EditCut() ) ); - editCutAction->setShortcut( QKeySequence::Cut ); - editCutAction->setStatusTip( tr("Cut the selection") ); - connect( editCutAction, SIGNAL(triggered()), this, SLOT(editCut()) ); - - editCopyAction = new QAction( tr("&Copy"), this ); - editCopyAction->setIcon( QIcon::fromTheme( "edit-copy", Icons::Fallback::EditCopy() ) ); - editCopyAction->setShortcut( QKeySequence::Copy ); - editCopyAction->setStatusTip( tr("Copy the selection") ); - connect( editCopyAction, SIGNAL(triggered()), this, SLOT(editCopy()) ); - - editPasteAction = new QAction( tr("&Paste"), this ); - editPasteAction->setIcon( QIcon::fromTheme( "edit-paste", Icons::Fallback::EditPaste() ) ); - editPasteAction->setShortcut( QKeySequence::Paste ); - editPasteAction->setStatusTip( tr("Paste the clipboard") ); - connect( editPasteAction, SIGNAL(triggered()), this, SLOT(editPaste()) ); - - editDeleteAction = new QAction( tr("&Delete"), this ); - editDeleteAction->setIcon( QIcon::fromTheme( "edit-delete" ) ); - editDeleteAction->setShortcut( QKeySequence::Delete ); - editDeleteAction->setStatusTip( tr("Delete the selected objects") ); - connect( editDeleteAction, SIGNAL(triggered()), this, SLOT(editDelete()) ); - - editSelectAllAction = new QAction( tr("Select &All"), this ); - editSelectAllAction->setIcon( QIcon::fromTheme( "edit-select-all" ) ); - editSelectAllAction->setShortcut( QKeySequence::SelectAll ); - editSelectAllAction->setStatusTip( tr("Select all objects") ); - connect( editSelectAllAction, SIGNAL(triggered()), this, SLOT(editSelectAll()) ); - - editUnSelectAllAction = new QAction( tr("Un-select All"), this ); - editUnSelectAllAction->setIcon( QIcon::fromTheme( "edit-unselect-all" ) ); - editUnSelectAllAction->setStatusTip( tr("Remove all selections") ); - connect( editUnSelectAllAction, SIGNAL(triggered()), this, SLOT(editUnSelectAll()) ); - - editPreferencesAction = new QAction( tr("Preferences"), this ); - editPreferencesAction->setIcon( QIcon::fromTheme( "edit-preferences" ) ); - editPreferencesAction->setShortcut( QKeySequence::Preferences ); - editPreferencesAction->setStatusTip( tr("Configure the application") ); - connect( editPreferencesAction, SIGNAL(triggered()), this, SLOT(editPreferences()) ); - - - /* View actions */ - viewFileToolBarAction = new QAction( tr("File"), this ); - viewFileToolBarAction->setCheckable( true ); - viewFileToolBarAction->setStatusTip( tr("Change visibility of file toolbar in current window") ); - connect( viewFileToolBarAction, SIGNAL(toggled(bool)), this, SLOT(viewFileToolBar(bool)) ); - - viewEditorToolBarAction = new QAction( tr("Editor"), this ); - viewEditorToolBarAction->setCheckable( true ); - viewEditorToolBarAction->setStatusTip( tr("Change visibility of editor toolbar in current window") ); - connect( viewEditorToolBarAction, SIGNAL(toggled(bool)), this, SLOT(viewEditorToolBar(bool)) ); - - - viewGridAction = new QAction( tr("Grid"), this ); - viewGridAction->setCheckable( true ); - viewGridAction->setStatusTip( tr("Change visibility of the grid in current window") ); - connect( viewGridAction, SIGNAL(toggled(bool)), this, SLOT(viewGrid(bool)) ); - - viewMarkupAction = new QAction( tr("Markup"), this ); - viewMarkupAction->setCheckable( true ); - viewMarkupAction->setStatusTip( tr("Change visibility of markup lines in current window") ); - connect( viewMarkupAction, SIGNAL(toggled(bool)), this, SLOT(viewMarkup(bool)) ); - - viewZoomInAction = new QAction( tr("Zoom &In"), this ); - viewZoomInAction->setIcon( QIcon::fromTheme( "zoom-in", Icons::Fallback::ZoomIn() ) ); - viewZoomInAction->setShortcut( QKeySequence::ZoomIn ); - viewZoomInAction->setStatusTip( tr("Increase magnification") ); - connect( viewZoomInAction, SIGNAL(triggered()), this, SLOT(viewZoomIn()) ); - - viewZoomOutAction = new QAction( tr("Zoom &Out"), this ); - viewZoomOutAction->setIcon( QIcon::fromTheme( "zoom-out", Icons::Fallback::ZoomOut() ) ); - viewZoomOutAction->setShortcut( QKeySequence::ZoomOut ); - viewZoomOutAction->setStatusTip( tr("Decrease magnification") ); - connect( viewZoomOutAction, SIGNAL(triggered()), this, SLOT(viewZoomOut()) ); - - viewZoom1To1Action = new QAction( tr("Zoom &1 to 1"), this ); - viewZoom1To1Action->setIcon( QIcon::fromTheme( "zoom-original", Icons::Fallback::ZoomOriginal() ) ); - viewZoom1To1Action->setStatusTip( tr("Restore scale to 100%") ); - connect( viewZoom1To1Action, SIGNAL(triggered()), this, SLOT(viewZoom1To1()) ); - - viewZoomToFitAction = new QAction( tr("Zoom to &Fit"), this ); - viewZoomToFitAction->setIcon( QIcon::fromTheme( "zoom-fit-best", Icons::Fallback::ZoomBestFit() ) ); - viewZoomToFitAction->setStatusTip( tr("Set scale to fit window") ); - connect( viewZoomToFitAction, SIGNAL(triggered()), this, SLOT(viewZoomToFit()) ); - - - /* Object actions */ - objectsArrowModeAction = new QAction( tr("Select Mode"), this ); - objectsArrowModeAction->setIcon( Icons::Arrow() ); - objectsArrowModeAction->setStatusTip( tr("Select, move and modify objects") ); - connect( objectsArrowModeAction, SIGNAL(triggered()), this, SLOT(objectsArrowMode()) ); - - objectsCreateTextAction = new QAction( tr("Text"), this ); - objectsCreateTextAction->setIcon( Icons::Text() ); - objectsCreateTextAction->setStatusTip( tr("Create text object") ); - connect( objectsCreateTextAction, SIGNAL(triggered()), this, SLOT(objectsCreateText()) ); - - objectsCreateBoxAction = new QAction( tr("Box"), this ); - objectsCreateBoxAction->setIcon( Icons::Box() ); - objectsCreateBoxAction->setStatusTip( tr("Create box object") ); - connect( objectsCreateBoxAction, SIGNAL(triggered()), this, SLOT(objectsCreateBox()) ); - - objectsCreateLineAction = new QAction( tr("Line"), this ); - objectsCreateLineAction->setIcon( Icons::Line() ); - objectsCreateLineAction->setStatusTip( tr("Create line object") ); - connect( objectsCreateLineAction, SIGNAL(triggered()), this, SLOT(objectsCreateLine()) ); - - objectsCreateEllipseAction = new QAction( tr("Ellipse"), this ); - objectsCreateEllipseAction->setIcon( Icons::Ellipse() ); - objectsCreateEllipseAction->setStatusTip( tr("Create ellipse/circle object") ); - connect( objectsCreateEllipseAction, SIGNAL(triggered()), this, SLOT(objectsCreateEllipse()) ); - - objectsCreateImageAction = new QAction( tr("Image"), this ); - objectsCreateImageAction->setIcon( Icons::Image() ); - objectsCreateImageAction->setStatusTip( tr("Create image object") ); - connect( objectsCreateImageAction, SIGNAL(triggered()), this, SLOT(objectsCreateImage()) ); - - objectsCreateBarcodeAction = new QAction( tr("Barcode"), this ); - objectsCreateBarcodeAction->setIcon( Icons::Barcode() ); - objectsCreateBarcodeAction->setStatusTip( tr("Create barcode object") ); - connect( objectsCreateBarcodeAction, SIGNAL(triggered()), this, SLOT(objectsCreateBarcode()) ); - - objectsOrderRaiseAction = new QAction( tr("Bring To Front"), this ); - objectsOrderRaiseAction->setIcon( Icons::OrderTop() ); - objectsOrderRaiseAction->setStatusTip( tr("Raise selection to top") ); - connect( objectsOrderRaiseAction, SIGNAL(triggered()), this, SLOT(objectsOrderRaise()) ); - - objectsOrderLowerAction = new QAction( tr("Send To Back"), this ); - objectsOrderLowerAction->setIcon( Icons::OrderBottom() ); - objectsOrderLowerAction->setStatusTip( tr("Lower selection to bottom") ); - connect( objectsOrderLowerAction, SIGNAL(triggered()), this, SLOT(objectsOrderLower()) ); - - objectsXformRotateLeftAction = new QAction( tr("Rotate Left"), this ); - objectsXformRotateLeftAction->setIcon( Icons::RotateLeft() ); - objectsXformRotateLeftAction->setStatusTip( tr("Rotate object(s) 90 degrees counter-clockwise") ); - connect( objectsXformRotateLeftAction, SIGNAL(triggered()), this, SLOT(objectsXformRotateLeft()) ); - - objectsXformRotateRightAction = new QAction( tr("Rotate Right"), this ); - objectsXformRotateRightAction->setIcon( Icons::RotateRight() ); - objectsXformRotateRightAction->setStatusTip( tr("Rotate object(s) 90 degrees clockwise") ); - connect( objectsXformRotateRightAction, SIGNAL(triggered()), this, SLOT(objectsXformRotateRight()) ); - - objectsXformFlipHorizAction = new QAction( tr("Flip Horizontally"), this ); - objectsXformFlipHorizAction->setIcon( Icons::FlipHoriz() ); - objectsXformFlipHorizAction->setStatusTip( tr("Flip object(s) horizontally") ); - connect( objectsXformFlipHorizAction, SIGNAL(triggered()), this, SLOT(objectsXformFlipHoriz()) ); - - objectsXformFlipVertAction = new QAction( tr("Flip Vertically"), this ); - objectsXformFlipVertAction->setIcon( Icons::FlipVert() ); - objectsXformFlipVertAction->setStatusTip( tr("Flip object(s) vertically") ); - connect( objectsXformFlipVertAction, SIGNAL(triggered()), this, SLOT(objectsXformFlipVert()) ); - - objectsAlignLeftAction = new QAction( tr("Align Left"), this ); - objectsAlignLeftAction->setIcon( Icons::AlignLeft() ); - objectsAlignLeftAction->setStatusTip( tr("Align objects to left edges") ); - connect( objectsAlignLeftAction, SIGNAL(triggered()), this, SLOT(objectsAlignLeft()) ); - - objectsAlignHCenterAction = new QAction( tr("Align Center"), this ); - objectsAlignHCenterAction->setIcon( Icons::AlignHCenter() ); - objectsAlignHCenterAction->setStatusTip( tr("Align objects to horizontal centers") ); - connect( objectsAlignHCenterAction, SIGNAL(triggered()), this, SLOT(objectsAlignHCenter()) ); - - objectsAlignRightAction = new QAction( tr("Align Right"), this ); - objectsAlignRightAction->setIcon( Icons::AlignRight() ); - objectsAlignRightAction->setStatusTip( tr("Align objects to right edges") ); - connect( objectsAlignRightAction, SIGNAL(triggered()), this, SLOT(objectsAlignRight()) ); - - objectsAlignTopAction = new QAction( tr("Align Top"), this ); - objectsAlignTopAction->setIcon( Icons::AlignTop() ); - objectsAlignTopAction->setStatusTip( tr("Align objects to top edges") ); - connect( objectsAlignTopAction, SIGNAL(triggered()), this, SLOT(objectsAlignTop()) ); - - objectsAlignVCenterAction = new QAction( tr("Align Middle"), this ); - objectsAlignVCenterAction->setIcon( Icons::AlignVCenter() ); - objectsAlignVCenterAction->setStatusTip( tr("Align objects to vertical centers") ); - connect( objectsAlignVCenterAction, SIGNAL(triggered()), this, SLOT(objectsAlignVCenter()) ); - - objectsAlignBottomAction = new QAction( tr("Align Bottom"), this ); - objectsAlignBottomAction->setIcon( Icons::AlignBottom() ); - objectsAlignBottomAction->setStatusTip( tr("Align objects to bottom edges") ); - connect( objectsAlignBottomAction, SIGNAL(triggered()), this, SLOT(objectsAlignBottom()) ); - - objectsCenterHorizAction = new QAction( tr("Center Horizontally"), this ); - objectsCenterHorizAction->setIcon( Icons::CenterHoriz() ); - objectsCenterHorizAction->setStatusTip( tr("Horizontally center objects in label") ); - connect( objectsCenterHorizAction, SIGNAL(triggered()), this, SLOT(objectsCenterHoriz()) ); - - objectsCenterVertAction = new QAction( tr("Center Vertically"), this ); - objectsCenterVertAction->setIcon( Icons::CenterVert() ); - objectsCenterVertAction->setStatusTip( tr("Vertically center objects in label") ); - connect( objectsCenterVertAction, SIGNAL(triggered()), this, SLOT(objectsCenterVert()) ); - - - /* Help actions */ - helpContentsAction = new QAction( tr("&Contents..."), this ); - helpContentsAction->setIcon( QIcon::fromTheme( "help-contents" ) ); - helpContentsAction->setShortcut( QKeySequence::HelpContents ); - helpContentsAction->setStatusTip( tr("Open gLabels manual") ); - connect( helpContentsAction, SIGNAL(triggered()), this, SLOT(helpContents()) ); - - helpAboutAction = new QAction( tr("&About..."), this ); - helpAboutAction->setIcon( QIcon::fromTheme( "help-about" ) ); - helpAboutAction->setStatusTip( tr("About gLabels") ); - connect( helpAboutAction, SIGNAL(triggered()), this, SLOT(helpAbout()) ); - - - /* Context menu version of edit actions */ - contextCutAction = new QAction( tr("Cut"), this ); - contextCutAction->setIcon( QIcon::fromTheme( "edit-cut", Icons::Fallback::EditCut() ) ); - contextCutAction->setStatusTip( tr("Cut the selection") ); - connect( contextCutAction, SIGNAL(triggered()), this, SLOT(editCut()) ); - - contextCopyAction = new QAction( tr("&Copy"), this ); - contextCopyAction->setIcon( QIcon::fromTheme( "edit-copy", Icons::Fallback::EditCopy() ) ); - contextCopyAction->setStatusTip( tr("Copy the selection") ); - connect( contextCopyAction, SIGNAL(triggered()), this, SLOT(editCopy()) ); - - contextPasteAction = new QAction( tr("&Paste"), this ); - contextPasteAction->setIcon( QIcon::fromTheme( "edit-paste", Icons::Fallback::EditPaste() ) ); - contextPasteAction->setStatusTip( tr("Paste the clipboard") ); - connect( contextPasteAction, SIGNAL(triggered()), this, SLOT(editPaste()) ); - - contextDeleteAction = new QAction( tr("&Delete"), this ); - contextDeleteAction->setIcon( QIcon::fromTheme( "edit-delete" ) ); - contextDeleteAction->setStatusTip( tr("Delete the selected objects") ); - connect( contextDeleteAction, SIGNAL(triggered()), this, SLOT(editDelete()) ); - } - - - /// - /// Create Menus - /// - void MainWindow::createMenus() - { - fileMenu = menuBar()->addMenu( tr("&File") ); - fileMenu->addAction( fileNewAction ); - fileMenu->addAction( fileOpenAction ); - fileMenu->addAction( fileSaveAction ); - fileMenu->addAction( fileSaveAsAction ); - fileMenu->addSeparator(); - fileMenu->addAction( filePropertiesAction ); - fileMenu->addAction( fileTemplateDesignerAction ); - fileMenu->addSeparator(); - fileMenu->addAction( fileCloseAction ); - fileMenu->addAction( fileExitAction ); - - editMenu = menuBar()->addMenu( tr("&Edit") ); - editMenu->addAction( editUndoAction ); - editMenu->addAction( editRedoAction ); - editMenu->addSeparator(); - editMenu->addAction( editCutAction ); - editMenu->addAction( editCopyAction ); - editMenu->addAction( editPasteAction ); - editMenu->addAction( editDeleteAction ); - editMenu->addSeparator(); - editMenu->addAction( editSelectAllAction ); - editMenu->addAction( editUnSelectAllAction ); - editMenu->addSeparator(); - editMenu->addAction( editPreferencesAction ); - - viewMenu = menuBar()->addMenu( tr("&View") ); - viewToolBarsMenu = viewMenu->addMenu( tr("Toolbars") ); - viewToolBarsMenu->addAction( viewFileToolBarAction ); - viewToolBarsMenu->addAction( viewEditorToolBarAction ); - viewMenu->addSeparator(); - viewMenu->addAction( viewGridAction ); - viewMenu->addAction( viewMarkupAction ); - viewMenu->addSeparator(); - viewMenu->addAction( viewZoomInAction ); - viewMenu->addAction( viewZoomOutAction ); - viewMenu->addAction( viewZoom1To1Action ); - viewMenu->addAction( viewZoomToFitAction ); - - objectsMenu = menuBar()->addMenu( tr("&Objects") ); - objectsMenu->addAction( objectsArrowModeAction ); - objectsCreateMenu = objectsMenu->addMenu( tr("&Create") ); - objectsCreateMenu->addAction( objectsCreateTextAction ); - objectsCreateMenu->addAction( objectsCreateBoxAction ); - objectsCreateMenu->addAction( objectsCreateLineAction ); - objectsCreateMenu->addAction( objectsCreateEllipseAction ); - objectsCreateMenu->addAction( objectsCreateImageAction ); - objectsCreateMenu->addAction( objectsCreateBarcodeAction ); - objectsMenu->addSeparator(); - objectsOrderMenu = objectsMenu->addMenu( tr("&Order") ); - objectsOrderMenu->addAction( objectsOrderRaiseAction ); - objectsOrderMenu->addAction( objectsOrderLowerAction ); - objectsXformMenu = objectsMenu->addMenu( tr("&Rotate/Flip") ); - objectsXformMenu->addAction( objectsXformRotateLeftAction ); - objectsXformMenu->addAction( objectsXformRotateRightAction ); - objectsXformMenu->addAction( objectsXformFlipHorizAction ); - objectsXformMenu->addAction( objectsXformFlipVertAction ); - objectsAlignMenu = objectsMenu->addMenu( tr("&Alignment") ); - objectsAlignMenu->addAction( objectsAlignLeftAction ); - objectsAlignMenu->addAction( objectsAlignHCenterAction ); - objectsAlignMenu->addAction( objectsAlignRightAction ); - objectsAlignMenu->addSeparator(); - objectsAlignMenu->addAction( objectsAlignTopAction ); - objectsAlignMenu->addAction( objectsAlignVCenterAction ); - objectsAlignMenu->addAction( objectsAlignBottomAction ); - objectsCenterMenu = objectsMenu->addMenu( tr("Center") ); - objectsCenterMenu->addAction( objectsCenterHorizAction ); - objectsCenterMenu->addAction( objectsCenterVertAction ); - - helpMenu = menuBar()->addMenu( tr("&Help") ); - helpMenu->addAction( helpContentsAction ); - helpMenu->addAction( helpAboutAction ); - - contextMenu = new QMenu(); - contextOrderMenu = contextMenu->addMenu( tr("&Order") ); - contextOrderMenu->addAction( objectsOrderRaiseAction ); - contextOrderMenu->addAction( objectsOrderLowerAction ); - contextXformMenu = contextMenu->addMenu( tr("&Rotate/Flip") ); - contextXformMenu->addAction( objectsXformRotateLeftAction ); - contextXformMenu->addAction( objectsXformRotateRightAction ); - contextXformMenu->addAction( objectsXformFlipHorizAction ); - contextXformMenu->addAction( objectsXformFlipVertAction ); - contextAlignMenu = contextMenu->addMenu( tr("&Alignment") ); - contextAlignMenu->addAction( objectsAlignLeftAction ); - contextAlignMenu->addAction( objectsAlignHCenterAction ); - contextAlignMenu->addAction( objectsAlignRightAction ); - contextAlignMenu->addSeparator(); - contextAlignMenu->addAction( objectsAlignTopAction ); - contextAlignMenu->addAction( objectsAlignVCenterAction ); - contextAlignMenu->addAction( objectsAlignBottomAction ); - contextCenterMenu = contextMenu->addMenu( tr("Center") ); - contextCenterMenu->addAction( objectsCenterHorizAction ); - contextCenterMenu->addAction( objectsCenterVertAction ); - contextMenu->addSeparator(); - contextMenu->addAction( contextCutAction ); - contextMenu->addAction( contextCopyAction ); - contextMenu->addAction( contextPasteAction ); - contextMenu->addAction( contextDeleteAction ); - - noSelectionContextMenu = new QMenu(); - noSelectionContextMenu->addAction( contextPasteAction ); - } - - - /// - /// Create Tool Bars - /// - void MainWindow::createToolBars() - { - fileToolBar = addToolBar( tr("&File") ); - fileToolBar->addAction( fileNewAction ); - fileToolBar->addAction( fileOpenAction ); - fileToolBar->addAction( fileSaveAction ); - - editorToolBar = new QToolBar( tr("&Editor") ); - editorToolBar->addAction( objectsArrowModeAction ); - editorToolBar->addSeparator(); - editorToolBar->addAction( objectsCreateTextAction ); - editorToolBar->addAction( objectsCreateBoxAction ); - editorToolBar->addAction( objectsCreateLineAction ); - editorToolBar->addAction( objectsCreateEllipseAction ); - editorToolBar->addAction( objectsCreateImageAction ); - editorToolBar->addAction( objectsCreateBarcodeAction ); - editorToolBar->addSeparator(); - editorToolBar->addAction( editCutAction ); - editorToolBar->addAction( editCopyAction ); - editorToolBar->addAction( editPasteAction ); - editorToolBar->addSeparator(); - editorToolBar->addAction( viewZoomInAction ); - editorToolBar->addAction( viewZoomOutAction ); - editorToolBar->addAction( viewZoom1To1Action ); - editorToolBar->addAction( viewZoomToFitAction ); - } - - - /// - /// Create Status Bar - /// - void MainWindow::createStatusBar() - { - zoomInfoLabel = new QLabel( " 999% " ); - zoomInfoLabel->setAlignment( Qt::AlignHCenter ); - zoomInfoLabel->setMinimumSize( zoomInfoLabel->sizeHint() ); - zoomInfoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); - - cursorInfoLabel = new QLabel; - cursorInfoLabel->setIndent( 3 ); - cursorInfoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); - - statusBar()->addWidget( zoomInfoLabel ); - statusBar()->addWidget( cursorInfoLabel, 1 ); - - onZoomChanged(); - onPointerExit(); - - connect( mView, SIGNAL(zoomChanged()), this, SLOT(onZoomChanged()) ); - connect( mView, SIGNAL(pointerMoved(double, double)), - this, SLOT(onPointerMoved(double, double)) ); - connect( mView, SIGNAL(pointerExited()), this, SLOT(onPointerExit()) ); - } - - - /// - /// Create Properties Page - /// - QWidget* MainWindow::createPropertiesPage() - { - mPropertiesView = new PropertiesView(); - - return mPropertiesView; - } - - - /// - /// Create Editor Page - /// - QWidget* MainWindow::createEditorPage() - { - QWidget* page = new QWidget; - - mViewScrollArea = new QScrollArea(); - mViewScrollArea->setMinimumSize( 640, 450 ); - mViewScrollArea->setWidgetResizable( true ); - - mView = new View( mViewScrollArea ); - mObjectEditor = new ObjectEditor(); - - mViewScrollArea->setWidget( mView ); - - QVBoxLayout* editorVLayout = new QVBoxLayout; - editorVLayout->addWidget( editorToolBar ); - editorVLayout->addWidget( mViewScrollArea ); - - QHBoxLayout* editorHLayout = new QHBoxLayout; - editorHLayout->addLayout( editorVLayout ); - editorHLayout->addWidget( mObjectEditor ); - - page->setLayout( editorHLayout ); - - return page; - } - - - /// - /// Create Merge Page - /// - QWidget* MainWindow::createMergePage() - { - mMergePropertyEditor = new MergePropertyEditor(); - - return mMergePropertyEditor; - } - - - /// - /// Create Print Page - /// - QWidget* MainWindow::createPrintPage() - { - mPrintView = new PrintView(); - - return mPrintView; - } - - - /// - /// Set enabled state of actions associated with a document. - /// - void MainWindow::setDocVerbsEnabled( bool enabled ) - { - filePropertiesAction->setEnabled( enabled ); - fileSaveAction->setEnabled( enabled ); - fileSaveAsAction->setEnabled( enabled ); - editUndoAction->setEnabled( enabled ); - editRedoAction->setEnabled( enabled ); - editCutAction->setEnabled( enabled ); - editCopyAction->setEnabled( enabled ); - editPasteAction->setEnabled( enabled ); - editDeleteAction->setEnabled( enabled ); - editSelectAllAction->setEnabled( enabled ); - editUnSelectAllAction->setEnabled( enabled ); - viewZoomInAction->setEnabled( enabled ); - viewZoomOutAction->setEnabled( enabled ); - viewZoom1To1Action->setEnabled( enabled ); - viewZoomToFitAction->setEnabled( enabled ); - viewGridAction->setEnabled( enabled ); - viewMarkupAction->setEnabled( enabled ); - objectsArrowModeAction->setEnabled( enabled ); - objectsCreateMenu->setEnabled( enabled ); - objectsCreateTextAction->setEnabled( enabled ); - objectsCreateLineAction->setEnabled( enabled ); - objectsCreateBoxAction->setEnabled( enabled ); - objectsCreateEllipseAction->setEnabled( enabled ); - objectsCreateImageAction->setEnabled( enabled ); - objectsCreateBarcodeAction->setEnabled( enabled ); - objectsOrderMenu->setEnabled( enabled ); - objectsOrderRaiseAction->setEnabled( enabled ); - objectsOrderLowerAction->setEnabled( enabled ); - objectsXformMenu->setEnabled( enabled ); - objectsXformRotateLeftAction->setEnabled( enabled ); - objectsXformRotateRightAction->setEnabled( enabled ); - objectsXformFlipHorizAction->setEnabled( enabled ); - objectsXformFlipVertAction->setEnabled( enabled ); - objectsAlignMenu->setEnabled( enabled ); - objectsAlignLeftAction->setEnabled( enabled ); - objectsAlignRightAction->setEnabled( enabled ); - objectsAlignHCenterAction->setEnabled( enabled ); - objectsAlignTopAction->setEnabled( enabled ); - objectsAlignBottomAction->setEnabled( enabled ); - objectsAlignVCenterAction->setEnabled( enabled ); - objectsCenterMenu->setEnabled( enabled ); - objectsCenterHorizAction->setEnabled( enabled ); - objectsCenterVertAction->setEnabled( enabled ); - } - - - /// - /// Set enabled state of actions associated with a document being modified since last save. - /// - void MainWindow::setDocModifiedVerbsEnabled( bool enabled ) - { - fileSaveAction->setEnabled( enabled ); - } - - - /// - /// Set enabled state of actions associated with data being available on clipboard. - /// - void MainWindow::setPasteVerbsEnabled( bool enabled ) - { - editPasteAction->setEnabled( enabled ); - } - - - /// - /// Set enabled state of actions associated with a non-empty selection. - /// - void MainWindow::setSelectionVerbsEnabled( bool enabled ) - { - editCutAction->setEnabled( enabled ); - editCopyAction->setEnabled( enabled ); - editDeleteAction->setEnabled( enabled ); - editUnSelectAllAction->setEnabled( enabled ); - objectsOrderMenu->setEnabled( enabled ); - objectsOrderRaiseAction->setEnabled( enabled ); - objectsOrderLowerAction->setEnabled( enabled ); - objectsXformMenu->setEnabled( enabled ); - objectsXformRotateLeftAction->setEnabled( enabled ); - objectsXformRotateRightAction->setEnabled( enabled ); - objectsXformFlipHorizAction->setEnabled( enabled ); - objectsXformFlipVertAction->setEnabled( enabled ); - objectsCenterMenu->setEnabled( enabled ); - objectsCenterHorizAction->setEnabled( enabled ); - objectsCenterVertAction->setEnabled( enabled ); - } - - - /// - /// Set enabled state of actions associated with a non-atomic selection. - /// - void MainWindow::setMultiSelectionVerbsEnabled( bool enabled ) - { - objectsAlignMenu->setEnabled( enabled ); - objectsAlignLeftAction->setEnabled( enabled ); - objectsAlignRightAction->setEnabled( enabled ); - objectsAlignHCenterAction->setEnabled( enabled ); - objectsAlignTopAction->setEnabled( enabled ); - objectsAlignBottomAction->setEnabled( enabled ); - objectsAlignVCenterAction->setEnabled( enabled ); - } - - - /// - /// Set window title - /// - void MainWindow::setTitle() - { - if ( mModel == 0 ) - { - setWindowTitle( "gLabels" ); - } - else - { - if ( mModel->isModified() ) - { - setWindowTitle( mModel->shortName() + " " + tr("(modified)") - + " - gLabels" ); - } - else - { - setWindowTitle( mModel->shortName() + " - gLabels" ); - } - } - } - - - /// - /// Read MainWindow Settings - /// - void MainWindow::readSettings() - { - QSettings settings; - - settings.beginGroup( "MainWindow" ); - bool showFileToolBar = settings.value( "showFileToolBar", true ).toBool(); - bool showEditorToolBar = settings.value( "showEditToolBar", true ).toBool(); - bool showGrid = settings.value( "showGrid", true ).toBool(); - bool showMarkup = settings.value( "showMarkup", true ).toBool(); - settings.endGroup(); - - viewFileToolBarAction ->setChecked( showFileToolBar ); - viewEditorToolBarAction ->setChecked( showEditorToolBar ); - viewGridAction ->setChecked( showGrid ); - viewMarkupAction ->setChecked( showMarkup ); - - fileToolBar ->setVisible( showFileToolBar ); - editorToolBar ->setVisible( showEditorToolBar ); - mView ->setGridVisible( showGrid ); - mView ->setMarkupVisible( showMarkup ); - } - - - /// - /// Write MainWindow Settings - /// - void MainWindow::writeSettings() - { - QSettings settings; - - settings.beginGroup( "MainWindow" ); - settings.setValue( "showFileToolBar", viewFileToolBarAction->isChecked() ); - settings.setValue( "showEditorToolBar", viewEditorToolBarAction->isChecked() ); - settings.setValue( "showGrid", viewGridAction->isChecked() ); - settings.setValue( "showMarkup", viewMarkupAction->isChecked() ); - settings.endGroup(); - } - - - /// - /// File->New Action - /// - void MainWindow::fileNew() - { - File::newLabel( this ); - } - - - /// - /// File->Open Action - /// - void MainWindow::fileOpen() - { - File::open( this ); - } - - - /// - /// File->Save Action - /// - void MainWindow::fileSave() - { - File::save( this ); - } - - - /// - /// File->Save As Action - /// - void MainWindow::fileSaveAs() - { - File::saveAs( this ); - } - - - /// - /// File->Properties Action - /// - void MainWindow::fileProperties() - { - qDebug() << "ACTION: file->Properties"; - } - - - /// - /// File->Template Designer Action - /// - void MainWindow::fileTemplateDesigner() - { - qDebug() << "ACTION: file->Template Designer"; - } - - - /// - /// File->Close Action - /// - void MainWindow::fileClose() - { - File::close( this ); - } - - - /// - /// File->Exit Action - /// - void MainWindow::fileExit() - { - File::exit(); - } - - - /// - /// Edit->Undo Action - /// - void MainWindow::editUndo() - { - qDebug() << "ACTION: edit->Undo"; - } - - - /// - /// Edit->Redo Action - /// - void MainWindow::editRedo() - { - qDebug() << "ACTION: edit->Redo"; - } - - - /// - /// Edit->Cut Action - /// - void MainWindow::editCut() - { - qDebug() << "ACTION: edit->Cut"; - } - - - /// - /// Edit->Copy Action - /// - void MainWindow::editCopy() - { - qDebug() << "ACTION: edit->Copy"; - } - - - /// - /// Edit->Paste Action - /// - void MainWindow::editPaste() - { - qDebug() << "ACTION: edit->Paste"; - } - - - /// - /// Edit->Delete Action - /// - void MainWindow::editDelete() - { - mModel->deleteSelection(); - } - - - /// - /// Edit->Select All Action - /// - void MainWindow::editSelectAll() - { - mModel->selectAll(); - } - - - /// - /// Edit->Unselect All Action - /// - void MainWindow::editUnSelectAll() - { - mModel->unselectAll(); - } - - - /// - /// Edit->Preferences Action - /// - void MainWindow::editPreferences() - { - qDebug() << "ACTION: edit->Preferences"; - } - - - /// - /// View->File Tool Bar Toggle Action - /// - void MainWindow::viewFileToolBar( bool state ) - { - fileToolBar->setVisible( state ); - } - - - /// - /// View->Objects Tool Bar Toggle Action - /// - void MainWindow::viewEditorToolBar( bool state ) - { - editorToolBar->setVisible( state ); - } - - - /// - /// View->Grid Toggle Action - /// - void MainWindow::viewGrid( bool state ) - { - mView->setGridVisible( state ); - } - - - /// - /// View->Markup Toggle Action - /// - void MainWindow::viewMarkup( bool state ) - { - mView->setMarkupVisible( state ); - } - - - /// - /// View->Zoom In Action - /// - void MainWindow::viewZoomIn() - { - mView->zoomIn(); - } - - - /// - /// View->Zoom Out Action - /// - void MainWindow::viewZoomOut() - { - mView->zoomOut(); - } - - - /// - /// View->Zoom 1:1 Action - /// - void MainWindow::viewZoom1To1() - { - mView->zoom1To1(); - } - - - /// - /// View->Zoom To Fit Action - /// - void MainWindow::viewZoomToFit() - { - mView->zoomToFit(); - } - - - /// - /// Objects->Arrow Mode Action - /// - void MainWindow::objectsArrowMode() - { - mView->arrowMode(); - } - - - /// - /// Objects->Create Text Mode Action - /// - void MainWindow::objectsCreateText() - { - qDebug() << "ACTION: objects->Create->Text"; - } - - - /// - /// Objects->Create Box Mode Action - /// - void MainWindow::objectsCreateBox() - { - mView->createBoxMode(); - } - - - /// - /// Objects->Create Line Mode Action - /// - void MainWindow::objectsCreateLine() - { - qDebug() << "ACTION: objects->Create->Line"; - } - - - /// - /// Objects->Create Ellipse Mode Action - /// - void MainWindow::objectsCreateEllipse() - { - qDebug() << "ACTION: objects->Create->Ellipse"; - } - - - /// - /// Objects->Create Image Mode Action - /// - void MainWindow::objectsCreateImage() - { - qDebug() << "ACTION: objects->Create->Image"; - } - - - /// - /// Objects->Create Barcode Mode Action - /// - void MainWindow::objectsCreateBarcode() - { - qDebug() << "ACTION: objects->Create->Barcode"; - } - - - /// - /// Objects->Order->Bring To Front Action - /// - void MainWindow::objectsOrderRaise() - { - mModel->raiseSelectionToTop(); - } - - - /// - /// Objects->Order->Send To Back Action - /// - void MainWindow::objectsOrderLower() - { - mModel->lowerSelectionToBottom(); - } - - - /// - /// Objects->Rotate/Flip->Rotate Left Action - /// - void MainWindow::objectsXformRotateLeft() - { - mModel->rotateSelectionLeft(); - } - - - /// - /// Objects->Rotate/Flip->Rotate Right Action - /// - void MainWindow::objectsXformRotateRight() - { - mModel->rotateSelectionRight(); - } - - - /// - /// Objects->Rotate/Flip->Flip Horizontally Action - /// - void MainWindow::objectsXformFlipHoriz() - { - mModel->flipSelectionHoriz(); - } - - - /// - /// Objects->Rotate/Flip->Flip Vertically Action - /// - void MainWindow::objectsXformFlipVert() - { - mModel->flipSelectionVert(); - } - - - /// - /// Objects->Align->Left Action - /// - void MainWindow::objectsAlignLeft() - { - mModel->alignSelectionLeft(); - } - - - /// - /// Objects->Align->Center Horizontally Action - /// - void MainWindow::objectsAlignHCenter() - { - mModel->alignSelectionHCenter(); - } - - - /// - /// Objects->Align->Right Action - /// - void MainWindow::objectsAlignRight() - { - mModel->alignSelectionRight(); - } - - - /// - /// Objects->Align->Top Action - /// - void MainWindow::objectsAlignTop() - { - mModel->alignSelectionTop(); - } - - - /// - /// Objects->Align->Center Vertically Action - /// - void MainWindow::objectsAlignVCenter() - { - mModel->alignSelectionVCenter(); - } - - - /// - /// Objects->Align->Bottom Action - /// - void MainWindow::objectsAlignBottom() - { - mModel->alignSelectionBottom(); - } - - - /// - /// Objects->Center->Horizontally Action - /// - void MainWindow::objectsCenterHoriz() - { - mModel->centerSelectionHoriz(); - } - - - /// - /// Objects->Center->Vertically Action - /// - void MainWindow::objectsCenterVert() - { - mModel->centerSelectionVert(); - } - - - /// - /// Help->Contents Action - /// - void MainWindow::helpContents() - { - Help::displayContents( this ); - } - - - /// - /// Help->About Action - /// - void MainWindow::helpAbout() - { - Help::displayAbout( this ); - } - - - /// - /// Context Menu Activation - /// - void MainWindow::onContextMenuActivate() - { - if ( mModel->isSelectionEmpty() ) - { - noSelectionContextMenu->popup( QCursor::pos() ); - } - else - { - contextMenu->popup( QCursor::pos() ); - } - } - - - /// - /// Zoom changed: update Zoom Information in Status Bar - /// - void MainWindow::onZoomChanged() - { - zoomInfoLabel->setText( QString( " %1% " ).arg(100*mView->zoom(), 0, 'f', 0) ); - - viewZoomInAction->setEnabled( !mView->isZoomMax() ); - viewZoomOutAction->setEnabled( !mView->isZoomMin() ); - } - - - /// - /// Pointer moved: update Cursor Information in Status Bar - /// - void MainWindow::onPointerMoved( double x, double y ) - { - /* TODO: convert x,y to locale units and set precision accordingly. */ - cursorInfoLabel->setText( QString( "%1, %2" ).arg(x).arg(y) ); - } - - - /// - /// Pointer exited view: update Zoom Information in Status Bar (Clears information) - /// - void MainWindow::onPointerExit() - { - cursorInfoLabel->setText( "" ); - } - - - /// - /// Name changed handler - /// - void MainWindow::onNameChanged() - { - setTitle(); - } - - - /// - /// Modified changed handler - /// - void MainWindow::onModifiedChanged() - { - setTitle(); - setDocModifiedVerbsEnabled( mModel->isModified() ); - } - - - /// - /// Selection changed handler - /// - void MainWindow::onSelectionChanged() - { - setSelectionVerbsEnabled( !mModel->isSelectionEmpty() ); - setMultiSelectionVerbsEnabled( !mModel->isSelectionAtomic() ); - } - - - /// - /// Label changed handler - /// - void MainWindow::onLabelChanged() - { - /* @TODO: update undo/redo verbs. */ - } + setDocVerbsEnabled( false ); + setPasteVerbsEnabled( false ); + setTitle(); + readSettings(); + smWindowList.push_back( this ); } + +/// +/// Destructor +/// +MainWindow::~MainWindow() +{ + smWindowList.removeOne( this ); +} + + +/// +/// Get model accessor +/// +LabelModel* MainWindow::model() const +{ + return mModel; +} + + +/// +/// Set model accessor +/// +void MainWindow::setModel( LabelModel *label ) +{ + mModel = label; + mPropertiesView->setModel( mModel ); + mView->setModel( mModel ); + mObjectEditor->setModel( mModel ); + mPrintView->setModel( mModel ); + + mNotebook->setEnabled( true ); + setDocVerbsEnabled( true ); + setSelectionVerbsEnabled( false ); + setMultiSelectionVerbsEnabled( false ); + setTitle(); + + connect( mView, SIGNAL(contextMenuActivate()), this, SLOT(onContextMenuActivate()) ); + connect( mModel, SIGNAL(nameChanged()), this, SLOT(onNameChanged()) ); + connect( mModel, SIGNAL(modifiedChanged()), this, SLOT(onModifiedChanged()) ); + connect( mModel, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()) ); + connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) ); +} + + +/// +/// Is window empty? +/// +bool MainWindow::isEmpty() const +{ + return mModel == 0; +} + +/// +/// Get window list +/// +QList MainWindow::windowList() +{ + return smWindowList; +} + + +/// +/// Close Event Handler +/// +void MainWindow::closeEvent( QCloseEvent *event ) +{ + writeSettings(); + event->accept(); +} + + +/// +/// Create Actions +/// +void MainWindow::createActions() +{ + /* File actions */ + fileNewAction = new QAction( tr("&New..."), this ); + fileNewAction->setIcon( QIcon::fromTheme( "document-new", Icons::Fallback::FileNew() ) ); + fileNewAction->setShortcut( QKeySequence::New ); + fileNewAction->setStatusTip( tr("Create a new file") ); + connect( fileNewAction, SIGNAL(triggered()), this, SLOT(fileNew()) ); + + fileOpenAction = new QAction( tr("&Open..."), this ); + fileOpenAction->setIcon( QIcon::fromTheme( "document-open", Icons::Fallback::FileOpen() ) ); + fileOpenAction->setShortcut( QKeySequence::Open ); + fileOpenAction->setStatusTip( tr("Open a file") ); + connect( fileOpenAction, SIGNAL(triggered()), this, SLOT(fileOpen()) ); + + fileSaveAction = new QAction( tr("&Save"), this ); + fileSaveAction->setIcon( QIcon::fromTheme( "document-save", Icons::Fallback::FileSave() ) ); + fileSaveAction->setShortcut( QKeySequence::Save ); + fileSaveAction->setStatusTip( tr("Save current file") ); + connect( fileSaveAction, SIGNAL(triggered()), this, SLOT(fileSave()) ); + + fileSaveAsAction = new QAction( tr("Save &As..."), this ); + fileSaveAsAction->setIcon( QIcon::fromTheme( "document-save-as", Icons::Fallback::FileSaveAs() ) ); + fileSaveAsAction->setShortcut( QKeySequence::SaveAs ); + fileSaveAsAction->setStatusTip( tr("Save current file to a different name") ); + connect( fileSaveAsAction, SIGNAL(triggered()), this, SLOT(fileSaveAs()) ); + + filePropertiesAction = new QAction( tr("Properties..."), this ); + filePropertiesAction->setIcon( QIcon::fromTheme( "document-properties" ) ); + filePropertiesAction->setStatusTip( tr("Modify document properties") ); + connect( filePropertiesAction, SIGNAL(triggered()), this, SLOT(fileProperties()) ); + + fileTemplateDesignerAction = new QAction( tr("Template &Designer..."), this ); + fileTemplateDesignerAction->setStatusTip( tr("Create custom templates") ); + connect( fileTemplateDesignerAction, SIGNAL(triggered()), this, SLOT(fileTemplateDesigner()) ); + + fileCloseAction = new QAction( tr("&Close"), this ); + fileCloseAction->setIcon( QIcon::fromTheme( "window-close" ) ); + fileCloseAction->setShortcut( QKeySequence::Close ); + fileCloseAction->setStatusTip( tr("Close the current window") ); + connect( fileCloseAction, SIGNAL(triggered()), this, SLOT(fileClose()) ); + + fileExitAction = new QAction( tr("E&xit"), this ); + fileExitAction->setIcon( QIcon::fromTheme( "application-exit" ) ); + fileExitAction->setShortcut( QKeySequence::Quit ); + fileExitAction->setStatusTip( tr("Exit glabels") ); + connect( fileExitAction, SIGNAL(triggered()), this, SLOT(fileExit()) ); + + + /* Edit actions */ + editUndoAction = new QAction( tr("Undo"), this ); + editUndoAction->setIcon( QIcon::fromTheme( "edit-undo" ) ); + editUndoAction->setShortcut( QKeySequence::Undo ); + editUndoAction->setStatusTip( tr("Undo") ); + connect( editUndoAction, SIGNAL(triggered()), this, SLOT(editUndo()) ); + + editRedoAction = new QAction( tr("Redo"), this ); + editRedoAction->setIcon( QIcon::fromTheme( "edit-redo" ) ); + editRedoAction->setShortcut( QKeySequence::Redo ); + editRedoAction->setStatusTip( tr("Redo") ); + connect( editRedoAction, SIGNAL(triggered()), this, SLOT(editRedo()) ); + + editCutAction = new QAction( tr("Cut"), this ); + editCutAction->setIcon( QIcon::fromTheme( "edit-cut", Icons::Fallback::EditCut() ) ); + editCutAction->setShortcut( QKeySequence::Cut ); + editCutAction->setStatusTip( tr("Cut the selection") ); + connect( editCutAction, SIGNAL(triggered()), this, SLOT(editCut()) ); + + editCopyAction = new QAction( tr("&Copy"), this ); + editCopyAction->setIcon( QIcon::fromTheme( "edit-copy", Icons::Fallback::EditCopy() ) ); + editCopyAction->setShortcut( QKeySequence::Copy ); + editCopyAction->setStatusTip( tr("Copy the selection") ); + connect( editCopyAction, SIGNAL(triggered()), this, SLOT(editCopy()) ); + + editPasteAction = new QAction( tr("&Paste"), this ); + editPasteAction->setIcon( QIcon::fromTheme( "edit-paste", Icons::Fallback::EditPaste() ) ); + editPasteAction->setShortcut( QKeySequence::Paste ); + editPasteAction->setStatusTip( tr("Paste the clipboard") ); + connect( editPasteAction, SIGNAL(triggered()), this, SLOT(editPaste()) ); + + editDeleteAction = new QAction( tr("&Delete"), this ); + editDeleteAction->setIcon( QIcon::fromTheme( "edit-delete" ) ); + editDeleteAction->setShortcut( QKeySequence::Delete ); + editDeleteAction->setStatusTip( tr("Delete the selected objects") ); + connect( editDeleteAction, SIGNAL(triggered()), this, SLOT(editDelete()) ); + + editSelectAllAction = new QAction( tr("Select &All"), this ); + editSelectAllAction->setIcon( QIcon::fromTheme( "edit-select-all" ) ); + editSelectAllAction->setShortcut( QKeySequence::SelectAll ); + editSelectAllAction->setStatusTip( tr("Select all objects") ); + connect( editSelectAllAction, SIGNAL(triggered()), this, SLOT(editSelectAll()) ); + + editUnSelectAllAction = new QAction( tr("Un-select All"), this ); + editUnSelectAllAction->setIcon( QIcon::fromTheme( "edit-unselect-all" ) ); + editUnSelectAllAction->setStatusTip( tr("Remove all selections") ); + connect( editUnSelectAllAction, SIGNAL(triggered()), this, SLOT(editUnSelectAll()) ); + + editPreferencesAction = new QAction( tr("Preferences"), this ); + editPreferencesAction->setIcon( QIcon::fromTheme( "edit-preferences" ) ); + editPreferencesAction->setShortcut( QKeySequence::Preferences ); + editPreferencesAction->setStatusTip( tr("Configure the application") ); + connect( editPreferencesAction, SIGNAL(triggered()), this, SLOT(editPreferences()) ); + + + /* View actions */ + viewFileToolBarAction = new QAction( tr("File"), this ); + viewFileToolBarAction->setCheckable( true ); + viewFileToolBarAction->setStatusTip( tr("Change visibility of file toolbar in current window") ); + connect( viewFileToolBarAction, SIGNAL(toggled(bool)), this, SLOT(viewFileToolBar(bool)) ); + + viewEditorToolBarAction = new QAction( tr("Editor"), this ); + viewEditorToolBarAction->setCheckable( true ); + viewEditorToolBarAction->setStatusTip( tr("Change visibility of editor toolbar in current window") ); + connect( viewEditorToolBarAction, SIGNAL(toggled(bool)), this, SLOT(viewEditorToolBar(bool)) ); + + + viewGridAction = new QAction( tr("Grid"), this ); + viewGridAction->setCheckable( true ); + viewGridAction->setStatusTip( tr("Change visibility of the grid in current window") ); + connect( viewGridAction, SIGNAL(toggled(bool)), this, SLOT(viewGrid(bool)) ); + + viewMarkupAction = new QAction( tr("Markup"), this ); + viewMarkupAction->setCheckable( true ); + viewMarkupAction->setStatusTip( tr("Change visibility of markup lines in current window") ); + connect( viewMarkupAction, SIGNAL(toggled(bool)), this, SLOT(viewMarkup(bool)) ); + + viewZoomInAction = new QAction( tr("Zoom &In"), this ); + viewZoomInAction->setIcon( QIcon::fromTheme( "zoom-in", Icons::Fallback::ZoomIn() ) ); + viewZoomInAction->setShortcut( QKeySequence::ZoomIn ); + viewZoomInAction->setStatusTip( tr("Increase magnification") ); + connect( viewZoomInAction, SIGNAL(triggered()), this, SLOT(viewZoomIn()) ); + + viewZoomOutAction = new QAction( tr("Zoom &Out"), this ); + viewZoomOutAction->setIcon( QIcon::fromTheme( "zoom-out", Icons::Fallback::ZoomOut() ) ); + viewZoomOutAction->setShortcut( QKeySequence::ZoomOut ); + viewZoomOutAction->setStatusTip( tr("Decrease magnification") ); + connect( viewZoomOutAction, SIGNAL(triggered()), this, SLOT(viewZoomOut()) ); + + viewZoom1To1Action = new QAction( tr("Zoom &1 to 1"), this ); + viewZoom1To1Action->setIcon( QIcon::fromTheme( "zoom-original", Icons::Fallback::ZoomOriginal() ) ); + viewZoom1To1Action->setStatusTip( tr("Restore scale to 100%") ); + connect( viewZoom1To1Action, SIGNAL(triggered()), this, SLOT(viewZoom1To1()) ); + + viewZoomToFitAction = new QAction( tr("Zoom to &Fit"), this ); + viewZoomToFitAction->setIcon( QIcon::fromTheme( "zoom-fit-best", Icons::Fallback::ZoomBestFit() ) ); + viewZoomToFitAction->setStatusTip( tr("Set scale to fit window") ); + connect( viewZoomToFitAction, SIGNAL(triggered()), this, SLOT(viewZoomToFit()) ); + + + /* Object actions */ + objectsArrowModeAction = new QAction( tr("Select Mode"), this ); + objectsArrowModeAction->setIcon( Icons::Arrow() ); + objectsArrowModeAction->setStatusTip( tr("Select, move and modify objects") ); + connect( objectsArrowModeAction, SIGNAL(triggered()), this, SLOT(objectsArrowMode()) ); + + objectsCreateTextAction = new QAction( tr("Text"), this ); + objectsCreateTextAction->setIcon( Icons::Text() ); + objectsCreateTextAction->setStatusTip( tr("Create text object") ); + connect( objectsCreateTextAction, SIGNAL(triggered()), this, SLOT(objectsCreateText()) ); + + objectsCreateBoxAction = new QAction( tr("Box"), this ); + objectsCreateBoxAction->setIcon( Icons::Box() ); + objectsCreateBoxAction->setStatusTip( tr("Create box object") ); + connect( objectsCreateBoxAction, SIGNAL(triggered()), this, SLOT(objectsCreateBox()) ); + + objectsCreateLineAction = new QAction( tr("Line"), this ); + objectsCreateLineAction->setIcon( Icons::Line() ); + objectsCreateLineAction->setStatusTip( tr("Create line object") ); + connect( objectsCreateLineAction, SIGNAL(triggered()), this, SLOT(objectsCreateLine()) ); + + objectsCreateEllipseAction = new QAction( tr("Ellipse"), this ); + objectsCreateEllipseAction->setIcon( Icons::Ellipse() ); + objectsCreateEllipseAction->setStatusTip( tr("Create ellipse/circle object") ); + connect( objectsCreateEllipseAction, SIGNAL(triggered()), this, SLOT(objectsCreateEllipse()) ); + + objectsCreateImageAction = new QAction( tr("Image"), this ); + objectsCreateImageAction->setIcon( Icons::Image() ); + objectsCreateImageAction->setStatusTip( tr("Create image object") ); + connect( objectsCreateImageAction, SIGNAL(triggered()), this, SLOT(objectsCreateImage()) ); + + objectsCreateBarcodeAction = new QAction( tr("Barcode"), this ); + objectsCreateBarcodeAction->setIcon( Icons::Barcode() ); + objectsCreateBarcodeAction->setStatusTip( tr("Create barcode object") ); + connect( objectsCreateBarcodeAction, SIGNAL(triggered()), this, SLOT(objectsCreateBarcode()) ); + + objectsOrderRaiseAction = new QAction( tr("Bring To Front"), this ); + objectsOrderRaiseAction->setIcon( Icons::OrderTop() ); + objectsOrderRaiseAction->setStatusTip( tr("Raise selection to top") ); + connect( objectsOrderRaiseAction, SIGNAL(triggered()), this, SLOT(objectsOrderRaise()) ); + + objectsOrderLowerAction = new QAction( tr("Send To Back"), this ); + objectsOrderLowerAction->setIcon( Icons::OrderBottom() ); + objectsOrderLowerAction->setStatusTip( tr("Lower selection to bottom") ); + connect( objectsOrderLowerAction, SIGNAL(triggered()), this, SLOT(objectsOrderLower()) ); + + objectsXformRotateLeftAction = new QAction( tr("Rotate Left"), this ); + objectsXformRotateLeftAction->setIcon( Icons::RotateLeft() ); + objectsXformRotateLeftAction->setStatusTip( tr("Rotate object(s) 90 degrees counter-clockwise") ); + connect( objectsXformRotateLeftAction, SIGNAL(triggered()), this, SLOT(objectsXformRotateLeft()) ); + + objectsXformRotateRightAction = new QAction( tr("Rotate Right"), this ); + objectsXformRotateRightAction->setIcon( Icons::RotateRight() ); + objectsXformRotateRightAction->setStatusTip( tr("Rotate object(s) 90 degrees clockwise") ); + connect( objectsXformRotateRightAction, SIGNAL(triggered()), this, SLOT(objectsXformRotateRight()) ); + + objectsXformFlipHorizAction = new QAction( tr("Flip Horizontally"), this ); + objectsXformFlipHorizAction->setIcon( Icons::FlipHoriz() ); + objectsXformFlipHorizAction->setStatusTip( tr("Flip object(s) horizontally") ); + connect( objectsXformFlipHorizAction, SIGNAL(triggered()), this, SLOT(objectsXformFlipHoriz()) ); + + objectsXformFlipVertAction = new QAction( tr("Flip Vertically"), this ); + objectsXformFlipVertAction->setIcon( Icons::FlipVert() ); + objectsXformFlipVertAction->setStatusTip( tr("Flip object(s) vertically") ); + connect( objectsXformFlipVertAction, SIGNAL(triggered()), this, SLOT(objectsXformFlipVert()) ); + + objectsAlignLeftAction = new QAction( tr("Align Left"), this ); + objectsAlignLeftAction->setIcon( Icons::AlignLeft() ); + objectsAlignLeftAction->setStatusTip( tr("Align objects to left edges") ); + connect( objectsAlignLeftAction, SIGNAL(triggered()), this, SLOT(objectsAlignLeft()) ); + + objectsAlignHCenterAction = new QAction( tr("Align Center"), this ); + objectsAlignHCenterAction->setIcon( Icons::AlignHCenter() ); + objectsAlignHCenterAction->setStatusTip( tr("Align objects to horizontal centers") ); + connect( objectsAlignHCenterAction, SIGNAL(triggered()), this, SLOT(objectsAlignHCenter()) ); + + objectsAlignRightAction = new QAction( tr("Align Right"), this ); + objectsAlignRightAction->setIcon( Icons::AlignRight() ); + objectsAlignRightAction->setStatusTip( tr("Align objects to right edges") ); + connect( objectsAlignRightAction, SIGNAL(triggered()), this, SLOT(objectsAlignRight()) ); + + objectsAlignTopAction = new QAction( tr("Align Top"), this ); + objectsAlignTopAction->setIcon( Icons::AlignTop() ); + objectsAlignTopAction->setStatusTip( tr("Align objects to top edges") ); + connect( objectsAlignTopAction, SIGNAL(triggered()), this, SLOT(objectsAlignTop()) ); + + objectsAlignVCenterAction = new QAction( tr("Align Middle"), this ); + objectsAlignVCenterAction->setIcon( Icons::AlignVCenter() ); + objectsAlignVCenterAction->setStatusTip( tr("Align objects to vertical centers") ); + connect( objectsAlignVCenterAction, SIGNAL(triggered()), this, SLOT(objectsAlignVCenter()) ); + + objectsAlignBottomAction = new QAction( tr("Align Bottom"), this ); + objectsAlignBottomAction->setIcon( Icons::AlignBottom() ); + objectsAlignBottomAction->setStatusTip( tr("Align objects to bottom edges") ); + connect( objectsAlignBottomAction, SIGNAL(triggered()), this, SLOT(objectsAlignBottom()) ); + + objectsCenterHorizAction = new QAction( tr("Center Horizontally"), this ); + objectsCenterHorizAction->setIcon( Icons::CenterHoriz() ); + objectsCenterHorizAction->setStatusTip( tr("Horizontally center objects in label") ); + connect( objectsCenterHorizAction, SIGNAL(triggered()), this, SLOT(objectsCenterHoriz()) ); + + objectsCenterVertAction = new QAction( tr("Center Vertically"), this ); + objectsCenterVertAction->setIcon( Icons::CenterVert() ); + objectsCenterVertAction->setStatusTip( tr("Vertically center objects in label") ); + connect( objectsCenterVertAction, SIGNAL(triggered()), this, SLOT(objectsCenterVert()) ); + + + /* Help actions */ + helpContentsAction = new QAction( tr("&Contents..."), this ); + helpContentsAction->setIcon( QIcon::fromTheme( "help-contents" ) ); + helpContentsAction->setShortcut( QKeySequence::HelpContents ); + helpContentsAction->setStatusTip( tr("Open gLabels manual") ); + connect( helpContentsAction, SIGNAL(triggered()), this, SLOT(helpContents()) ); + + helpAboutAction = new QAction( tr("&About..."), this ); + helpAboutAction->setIcon( QIcon::fromTheme( "help-about" ) ); + helpAboutAction->setStatusTip( tr("About gLabels") ); + connect( helpAboutAction, SIGNAL(triggered()), this, SLOT(helpAbout()) ); + + + /* Context menu version of edit actions */ + contextCutAction = new QAction( tr("Cut"), this ); + contextCutAction->setIcon( QIcon::fromTheme( "edit-cut", Icons::Fallback::EditCut() ) ); + contextCutAction->setStatusTip( tr("Cut the selection") ); + connect( contextCutAction, SIGNAL(triggered()), this, SLOT(editCut()) ); + + contextCopyAction = new QAction( tr("&Copy"), this ); + contextCopyAction->setIcon( QIcon::fromTheme( "edit-copy", Icons::Fallback::EditCopy() ) ); + contextCopyAction->setStatusTip( tr("Copy the selection") ); + connect( contextCopyAction, SIGNAL(triggered()), this, SLOT(editCopy()) ); + + contextPasteAction = new QAction( tr("&Paste"), this ); + contextPasteAction->setIcon( QIcon::fromTheme( "edit-paste", Icons::Fallback::EditPaste() ) ); + contextPasteAction->setStatusTip( tr("Paste the clipboard") ); + connect( contextPasteAction, SIGNAL(triggered()), this, SLOT(editPaste()) ); + + contextDeleteAction = new QAction( tr("&Delete"), this ); + contextDeleteAction->setIcon( QIcon::fromTheme( "edit-delete" ) ); + contextDeleteAction->setStatusTip( tr("Delete the selected objects") ); + connect( contextDeleteAction, SIGNAL(triggered()), this, SLOT(editDelete()) ); +} + + +/// +/// Create Menus +/// +void MainWindow::createMenus() +{ + fileMenu = menuBar()->addMenu( tr("&File") ); + fileMenu->addAction( fileNewAction ); + fileMenu->addAction( fileOpenAction ); + fileMenu->addAction( fileSaveAction ); + fileMenu->addAction( fileSaveAsAction ); + fileMenu->addSeparator(); + fileMenu->addAction( filePropertiesAction ); + fileMenu->addAction( fileTemplateDesignerAction ); + fileMenu->addSeparator(); + fileMenu->addAction( fileCloseAction ); + fileMenu->addAction( fileExitAction ); + + editMenu = menuBar()->addMenu( tr("&Edit") ); + editMenu->addAction( editUndoAction ); + editMenu->addAction( editRedoAction ); + editMenu->addSeparator(); + editMenu->addAction( editCutAction ); + editMenu->addAction( editCopyAction ); + editMenu->addAction( editPasteAction ); + editMenu->addAction( editDeleteAction ); + editMenu->addSeparator(); + editMenu->addAction( editSelectAllAction ); + editMenu->addAction( editUnSelectAllAction ); + editMenu->addSeparator(); + editMenu->addAction( editPreferencesAction ); + + viewMenu = menuBar()->addMenu( tr("&View") ); + viewToolBarsMenu = viewMenu->addMenu( tr("Toolbars") ); + viewToolBarsMenu->addAction( viewFileToolBarAction ); + viewToolBarsMenu->addAction( viewEditorToolBarAction ); + viewMenu->addSeparator(); + viewMenu->addAction( viewGridAction ); + viewMenu->addAction( viewMarkupAction ); + viewMenu->addSeparator(); + viewMenu->addAction( viewZoomInAction ); + viewMenu->addAction( viewZoomOutAction ); + viewMenu->addAction( viewZoom1To1Action ); + viewMenu->addAction( viewZoomToFitAction ); + + objectsMenu = menuBar()->addMenu( tr("&Objects") ); + objectsMenu->addAction( objectsArrowModeAction ); + objectsCreateMenu = objectsMenu->addMenu( tr("&Create") ); + objectsCreateMenu->addAction( objectsCreateTextAction ); + objectsCreateMenu->addAction( objectsCreateBoxAction ); + objectsCreateMenu->addAction( objectsCreateLineAction ); + objectsCreateMenu->addAction( objectsCreateEllipseAction ); + objectsCreateMenu->addAction( objectsCreateImageAction ); + objectsCreateMenu->addAction( objectsCreateBarcodeAction ); + objectsMenu->addSeparator(); + objectsOrderMenu = objectsMenu->addMenu( tr("&Order") ); + objectsOrderMenu->addAction( objectsOrderRaiseAction ); + objectsOrderMenu->addAction( objectsOrderLowerAction ); + objectsXformMenu = objectsMenu->addMenu( tr("&Rotate/Flip") ); + objectsXformMenu->addAction( objectsXformRotateLeftAction ); + objectsXformMenu->addAction( objectsXformRotateRightAction ); + objectsXformMenu->addAction( objectsXformFlipHorizAction ); + objectsXformMenu->addAction( objectsXformFlipVertAction ); + objectsAlignMenu = objectsMenu->addMenu( tr("&Alignment") ); + objectsAlignMenu->addAction( objectsAlignLeftAction ); + objectsAlignMenu->addAction( objectsAlignHCenterAction ); + objectsAlignMenu->addAction( objectsAlignRightAction ); + objectsAlignMenu->addSeparator(); + objectsAlignMenu->addAction( objectsAlignTopAction ); + objectsAlignMenu->addAction( objectsAlignVCenterAction ); + objectsAlignMenu->addAction( objectsAlignBottomAction ); + objectsCenterMenu = objectsMenu->addMenu( tr("Center") ); + objectsCenterMenu->addAction( objectsCenterHorizAction ); + objectsCenterMenu->addAction( objectsCenterVertAction ); + + helpMenu = menuBar()->addMenu( tr("&Help") ); + helpMenu->addAction( helpContentsAction ); + helpMenu->addAction( helpAboutAction ); + + contextMenu = new QMenu(); + contextOrderMenu = contextMenu->addMenu( tr("&Order") ); + contextOrderMenu->addAction( objectsOrderRaiseAction ); + contextOrderMenu->addAction( objectsOrderLowerAction ); + contextXformMenu = contextMenu->addMenu( tr("&Rotate/Flip") ); + contextXformMenu->addAction( objectsXformRotateLeftAction ); + contextXformMenu->addAction( objectsXformRotateRightAction ); + contextXformMenu->addAction( objectsXformFlipHorizAction ); + contextXformMenu->addAction( objectsXformFlipVertAction ); + contextAlignMenu = contextMenu->addMenu( tr("&Alignment") ); + contextAlignMenu->addAction( objectsAlignLeftAction ); + contextAlignMenu->addAction( objectsAlignHCenterAction ); + contextAlignMenu->addAction( objectsAlignRightAction ); + contextAlignMenu->addSeparator(); + contextAlignMenu->addAction( objectsAlignTopAction ); + contextAlignMenu->addAction( objectsAlignVCenterAction ); + contextAlignMenu->addAction( objectsAlignBottomAction ); + contextCenterMenu = contextMenu->addMenu( tr("Center") ); + contextCenterMenu->addAction( objectsCenterHorizAction ); + contextCenterMenu->addAction( objectsCenterVertAction ); + contextMenu->addSeparator(); + contextMenu->addAction( contextCutAction ); + contextMenu->addAction( contextCopyAction ); + contextMenu->addAction( contextPasteAction ); + contextMenu->addAction( contextDeleteAction ); + + noSelectionContextMenu = new QMenu(); + noSelectionContextMenu->addAction( contextPasteAction ); +} + + +/// +/// Create Tool Bars +/// +void MainWindow::createToolBars() +{ + fileToolBar = addToolBar( tr("&File") ); + fileToolBar->addAction( fileNewAction ); + fileToolBar->addAction( fileOpenAction ); + fileToolBar->addAction( fileSaveAction ); + + editorToolBar = new QToolBar( tr("&Editor") ); + editorToolBar->addAction( objectsArrowModeAction ); + editorToolBar->addSeparator(); + editorToolBar->addAction( objectsCreateTextAction ); + editorToolBar->addAction( objectsCreateBoxAction ); + editorToolBar->addAction( objectsCreateLineAction ); + editorToolBar->addAction( objectsCreateEllipseAction ); + editorToolBar->addAction( objectsCreateImageAction ); + editorToolBar->addAction( objectsCreateBarcodeAction ); + editorToolBar->addSeparator(); + editorToolBar->addAction( editCutAction ); + editorToolBar->addAction( editCopyAction ); + editorToolBar->addAction( editPasteAction ); + editorToolBar->addSeparator(); + editorToolBar->addAction( viewZoomInAction ); + editorToolBar->addAction( viewZoomOutAction ); + editorToolBar->addAction( viewZoom1To1Action ); + editorToolBar->addAction( viewZoomToFitAction ); +} + + +/// +/// Create Status Bar +/// +void MainWindow::createStatusBar() +{ + zoomInfoLabel = new QLabel( " 999% " ); + zoomInfoLabel->setAlignment( Qt::AlignHCenter ); + zoomInfoLabel->setMinimumSize( zoomInfoLabel->sizeHint() ); + zoomInfoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + + cursorInfoLabel = new QLabel; + cursorInfoLabel->setIndent( 3 ); + cursorInfoLabel->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + + statusBar()->addWidget( zoomInfoLabel ); + statusBar()->addWidget( cursorInfoLabel, 1 ); + + onZoomChanged(); + onPointerExit(); + + connect( mView, SIGNAL(zoomChanged()), this, SLOT(onZoomChanged()) ); + connect( mView, SIGNAL(pointerMoved(double, double)), + this, SLOT(onPointerMoved(double, double)) ); + connect( mView, SIGNAL(pointerExited()), this, SLOT(onPointerExit()) ); +} + + +/// +/// Create Properties Page +/// +QWidget* MainWindow::createPropertiesPage() +{ + mPropertiesView = new PropertiesView(); + + return mPropertiesView; +} + + +/// +/// Create Editor Page +/// +QWidget* MainWindow::createEditorPage() +{ + QWidget* page = new QWidget; + + mViewScrollArea = new QScrollArea(); + mViewScrollArea->setMinimumSize( 640, 450 ); + mViewScrollArea->setWidgetResizable( true ); + + mView = new View( mViewScrollArea ); + mObjectEditor = new ObjectEditor(); + + mViewScrollArea->setWidget( mView ); + + QVBoxLayout* editorVLayout = new QVBoxLayout; + editorVLayout->addWidget( editorToolBar ); + editorVLayout->addWidget( mViewScrollArea ); + + QHBoxLayout* editorHLayout = new QHBoxLayout; + editorHLayout->addLayout( editorVLayout ); + editorHLayout->addWidget( mObjectEditor ); + + page->setLayout( editorHLayout ); + + return page; +} + + +/// +/// Create Merge Page +/// +QWidget* MainWindow::createMergePage() +{ + mMergePropertyEditor = new MergePropertyEditor(); + + return mMergePropertyEditor; +} + + +/// +/// Create Print Page +/// +QWidget* MainWindow::createPrintPage() +{ + mPrintView = new PrintView(); + + return mPrintView; +} + + +/// +/// Set enabled state of actions associated with a document. +/// +void MainWindow::setDocVerbsEnabled( bool enabled ) +{ + filePropertiesAction->setEnabled( enabled ); + fileSaveAction->setEnabled( enabled ); + fileSaveAsAction->setEnabled( enabled ); + editUndoAction->setEnabled( enabled ); + editRedoAction->setEnabled( enabled ); + editCutAction->setEnabled( enabled ); + editCopyAction->setEnabled( enabled ); + editPasteAction->setEnabled( enabled ); + editDeleteAction->setEnabled( enabled ); + editSelectAllAction->setEnabled( enabled ); + editUnSelectAllAction->setEnabled( enabled ); + viewZoomInAction->setEnabled( enabled ); + viewZoomOutAction->setEnabled( enabled ); + viewZoom1To1Action->setEnabled( enabled ); + viewZoomToFitAction->setEnabled( enabled ); + viewGridAction->setEnabled( enabled ); + viewMarkupAction->setEnabled( enabled ); + objectsArrowModeAction->setEnabled( enabled ); + objectsCreateMenu->setEnabled( enabled ); + objectsCreateTextAction->setEnabled( enabled ); + objectsCreateLineAction->setEnabled( enabled ); + objectsCreateBoxAction->setEnabled( enabled ); + objectsCreateEllipseAction->setEnabled( enabled ); + objectsCreateImageAction->setEnabled( enabled ); + objectsCreateBarcodeAction->setEnabled( enabled ); + objectsOrderMenu->setEnabled( enabled ); + objectsOrderRaiseAction->setEnabled( enabled ); + objectsOrderLowerAction->setEnabled( enabled ); + objectsXformMenu->setEnabled( enabled ); + objectsXformRotateLeftAction->setEnabled( enabled ); + objectsXformRotateRightAction->setEnabled( enabled ); + objectsXformFlipHorizAction->setEnabled( enabled ); + objectsXformFlipVertAction->setEnabled( enabled ); + objectsAlignMenu->setEnabled( enabled ); + objectsAlignLeftAction->setEnabled( enabled ); + objectsAlignRightAction->setEnabled( enabled ); + objectsAlignHCenterAction->setEnabled( enabled ); + objectsAlignTopAction->setEnabled( enabled ); + objectsAlignBottomAction->setEnabled( enabled ); + objectsAlignVCenterAction->setEnabled( enabled ); + objectsCenterMenu->setEnabled( enabled ); + objectsCenterHorizAction->setEnabled( enabled ); + objectsCenterVertAction->setEnabled( enabled ); +} + + +/// +/// Set enabled state of actions associated with a document being modified since last save. +/// +void MainWindow::setDocModifiedVerbsEnabled( bool enabled ) +{ + fileSaveAction->setEnabled( enabled ); +} + + +/// +/// Set enabled state of actions associated with data being available on clipboard. +/// +void MainWindow::setPasteVerbsEnabled( bool enabled ) +{ + editPasteAction->setEnabled( enabled ); +} + + +/// +/// Set enabled state of actions associated with a non-empty selection. +/// +void MainWindow::setSelectionVerbsEnabled( bool enabled ) +{ + editCutAction->setEnabled( enabled ); + editCopyAction->setEnabled( enabled ); + editDeleteAction->setEnabled( enabled ); + editUnSelectAllAction->setEnabled( enabled ); + objectsOrderMenu->setEnabled( enabled ); + objectsOrderRaiseAction->setEnabled( enabled ); + objectsOrderLowerAction->setEnabled( enabled ); + objectsXformMenu->setEnabled( enabled ); + objectsXformRotateLeftAction->setEnabled( enabled ); + objectsXformRotateRightAction->setEnabled( enabled ); + objectsXformFlipHorizAction->setEnabled( enabled ); + objectsXformFlipVertAction->setEnabled( enabled ); + objectsCenterMenu->setEnabled( enabled ); + objectsCenterHorizAction->setEnabled( enabled ); + objectsCenterVertAction->setEnabled( enabled ); +} + + +/// +/// Set enabled state of actions associated with a non-atomic selection. +/// +void MainWindow::setMultiSelectionVerbsEnabled( bool enabled ) +{ + objectsAlignMenu->setEnabled( enabled ); + objectsAlignLeftAction->setEnabled( enabled ); + objectsAlignRightAction->setEnabled( enabled ); + objectsAlignHCenterAction->setEnabled( enabled ); + objectsAlignTopAction->setEnabled( enabled ); + objectsAlignBottomAction->setEnabled( enabled ); + objectsAlignVCenterAction->setEnabled( enabled ); +} + + +/// +/// Set window title +/// +void MainWindow::setTitle() +{ + if ( mModel == 0 ) + { + setWindowTitle( "gLabels" ); + } + else + { + if ( mModel->isModified() ) + { + setWindowTitle( mModel->shortName() + " " + tr("(modified)") + + " - gLabels" ); + } + else + { + setWindowTitle( mModel->shortName() + " - gLabels" ); + } + } +} + + +/// +/// Read MainWindow Settings +/// +void MainWindow::readSettings() +{ + QSettings settings; + + settings.beginGroup( "MainWindow" ); + bool showFileToolBar = settings.value( "showFileToolBar", true ).toBool(); + bool showEditorToolBar = settings.value( "showEditToolBar", true ).toBool(); + bool showGrid = settings.value( "showGrid", true ).toBool(); + bool showMarkup = settings.value( "showMarkup", true ).toBool(); + settings.endGroup(); + + viewFileToolBarAction ->setChecked( showFileToolBar ); + viewEditorToolBarAction ->setChecked( showEditorToolBar ); + viewGridAction ->setChecked( showGrid ); + viewMarkupAction ->setChecked( showMarkup ); + + fileToolBar ->setVisible( showFileToolBar ); + editorToolBar ->setVisible( showEditorToolBar ); + mView ->setGridVisible( showGrid ); + mView ->setMarkupVisible( showMarkup ); +} + + +/// +/// Write MainWindow Settings +/// +void MainWindow::writeSettings() +{ + QSettings settings; + + settings.beginGroup( "MainWindow" ); + settings.setValue( "showFileToolBar", viewFileToolBarAction->isChecked() ); + settings.setValue( "showEditorToolBar", viewEditorToolBarAction->isChecked() ); + settings.setValue( "showGrid", viewGridAction->isChecked() ); + settings.setValue( "showMarkup", viewMarkupAction->isChecked() ); + settings.endGroup(); +} + + +/// +/// File->New Action +/// +void MainWindow::fileNew() +{ + File::newLabel( this ); +} + + +/// +/// File->Open Action +/// +void MainWindow::fileOpen() +{ + File::open( this ); +} + + +/// +/// File->Save Action +/// +void MainWindow::fileSave() +{ + File::save( this ); +} + + +/// +/// File->Save As Action +/// +void MainWindow::fileSaveAs() +{ + File::saveAs( this ); +} + + +/// +/// File->Properties Action +/// +void MainWindow::fileProperties() +{ + qDebug() << "ACTION: file->Properties"; +} + + +/// +/// File->Template Designer Action +/// +void MainWindow::fileTemplateDesigner() +{ + qDebug() << "ACTION: file->Template Designer"; +} + + +/// +/// File->Close Action +/// +void MainWindow::fileClose() +{ + File::close( this ); +} + + +/// +/// File->Exit Action +/// +void MainWindow::fileExit() +{ + File::exit(); +} + + +/// +/// Edit->Undo Action +/// +void MainWindow::editUndo() +{ + qDebug() << "ACTION: edit->Undo"; +} + + +/// +/// Edit->Redo Action +/// +void MainWindow::editRedo() +{ + qDebug() << "ACTION: edit->Redo"; +} + + +/// +/// Edit->Cut Action +/// +void MainWindow::editCut() +{ + qDebug() << "ACTION: edit->Cut"; +} + + +/// +/// Edit->Copy Action +/// +void MainWindow::editCopy() +{ + qDebug() << "ACTION: edit->Copy"; +} + + +/// +/// Edit->Paste Action +/// +void MainWindow::editPaste() +{ + qDebug() << "ACTION: edit->Paste"; +} + + +/// +/// Edit->Delete Action +/// +void MainWindow::editDelete() +{ + mModel->deleteSelection(); +} + + +/// +/// Edit->Select All Action +/// +void MainWindow::editSelectAll() +{ + mModel->selectAll(); +} + + +/// +/// Edit->Unselect All Action +/// +void MainWindow::editUnSelectAll() +{ + mModel->unselectAll(); +} + + +/// +/// Edit->Preferences Action +/// +void MainWindow::editPreferences() +{ + qDebug() << "ACTION: edit->Preferences"; +} + + +/// +/// View->File Tool Bar Toggle Action +/// +void MainWindow::viewFileToolBar( bool state ) +{ + fileToolBar->setVisible( state ); +} + + +/// +/// View->Objects Tool Bar Toggle Action +/// +void MainWindow::viewEditorToolBar( bool state ) +{ + editorToolBar->setVisible( state ); +} + + +/// +/// View->Grid Toggle Action +/// +void MainWindow::viewGrid( bool state ) +{ + mView->setGridVisible( state ); +} + + +/// +/// View->Markup Toggle Action +/// +void MainWindow::viewMarkup( bool state ) +{ + mView->setMarkupVisible( state ); +} + + +/// +/// View->Zoom In Action +/// +void MainWindow::viewZoomIn() +{ + mView->zoomIn(); +} + + +/// +/// View->Zoom Out Action +/// +void MainWindow::viewZoomOut() +{ + mView->zoomOut(); +} + + +/// +/// View->Zoom 1:1 Action +/// +void MainWindow::viewZoom1To1() +{ + mView->zoom1To1(); +} + + +/// +/// View->Zoom To Fit Action +/// +void MainWindow::viewZoomToFit() +{ + mView->zoomToFit(); +} + + +/// +/// Objects->Arrow Mode Action +/// +void MainWindow::objectsArrowMode() +{ + mView->arrowMode(); +} + + +/// +/// Objects->Create Text Mode Action +/// +void MainWindow::objectsCreateText() +{ + qDebug() << "ACTION: objects->Create->Text"; +} + + +/// +/// Objects->Create Box Mode Action +/// +void MainWindow::objectsCreateBox() +{ + mView->createBoxMode(); +} + + +/// +/// Objects->Create Line Mode Action +/// +void MainWindow::objectsCreateLine() +{ + qDebug() << "ACTION: objects->Create->Line"; +} + + +/// +/// Objects->Create Ellipse Mode Action +/// +void MainWindow::objectsCreateEllipse() +{ + qDebug() << "ACTION: objects->Create->Ellipse"; +} + + +/// +/// Objects->Create Image Mode Action +/// +void MainWindow::objectsCreateImage() +{ + qDebug() << "ACTION: objects->Create->Image"; +} + + +/// +/// Objects->Create Barcode Mode Action +/// +void MainWindow::objectsCreateBarcode() +{ + qDebug() << "ACTION: objects->Create->Barcode"; +} + + +/// +/// Objects->Order->Bring To Front Action +/// +void MainWindow::objectsOrderRaise() +{ + mModel->raiseSelectionToTop(); +} + + +/// +/// Objects->Order->Send To Back Action +/// +void MainWindow::objectsOrderLower() +{ + mModel->lowerSelectionToBottom(); +} + + +/// +/// Objects->Rotate/Flip->Rotate Left Action +/// +void MainWindow::objectsXformRotateLeft() +{ + mModel->rotateSelectionLeft(); +} + + +/// +/// Objects->Rotate/Flip->Rotate Right Action +/// +void MainWindow::objectsXformRotateRight() +{ + mModel->rotateSelectionRight(); +} + + +/// +/// Objects->Rotate/Flip->Flip Horizontally Action +/// +void MainWindow::objectsXformFlipHoriz() +{ + mModel->flipSelectionHoriz(); +} + + +/// +/// Objects->Rotate/Flip->Flip Vertically Action +/// +void MainWindow::objectsXformFlipVert() +{ + mModel->flipSelectionVert(); +} + + +/// +/// Objects->Align->Left Action +/// +void MainWindow::objectsAlignLeft() +{ + mModel->alignSelectionLeft(); +} + + +/// +/// Objects->Align->Center Horizontally Action +/// +void MainWindow::objectsAlignHCenter() +{ + mModel->alignSelectionHCenter(); +} + + +/// +/// Objects->Align->Right Action +/// +void MainWindow::objectsAlignRight() +{ + mModel->alignSelectionRight(); +} + + +/// +/// Objects->Align->Top Action +/// +void MainWindow::objectsAlignTop() +{ + mModel->alignSelectionTop(); +} + + +/// +/// Objects->Align->Center Vertically Action +/// +void MainWindow::objectsAlignVCenter() +{ + mModel->alignSelectionVCenter(); +} + + +/// +/// Objects->Align->Bottom Action +/// +void MainWindow::objectsAlignBottom() +{ + mModel->alignSelectionBottom(); +} + + +/// +/// Objects->Center->Horizontally Action +/// +void MainWindow::objectsCenterHoriz() +{ + mModel->centerSelectionHoriz(); +} + + +/// +/// Objects->Center->Vertically Action +/// +void MainWindow::objectsCenterVert() +{ + mModel->centerSelectionVert(); +} + + +/// +/// Help->Contents Action +/// +void MainWindow::helpContents() +{ + Help::displayContents( this ); +} + + +/// +/// Help->About Action +/// +void MainWindow::helpAbout() +{ + Help::displayAbout( this ); +} + + +/// +/// Context Menu Activation +/// +void MainWindow::onContextMenuActivate() +{ + if ( mModel->isSelectionEmpty() ) + { + noSelectionContextMenu->popup( QCursor::pos() ); + } + else + { + contextMenu->popup( QCursor::pos() ); + } +} + + +/// +/// Zoom changed: update Zoom Information in Status Bar +/// +void MainWindow::onZoomChanged() +{ + zoomInfoLabel->setText( QString( " %1% " ).arg(100*mView->zoom(), 0, 'f', 0) ); + + viewZoomInAction->setEnabled( !mView->isZoomMax() ); + viewZoomOutAction->setEnabled( !mView->isZoomMin() ); +} + + +/// +/// Pointer moved: update Cursor Information in Status Bar +/// +void MainWindow::onPointerMoved( double x, double y ) +{ + /* TODO: convert x,y to locale units and set precision accordingly. */ + cursorInfoLabel->setText( QString( "%1, %2" ).arg(x).arg(y) ); +} + + +/// +/// Pointer exited view: update Zoom Information in Status Bar (Clears information) +/// +void MainWindow::onPointerExit() +{ + cursorInfoLabel->setText( "" ); +} + + +/// +/// Name changed handler +/// +void MainWindow::onNameChanged() +{ + setTitle(); +} + + +/// +/// Modified changed handler +/// +void MainWindow::onModifiedChanged() +{ + setTitle(); + setDocModifiedVerbsEnabled( mModel->isModified() ); +} + + +/// +/// Selection changed handler +/// +void MainWindow::onSelectionChanged() +{ + setSelectionVerbsEnabled( !mModel->isSelectionEmpty() ); + setMultiSelectionVerbsEnabled( !mModel->isSelectionAtomic() ); +} + + +/// +/// Label changed handler +/// +void MainWindow::onLabelChanged() +{ + /* @TODO: update undo/redo verbs. */ +} diff --git a/glabels/MainWindow.h b/glabels/MainWindow.h index 4a0f798..4413b09 100644 --- a/glabels/MainWindow.h +++ b/glabels/MainWindow.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_MainWindow_h -#define glabels_MainWindow_h +#ifndef MainWindow_h +#define MainWindow_h #include @@ -32,245 +32,242 @@ class QLabel; class QScrollArea; -namespace glabels +// Forward References +class LabelModel; +class PropertiesView; +class View; +class ObjectEditor; +class MergePropertyEditor; +class PrintView; + + +/// +/// MainWindow Widget +/// +class MainWindow : public QMainWindow { - // Forward References - class LabelModel; - class PropertiesView; - class View; - class ObjectEditor; - class MergePropertyEditor; - class PrintView; + Q_OBJECT - /// - /// MainWindow Widget - /// - class MainWindow : public QMainWindow - { - Q_OBJECT + ///////////////////////////////////// + // Lifecycle + ///////////////////////////////////// +public: + MainWindow(); + virtual ~MainWindow(); - ///////////////////////////////////// - // Lifecycle - ///////////////////////////////////// - public: - MainWindow(); - virtual ~MainWindow(); + ///////////////////////////////////// + // Public Methods + ///////////////////////////////////// +public: + LabelModel* model() const; + void setModel( LabelModel* label ); + bool isEmpty() const; + + static QList windowList(); - ///////////////////////////////////// - // Public Methods - ///////////////////////////////////// - public: - LabelModel* model() const; - void setModel( LabelModel* label ); - bool isEmpty() const; - - static QList windowList(); + ///////////////////////////////////// + // Events + ///////////////////////////////////// +protected: + void closeEvent( QCloseEvent *event ); - ///////////////////////////////////// - // Events - ///////////////////////////////////// - protected: - void closeEvent( QCloseEvent *event ); + ///////////////////////////////////// + // Slots + ///////////////////////////////////// +private slots: + void fileNew(); + void fileOpen(); + void fileSave(); + void fileSaveAs(); + void fileProperties(); + void fileTemplateDesigner(); + void fileClose(); + void fileExit(); + + void editUndo(); + void editRedo(); + void editCut(); + void editCopy(); + void editPaste(); + void editDelete(); + void editSelectAll(); + void editUnSelectAll(); + void editPreferences(); + + void viewFileToolBar( bool ); + void viewEditorToolBar( bool ); + void viewGrid( bool ); + void viewMarkup( bool ); + void viewZoomIn(); + void viewZoomOut(); + void viewZoom1To1(); + void viewZoomToFit(); + + void objectsArrowMode(); + void objectsCreateText(); + void objectsCreateBox(); + void objectsCreateLine(); + void objectsCreateEllipse(); + void objectsCreateImage(); + void objectsCreateBarcode(); + void objectsOrderRaise(); + void objectsOrderLower(); + void objectsXformRotateLeft(); + void objectsXformRotateRight(); + void objectsXformFlipHoriz(); + void objectsXformFlipVert(); + void objectsAlignLeft(); + void objectsAlignHCenter(); + void objectsAlignRight(); + void objectsAlignTop(); + void objectsAlignVCenter(); + void objectsAlignBottom(); + void objectsCenterHoriz(); + void objectsCenterVert(); + + void helpContents(); + void helpAbout(); + + void onContextMenuActivate(); + + void onZoomChanged(); + void onPointerMoved( double, double ); + void onPointerExit(); + + void onNameChanged(); + void onModifiedChanged(); + void onSelectionChanged(); + void onLabelChanged(); - ///////////////////////////////////// - // Slots - ///////////////////////////////////// - private slots: - void fileNew(); - void fileOpen(); - void fileSave(); - void fileSaveAs(); - void fileProperties(); - void fileTemplateDesigner(); - void fileClose(); - void fileExit(); + ///////////////////////////////////// + // Internal Private Methods + ///////////////////////////////////// +private: + void createActions(); + void createMenus(); + void createToolBars(); + void createStatusBar(); - void editUndo(); - void editRedo(); - void editCut(); - void editCopy(); - void editPaste(); - void editDelete(); - void editSelectAll(); - void editUnSelectAll(); - void editPreferences(); + QWidget* createPropertiesPage(); + QWidget* createEditorPage(); + QWidget* createMergePage(); + QWidget* createPrintPage(); - void viewFileToolBar( bool ); - void viewEditorToolBar( bool ); - void viewGrid( bool ); - void viewMarkup( bool ); - void viewZoomIn(); - void viewZoomOut(); - void viewZoom1To1(); - void viewZoomToFit(); + void setDocVerbsEnabled( bool ); + void setDocModifiedVerbsEnabled( bool ); + void setPasteVerbsEnabled( bool ); + void setSelectionVerbsEnabled( bool ); + void setMultiSelectionVerbsEnabled( bool ); - void objectsArrowMode(); - void objectsCreateText(); - void objectsCreateBox(); - void objectsCreateLine(); - void objectsCreateEllipse(); - void objectsCreateImage(); - void objectsCreateBarcode(); - void objectsOrderRaise(); - void objectsOrderLower(); - void objectsXformRotateLeft(); - void objectsXformRotateRight(); - void objectsXformFlipHoriz(); - void objectsXformFlipVert(); - void objectsAlignLeft(); - void objectsAlignHCenter(); - void objectsAlignRight(); - void objectsAlignTop(); - void objectsAlignVCenter(); - void objectsAlignBottom(); - void objectsCenterHoriz(); - void objectsCenterVert(); + void setTitle(); - void helpContents(); - void helpAbout(); - - void onContextMenuActivate(); - - void onZoomChanged(); - void onPointerMoved( double, double ); - void onPointerExit(); - - void onNameChanged(); - void onModifiedChanged(); - void onSelectionChanged(); - void onLabelChanged(); + void readSettings(); + void writeSettings(); - ///////////////////////////////////// - // Internal Private Methods - ///////////////////////////////////// - private: - void createActions(); - void createMenus(); - void createToolBars(); - void createStatusBar(); + ///////////////////////////////////// + // Private Data + ///////////////////////////////////// +private: + static QList smWindowList; - QWidget* createPropertiesPage(); - QWidget* createEditorPage(); - QWidget* createMergePage(); - QWidget* createPrintPage(); + QMenu* fileMenu; + QMenu* editMenu; + QMenu* viewMenu; + QMenu* viewToolBarsMenu; + QMenu* objectsMenu; + QMenu* objectsCreateMenu; + QMenu* objectsOrderMenu; + QMenu* objectsXformMenu; + QMenu* objectsAlignMenu; + QMenu* objectsCenterMenu; + QMenu* helpMenu; - void setDocVerbsEnabled( bool ); - void setDocModifiedVerbsEnabled( bool ); - void setPasteVerbsEnabled( bool ); - void setSelectionVerbsEnabled( bool ); - void setMultiSelectionVerbsEnabled( bool ); - - void setTitle(); - - void readSettings(); - void writeSettings(); - - - ///////////////////////////////////// - // Private Data - ///////////////////////////////////// - private: - static QList smWindowList; - - QMenu* fileMenu; - QMenu* editMenu; - QMenu* viewMenu; - QMenu* viewToolBarsMenu; - QMenu* objectsMenu; - QMenu* objectsCreateMenu; - QMenu* objectsOrderMenu; - QMenu* objectsXformMenu; - QMenu* objectsAlignMenu; - QMenu* objectsCenterMenu; - QMenu* helpMenu; - - QMenu* contextMenu; - QMenu* contextOrderMenu; - QMenu* contextXformMenu; - QMenu* contextAlignMenu; - QMenu* contextCenterMenu; - QMenu* noSelectionContextMenu; + QMenu* contextMenu; + QMenu* contextOrderMenu; + QMenu* contextXformMenu; + QMenu* contextAlignMenu; + QMenu* contextCenterMenu; + QMenu* noSelectionContextMenu; - QToolBar* fileToolBar; - QToolBar* editorToolBar; + QToolBar* fileToolBar; + QToolBar* editorToolBar; - QTabWidget* mNotebook; - LabelModel* mModel; - PropertiesView* mPropertiesView; - QScrollArea* mViewScrollArea; - View* mView; - ObjectEditor* mObjectEditor; - MergePropertyEditor* mMergePropertyEditor; - PrintView* mPrintView; + QTabWidget* mNotebook; + LabelModel* mModel; + PropertiesView* mPropertiesView; + QScrollArea* mViewScrollArea; + View* mView; + ObjectEditor* mObjectEditor; + MergePropertyEditor* mMergePropertyEditor; + PrintView* mPrintView; - QLabel* zoomInfoLabel; - QLabel* cursorInfoLabel; + QLabel* zoomInfoLabel; + QLabel* cursorInfoLabel; - QAction* fileNewAction; - QAction* fileOpenAction; - QAction* fileSaveAction; - QAction* fileSaveAsAction; - QAction* filePropertiesAction; - QAction* fileTemplateDesignerAction; - QAction* fileCloseAction; - QAction* fileExitAction; + QAction* fileNewAction; + QAction* fileOpenAction; + QAction* fileSaveAction; + QAction* fileSaveAsAction; + QAction* filePropertiesAction; + QAction* fileTemplateDesignerAction; + QAction* fileCloseAction; + QAction* fileExitAction; - QAction* editUndoAction; - QAction* editRedoAction; - QAction* editCutAction; - QAction* editCopyAction; - QAction* editPasteAction; - QAction* editDeleteAction; - QAction* editSelectAllAction; - QAction* editUnSelectAllAction; - QAction* editPreferencesAction; + QAction* editUndoAction; + QAction* editRedoAction; + QAction* editCutAction; + QAction* editCopyAction; + QAction* editPasteAction; + QAction* editDeleteAction; + QAction* editSelectAllAction; + QAction* editUnSelectAllAction; + QAction* editPreferencesAction; - QAction* viewFileToolBarAction; - QAction* viewEditorToolBarAction; - QAction* viewGridAction; - QAction* viewMarkupAction; - QAction* viewZoomInAction; - QAction* viewZoomOutAction; - QAction* viewZoom1To1Action; - QAction* viewZoomToFitAction; + QAction* viewFileToolBarAction; + QAction* viewEditorToolBarAction; + QAction* viewGridAction; + QAction* viewMarkupAction; + QAction* viewZoomInAction; + QAction* viewZoomOutAction; + QAction* viewZoom1To1Action; + QAction* viewZoomToFitAction; - QAction* objectsArrowModeAction; - QAction* objectsCreateTextAction; - QAction* objectsCreateBoxAction; - QAction* objectsCreateLineAction; - QAction* objectsCreateEllipseAction; - QAction* objectsCreateImageAction; - QAction* objectsCreateBarcodeAction; - QAction* objectsOrderRaiseAction; - QAction* objectsOrderLowerAction; - QAction* objectsXformRotateLeftAction; - QAction* objectsXformRotateRightAction; - QAction* objectsXformFlipHorizAction; - QAction* objectsXformFlipVertAction; - QAction* objectsAlignLeftAction; - QAction* objectsAlignHCenterAction; - QAction* objectsAlignRightAction; - QAction* objectsAlignTopAction; - QAction* objectsAlignVCenterAction; - QAction* objectsAlignBottomAction; - QAction* objectsCenterHorizAction; - QAction* objectsCenterVertAction; + QAction* objectsArrowModeAction; + QAction* objectsCreateTextAction; + QAction* objectsCreateBoxAction; + QAction* objectsCreateLineAction; + QAction* objectsCreateEllipseAction; + QAction* objectsCreateImageAction; + QAction* objectsCreateBarcodeAction; + QAction* objectsOrderRaiseAction; + QAction* objectsOrderLowerAction; + QAction* objectsXformRotateLeftAction; + QAction* objectsXformRotateRightAction; + QAction* objectsXformFlipHorizAction; + QAction* objectsXformFlipVertAction; + QAction* objectsAlignLeftAction; + QAction* objectsAlignHCenterAction; + QAction* objectsAlignRightAction; + QAction* objectsAlignTopAction; + QAction* objectsAlignVCenterAction; + QAction* objectsAlignBottomAction; + QAction* objectsCenterHorizAction; + QAction* objectsCenterVertAction; - QAction* helpContentsAction; - QAction* helpAboutAction; + QAction* helpContentsAction; + QAction* helpAboutAction; - QAction* contextCutAction; - QAction* contextCopyAction; - QAction* contextPasteAction; - QAction* contextDeleteAction; - }; + QAction* contextCutAction; + QAction* contextCopyAction; + QAction* contextPasteAction; + QAction* contextDeleteAction; +}; -} -#endif // glabels_MainWindow_h +#endif // MainWindow_h diff --git a/glabels/Merge.cpp b/glabels/Merge.cpp index 57b58c7..6ee0f6d 100644 --- a/glabels/Merge.cpp +++ b/glabels/Merge.cpp @@ -21,115 +21,108 @@ #include "Merge.h" -namespace glabels +/// +/// Constructor +/// +Merge::Merge( QString id, QString name, SourceType type ) + : mId(id), mName(name), mType(type) { - - /// - /// Constructor - /// - Merge::Merge( QString id, QString name, SourceType type ) - : mId(id), mName(name), mType(type) - { - } - - - /// - /// Destructor - /// - Merge::~Merge() - { - } - - - /// - /// Set source - /// - void Merge::setSource( const QString& source ) - { - mSource = source; - - // Clear out any old records - foreach ( MergeRecord* record, mRecordList ) - { - delete record; - } - mRecordList.clear(); - - open(); - for ( MergeRecord* record = readNextRecord(); record != 0; record = readNextRecord() ) - { - mRecordList.append( record ); - } - close(); - - emit sourceChanged(); - } - - - /// - /// Select matching record - /// - void Merge::select( MergeRecord* record ) - { - record->setSelected( true ); - emit selectionChanged(); - } - - - /// - /// Unselect matching record - /// - void Merge::unselect( MergeRecord* record ) - { - record->setSelected( false ); - emit selectionChanged(); - } - - - /// - /// Select all records - /// - void Merge::selectAll() - { - foreach ( MergeRecord* record, mRecordList ) - { - record->setSelected( true ); - } - emit selectionChanged(); - } - - - /// - /// Unselect all records - /// - void Merge::unselectAll() - { - foreach ( MergeRecord* record, mRecordList ) - { - record->setSelected( false ); - } - emit selectionChanged(); - } - - - /// - /// Return list of selected records - /// - const QList Merge::selectedRecords() const - { - QList list; - - foreach ( MergeRecord* record, mRecordList ) - { - if ( record->isSelected() ) - { - list.append( record ); - } - } - - return list; - } - } +/// +/// Destructor +/// +Merge::~Merge() +{ +} + + +/// +/// Set source +/// +void Merge::setSource( const QString& source ) +{ + mSource = source; + + // Clear out any old records + foreach ( MergeRecord* record, mRecordList ) + { + delete record; + } + mRecordList.clear(); + + open(); + for ( MergeRecord* record = readNextRecord(); record != 0; record = readNextRecord() ) + { + mRecordList.append( record ); + } + close(); + + emit sourceChanged(); +} + + +/// +/// Select matching record +/// +void Merge::select( MergeRecord* record ) +{ + record->setSelected( true ); + emit selectionChanged(); +} + + +/// +/// Unselect matching record +/// +void Merge::unselect( MergeRecord* record ) +{ + record->setSelected( false ); + emit selectionChanged(); +} + + +/// +/// Select all records +/// +void Merge::selectAll() +{ + foreach ( MergeRecord* record, mRecordList ) + { + record->setSelected( true ); + } + emit selectionChanged(); +} + + +/// +/// Unselect all records +/// +void Merge::unselectAll() +{ + foreach ( MergeRecord* record, mRecordList ) + { + record->setSelected( false ); + } + emit selectionChanged(); +} + + +/// +/// Return list of selected records +/// +const QList Merge::selectedRecords() const +{ + QList list; + + foreach ( MergeRecord* record, mRecordList ) + { + if ( record->isSelected() ) + { + list.append( record ); + } + } + + return list; +} diff --git a/glabels/Merge.h b/glabels/Merge.h index 216339b..ebd6667 100644 --- a/glabels/Merge.h +++ b/glabels/Merge.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_Merge_h -#define glabels_Merge_h +#ifndef Merge_h +#define Merge_h #include #include @@ -28,121 +28,117 @@ #include "MergeRecord.h" -namespace glabels +/// +/// Merge Record Structure +/// +struct Merge : QObject { - - /// - /// Merge Record Structure - /// - struct Merge : QObject - { - Q_OBJECT - - - ///////////////////////////////// - // Source Type - ///////////////////////////////// - enum SourceType { NONE, FIXED, FILE }; - - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - protected: - Merge( QString id, QString name, SourceType type ); - virtual ~Merge(); - - - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - inline QString id() const; - inline QString name() const; - inline SourceType type() const; - inline QString source() const; - void setSource( const QString& source ); - - inline const QList& recordList( void ) const; - - - ///////////////////////////////// - // Selection methods - ///////////////////////////////// - public: - void select( MergeRecord* record ); - void unselect( MergeRecord* record ); - void selectAll(); - void unselectAll(); - const QList selectedRecords() const; - - - ///////////////////////////////// - // Virtual methods - ///////////////////////////////// - public: - virtual QList keyList() const = 0; - virtual QString primaryKey() const = 0; - protected: - virtual void open() = 0; - virtual void close() = 0; - virtual MergeRecord* readNextRecord() = 0; - - - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void sourceChanged(); - void selectionChanged(); - - - ///////////////////////////////// - // Private data - ///////////////////////////////// - private: - QString mId; - QString mName; - SourceType mType; - - QString mSource; - bool mSelected; - QList mRecordList; - }; + Q_OBJECT ///////////////////////////////// - // INLINE METHODS + // Source Type ///////////////////////////////// - QString Merge::id() const - { - return mId; - } + enum SourceType { NONE, FIXED, FILE }; + + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +protected: + Merge( QString id, QString name, SourceType type ); + virtual ~Merge(); - QString Merge::name() const - { - return mId; - } + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + inline QString id() const; + inline QString name() const; + inline SourceType type() const; + inline QString source() const; + void setSource( const QString& source ); + + inline const QList& recordList( void ) const; - Merge::SourceType Merge::type() const - { - return mType; - } + ///////////////////////////////// + // Selection methods + ///////////////////////////////// +public: + void select( MergeRecord* record ); + void unselect( MergeRecord* record ); + void selectAll(); + void unselectAll(); + const QList selectedRecords() const; - QString Merge::source() const - { - return mSource; - } + ///////////////////////////////// + // Virtual methods + ///////////////////////////////// +public: + virtual QList keyList() const = 0; + virtual QString primaryKey() const = 0; +protected: + virtual void open() = 0; + virtual void close() = 0; + virtual MergeRecord* readNextRecord() = 0; + + + ///////////////////////////////// + // Signals + ///////////////////////////////// +signals: + void sourceChanged(); + void selectionChanged(); + + + ///////////////////////////////// + // Private data + ///////////////////////////////// +private: + QString mId; + QString mName; + SourceType mType; + + QString mSource; + bool mSelected; + QList mRecordList; +}; - const QList& Merge::recordList( void ) const - { - return mRecordList; - } - +///////////////////////////////// +// INLINE METHODS +///////////////////////////////// +QString Merge::id() const +{ + return mId; } -#endif // glabels_Merge_h + +QString Merge::name() const +{ + return mId; +} + + +Merge::SourceType Merge::type() const +{ + return mType; +} + + +QString Merge::source() const +{ + return mSource; +} + + +const QList& Merge::recordList( void ) const +{ + return mRecordList; +} + + +#endif // Merge_h diff --git a/glabels/MergeField.h b/glabels/MergeField.h index 659ec84..ef75ca2 100644 --- a/glabels/MergeField.h +++ b/glabels/MergeField.h @@ -18,75 +18,71 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_MergeField_h -#define glabels_MergeField_h +#ifndef MergeField_h +#define MergeField_h #include -namespace glabels +/// +/// Merge Field Structure +/// +struct MergeField { - /// - /// Merge Field Structure - /// - struct MergeField - { - - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - // - // Key Property - // - inline const QString key( void ) const; - inline void setKey( const QString &value ); + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + // + // Key Property + // + inline const QString key( void ) const; + inline void setKey( const QString &value ); - // - // Value Property - // - inline const QString value( void ) const; - inline void setValue( const QString &value ); - - - ///////////////////////////////// - // Private data - ///////////////////////////////// - private: - QString mKey; - QString mValue; - - }; + // + // Value Property + // + inline const QString value( void ) const; + inline void setValue( const QString &value ); ///////////////////////////////// - // INLINE METHODS + // Private data ///////////////////////////////// - const QString MergeField::key( void ) const - { - return mKey; - } +private: + QString mKey; + QString mValue; + +}; - void MergeField::setKey( const QString &value ) - { - mKey = value; - } - - - const QString MergeField::value( void ) const - { - return mValue; - } - - - void MergeField::setValue( const QString &value ) - { - mValue = value; - } - +///////////////////////////////// +// INLINE METHODS +///////////////////////////////// +const QString MergeField::key( void ) const +{ + return mKey; } -#endif // glabels_MergeField_h + +void MergeField::setKey( const QString &value ) +{ + mKey = value; +} + + +const QString MergeField::value( void ) const +{ + return mValue; +} + + +void MergeField::setValue( const QString &value ) +{ + mValue = value; +} + + +#endif // MergeField_h diff --git a/glabels/MergePropertyEditor.cpp b/glabels/MergePropertyEditor.cpp index ceae55f..458b54d 100644 --- a/glabels/MergePropertyEditor.cpp +++ b/glabels/MergePropertyEditor.cpp @@ -24,43 +24,38 @@ #include -namespace glabels +/// +/// Constructor +/// +MergePropertyEditor::MergePropertyEditor( QWidget *parent ) + : QWidget(parent), mModel(0) +{ + setupUi( this ); +} + + +/// +/// Destructor +/// +MergePropertyEditor::~MergePropertyEditor() +{ +} + + +/// +/// Set Model +/// +void MergePropertyEditor::setModel( LabelModel* model ) +{ + mModel = model; + + connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) ); +} + + +/// +/// Label changed handler +/// +void MergePropertyEditor::onLabelChanged() { - - /// - /// Constructor - /// - MergePropertyEditor::MergePropertyEditor( QWidget *parent ) - : QWidget(parent), mModel(0) - { - setupUi( this ); - } - - - /// - /// Destructor - /// - MergePropertyEditor::~MergePropertyEditor() - { - } - - - /// - /// Set Model - /// - void MergePropertyEditor::setModel( LabelModel* model ) - { - mModel = model; - - connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) ); - } - - - /// - /// Label changed handler - /// - void MergePropertyEditor::onLabelChanged() - { - } - } diff --git a/glabels/MergePropertyEditor.h b/glabels/MergePropertyEditor.h index 515a681..24dbcf8 100644 --- a/glabels/MergePropertyEditor.h +++ b/glabels/MergePropertyEditor.h @@ -18,54 +18,51 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_MergePropertyEditor_h -#define glabels_MergePropertyEditor_h +#ifndef MergePropertyEditor_h +#define MergePropertyEditor_h #include "ui_MergePropertyEditor.h" -namespace glabels -{ - class LabelModel; // Forward reference +class LabelModel; // Forward reference - /// - /// Merge Property Editor Widget - /// - class MergePropertyEditor : public QWidget, public Ui_MergePropertyEditor - { - Q_OBJECT +/// +/// Merge Property Editor Widget +/// +class MergePropertyEditor : public QWidget, public Ui_MergePropertyEditor +{ + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - MergePropertyEditor( QWidget *parent = 0 ); - ~MergePropertyEditor(); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + MergePropertyEditor( QWidget *parent = 0 ); + ~MergePropertyEditor(); - ///////////////////////////////// - // Public methods - ///////////////////////////////// - void setModel( LabelModel* model ); + ///////////////////////////////// + // Public methods + ///////////////////////////////// + void setModel( LabelModel* model ); - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onLabelChanged(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onLabelChanged(); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - LabelModel* mModel; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + LabelModel* mModel; - }; +}; -} -#endif // glabels_MergePropertyEditor_h +#endif // MergePropertyEditor_h diff --git a/glabels/MergeRecord.cpp b/glabels/MergeRecord.cpp index 5800a21..7afd5e9 100644 --- a/glabels/MergeRecord.cpp +++ b/glabels/MergeRecord.cpp @@ -21,16 +21,9 @@ #include "MergeRecord.h" -namespace glabels +/// +/// Constructor +/// +MergeRecord::MergeRecord() : mSelected( false ) { - - /// - /// Constructor - /// - MergeRecord::MergeRecord() : mSelected( false ) - { - } - } - - diff --git a/glabels/MergeRecord.h b/glabels/MergeRecord.h index f51f2c1..8790e88 100644 --- a/glabels/MergeRecord.h +++ b/glabels/MergeRecord.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_MergeRecord_h -#define glabels_MergeRecord_h +#ifndef MergeRecord_h +#define MergeRecord_h #include #include @@ -27,74 +27,70 @@ #include "MergeField.h" -namespace glabels +/// +/// Merge Record Structure +/// +struct MergeRecord { - - /// - /// Merge Record Structure - /// - struct MergeRecord - { - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - MergeRecord(); - - - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - inline bool isSelected() const; - inline void setSelected( bool value ); - inline bool empty() const; - - inline const QList& fieldList() const; - inline void setFieldList( QList& value ); - - - ///////////////////////////////// - // Private data - ///////////////////////////////// - private: - bool mSelected; - QList mFieldList; - }; + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + MergeRecord(); ///////////////////////////////// - // INLINE METHODS + // Properties ///////////////////////////////// - bool MergeRecord::isSelected() const - { - return mSelected; - } +public: + inline bool isSelected() const; + inline void setSelected( bool value ); + inline bool empty() const; + + inline const QList& fieldList() const; + inline void setFieldList( QList& value ); - void MergeRecord::setSelected( bool value ) - { - mSelected = value; - } + ///////////////////////////////// + // Private data + ///////////////////////////////// +private: + bool mSelected; + QList mFieldList; +}; - bool MergeRecord::empty() const - { - return mFieldList.size() == 0; - } - - - const QList& MergeRecord::fieldList() const - { - return mFieldList; - } - - - void MergeRecord::setFieldList( QList& value ) - { - mFieldList = value; - } - +///////////////////////////////// +// INLINE METHODS +///////////////////////////////// +bool MergeRecord::isSelected() const +{ + return mSelected; } -#endif // glabels_MergeRecord_h + +void MergeRecord::setSelected( bool value ) +{ + mSelected = value; +} + + +bool MergeRecord::empty() const +{ + return mFieldList.size() == 0; +} + + +const QList& MergeRecord::fieldList() const +{ + return mFieldList; +} + + +void MergeRecord::setFieldList( QList& value ) +{ + mFieldList = value; +} + + +#endif // MergeRecord_h diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index 6d72d07..72ecc23 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -29,306 +29,301 @@ #include -namespace glabels +/// +/// Constructor +/// +ObjectEditor::ObjectEditor( QWidget *parent ) + : mModel(0), mObject(0), mBlocked(false) { + setupUi( this ); - /// - /// Constructor - /// - ObjectEditor::ObjectEditor( QWidget *parent ) - : mModel(0), mObject(0), mBlocked(false) - { - setupUi( this ); + lineColorButton->init( "No line", QColor(0,0,0,0), QColor(0,0,0,255) ); + fillColorButton->init( "No fill", QColor(0,0,0,0), QColor(0,0,0,255) ); + shadowColorButton->init( "Default", QColor(0,0,0,255), QColor(0,0,0,255) ); - lineColorButton->init( "No line", QColor(0,0,0,0), QColor(0,0,0,255) ); - fillColorButton->init( "No fill", QColor(0,0,0,0), QColor(0,0,0,255) ); - shadowColorButton->init( "Default", QColor(0,0,0,255), QColor(0,0,0,255) ); - - setEnabled( false ); - hidePages(); - } + setEnabled( false ); + hidePages(); +} - void ObjectEditor::setModel( LabelModel* model ) - { - mModel = model; +void ObjectEditor::setModel( LabelModel* model ) +{ + mModel = model; - connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) ); - connect( mModel, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()) ); + connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) ); + connect( mModel, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()) ); - onLabelSizeChanged(); - onSelectionChanged(); - } + onLabelSizeChanged(); + onSelectionChanged(); +} - void ObjectEditor::hidePages() +void ObjectEditor::hidePages() +{ + notebook->removeTab( notebook->indexOf(textPage) ); + notebook->removeTab( notebook->indexOf(barcodePage) ); + notebook->removeTab( notebook->indexOf(imagePage) ); + notebook->removeTab( notebook->indexOf(lineFillPage) ); + notebook->removeTab( notebook->indexOf(posSizePage) ); + notebook->removeTab( notebook->indexOf(shadowPage) ); +} + + +void ObjectEditor::loadLineFillPage() +{ + if ( mObject ) { - notebook->removeTab( notebook->indexOf(textPage) ); - notebook->removeTab( notebook->indexOf(barcodePage) ); - notebook->removeTab( notebook->indexOf(imagePage) ); - notebook->removeTab( notebook->indexOf(lineFillPage) ); - notebook->removeTab( notebook->indexOf(posSizePage) ); - notebook->removeTab( notebook->indexOf(shadowPage) ); + mBlocked = true; + + lineWidthSpin->setValue( mObject->lineWidth().pt() ); + lineColorButton->setColorNode( mObject->lineColorNode() ); + fillColorButton->setColorNode( mObject->fillColorNode() ); + + mBlocked = false; } +} - void ObjectEditor::loadLineFillPage() +void ObjectEditor::loadPositionPage() +{ + if ( mObject ) { - if ( mObject ) - { - mBlocked = true; + mBlocked = true; - lineWidthSpin->setValue( mObject->lineWidth().pt() ); - lineColorButton->setColorNode( mObject->lineColorNode() ); - fillColorButton->setColorNode( mObject->fillColorNode() ); + posXSpin->setValue( mObject->x0().in() ); + posYSpin->setValue( mObject->y0().in() ); - mBlocked = false; - } + mBlocked = false; } +} - void ObjectEditor::loadPositionPage() +void ObjectEditor::loadRectSizePage() +{ + if ( mObject ) { - if ( mObject ) - { - mBlocked = true; + mBlocked = true; - posXSpin->setValue( mObject->x0().in() ); - posYSpin->setValue( mObject->y0().in() ); + sizeWSpin->setValue( mObject->w().in() ); + sizeHSpin->setValue( mObject->h().in() ); - mBlocked = false; - } + mBlocked = false; } +} - void ObjectEditor::loadRectSizePage() +void ObjectEditor::loadShadowPage() +{ + if ( mObject ) { - if ( mObject ) - { - mBlocked = true; + mBlocked = true; - sizeWSpin->setValue( mObject->w().in() ); - sizeHSpin->setValue( mObject->h().in() ); + shadowEnableCheck->setChecked( mObject->shadow() ); + shadowXSpin->setValue( mObject->shadowX().in() ); + shadowYSpin->setValue( mObject->shadowY().in() ); + shadowColorButton->setColorNode( mObject->shadowColorNode() ); + shadowOpacitySpin->setValue( 100*mObject->shadowOpacity() ); - mBlocked = false; - } + mBlocked = false; } +} - void ObjectEditor::loadShadowPage() +void ObjectEditor::onLabelSizeChanged() +{ + if ( mModel ) { - if ( mObject ) - { - mBlocked = true; - - shadowEnableCheck->setChecked( mObject->shadow() ); - shadowXSpin->setValue( mObject->shadowX().in() ); - shadowYSpin->setValue( mObject->shadowY().in() ); - shadowColorButton->setColorNode( mObject->shadowColorNode() ); - shadowOpacitySpin->setValue( 100*mObject->shadowOpacity() ); + mBlocked = true; - mBlocked = false; - } - } - - - void ObjectEditor::onLabelSizeChanged() - { - if ( mModel ) - { - mBlocked = true; - - libglabels::Distance whMax = std::max( mModel->w(), mModel->h() ); - - posXSpin->setRange( -whMax.in(), 2*whMax.in() ); - posYSpin->setRange( -whMax.in(), 2*whMax.in() ); - sizeWSpin->setRange( 0, 2*whMax.in() ); - sizeHSpin->setRange( 0, 2*whMax.in() ); - - mBlocked = false; - } + glabels::Distance whMax = std::max( mModel->w(), mModel->h() ); + + posXSpin->setRange( -whMax.in(), 2*whMax.in() ); + posYSpin->setRange( -whMax.in(), 2*whMax.in() ); + sizeWSpin->setRange( 0, 2*whMax.in() ); + sizeHSpin->setRange( 0, 2*whMax.in() ); + + mBlocked = false; } +} - void ObjectEditor::onSelectionChanged() +void ObjectEditor::onSelectionChanged() +{ + if ( mObject ) { - if ( mObject ) + disconnect( mObject, 0, this, 0 ); + } + + hidePages(); + + if ( mModel->isSelectionAtomic() ) + { + mObject = mModel->getFirstSelectedObject(); + + if ( dynamic_cast(mObject) ) { - disconnect( mObject, 0, this, 0 ); - } + titleImageLabel->setPixmap( QPixmap(":icons/24x24/actions/glabels-box.png") ); + titleLabel->setText( "Box object properties" ); - hidePages(); + notebook->addTab( lineFillPage, "line/fill" ); + notebook->addTab( posSizePage, "position/size" ); + notebook->addTab( shadowPage, "shadow" ); - if ( mModel->isSelectionAtomic() ) - { - mObject = mModel->getFirstSelectedObject(); + sizeRectFrame->setVisible( true ); + sizeResetImageButton->setVisible( false ); + sizeLineFrame->setVisible( false ); - if ( dynamic_cast(mObject) ) - { - titleImageLabel->setPixmap( QPixmap(":icons/24x24/actions/glabels-box.png") ); - titleLabel->setText( "Box object properties" ); - - notebook->addTab( lineFillPage, "line/fill" ); - notebook->addTab( posSizePage, "position/size" ); - notebook->addTab( shadowPage, "shadow" ); - - sizeRectFrame->setVisible( true ); - sizeResetImageButton->setVisible( false ); - sizeLineFrame->setVisible( false ); - - loadLineFillPage(); - loadPositionPage(); - loadRectSizePage(); - loadShadowPage(); + loadLineFillPage(); + loadPositionPage(); + loadRectSizePage(); + loadShadowPage(); - setEnabled( true ); - } - else - { - Q_ASSERT_X( false, "ObjectEditor::onSelectionChanged", "Invalid object" ); - } - - connect( mObject, SIGNAL(changed()), this, SLOT(onObjectChanged()) ); - connect( mObject, SIGNAL(moved()), this, SLOT(onObjectMoved()) ); - connect( mObject, SIGNAL(destroyed(QObject*)), this, SLOT(onObjectDestroyed()) ); + setEnabled( true ); } else { - mObject = 0; - - titleImageLabel->setPixmap( QPixmap(":icons/24x24/actions/glabels-object-properties.png") ); - titleLabel->setText( "Object properties" ); - setEnabled( false ); + Q_ASSERT_X( false, "ObjectEditor::onSelectionChanged", "Invalid object" ); } + + connect( mObject, SIGNAL(changed()), this, SLOT(onObjectChanged()) ); + connect( mObject, SIGNAL(moved()), this, SLOT(onObjectMoved()) ); + connect( mObject, SIGNAL(destroyed(QObject*)), this, SLOT(onObjectDestroyed()) ); } - - - void ObjectEditor::onObjectChanged() + else { - if ( !mBlocked ) - { - loadLineFillPage(); - loadRectSizePage(); - loadShadowPage(); - } - } - - - void ObjectEditor::onObjectMoved() - { - if ( !mBlocked ) - { - loadPositionPage(); - } - } - - - void ObjectEditor::onObjectDestroyed() - { - disconnect( mObject, 0, this, 0 ); mObject = 0; - } - - - void ObjectEditor::onLineControlsChanged() - { - if ( !mBlocked ) - { - mBlocked = true; - mObject->setLineWidth( libglabels::Distance::pt(lineWidthSpin->value()) ); - mObject->setLineColorNode( lineColorButton->colorNode() ); - - mBlocked = false; - } + titleImageLabel->setPixmap( QPixmap(":icons/24x24/actions/glabels-object-properties.png") ); + titleLabel->setText( "Object properties" ); + setEnabled( false ); } +} - void ObjectEditor::onFillControlsChanged() +void ObjectEditor::onObjectChanged() +{ + if ( !mBlocked ) { - if ( !mBlocked ) - { - mBlocked = true; - - mObject->setFillColorNode( fillColorButton->colorNode() ); - - mBlocked = false; - } + loadLineFillPage(); + loadRectSizePage(); + loadShadowPage(); } +} - - void ObjectEditor::onPositionControlsChanged() + +void ObjectEditor::onObjectMoved() +{ + if ( !mBlocked ) { - if ( !mBlocked ) - { - mBlocked = true; - - mObject->setPosition( posXSpin->value(), posYSpin->value() ); - - mBlocked = false; - } + loadPositionPage(); } +} - void ObjectEditor::onRectSizeControlsChanged() +void ObjectEditor::onObjectDestroyed() +{ + disconnect( mObject, 0, this, 0 ); + mObject = 0; +} + + +void ObjectEditor::onLineControlsChanged() +{ + if ( !mBlocked ) { - if ( !mBlocked ) - { - mBlocked = true; + mBlocked = true; + + mObject->setLineWidth( glabels::Distance::pt(lineWidthSpin->value()) ); + mObject->setLineColorNode( lineColorButton->colorNode() ); + + mBlocked = false; + } +} + + +void ObjectEditor::onFillControlsChanged() +{ + if ( !mBlocked ) + { + mBlocked = true; + + mObject->setFillColorNode( fillColorButton->colorNode() ); + + mBlocked = false; + } +} + + +void ObjectEditor::onPositionControlsChanged() +{ + if ( !mBlocked ) + { + mBlocked = true; + + mObject->setPosition( posXSpin->value(), posYSpin->value() ); + + mBlocked = false; + } +} + + +void ObjectEditor::onRectSizeControlsChanged() +{ + if ( !mBlocked ) + { + mBlocked = true; - libglabels::Distance spinW = libglabels::Distance::in(sizeWSpin->value()); - libglabels::Distance spinH = libglabels::Distance::in(sizeHSpin->value()); + glabels::Distance spinW = glabels::Distance::in(sizeWSpin->value()); + glabels::Distance spinH = glabels::Distance::in(sizeHSpin->value()); - if ( sizeAspectCheck->isChecked() ) + if ( sizeAspectCheck->isChecked() ) + { + if ( fabs(spinW - mObject->w()) > fabs(spinH - mObject->h()) ) { - if ( fabs(spinW - mObject->w()) > fabs(spinH - mObject->h()) ) - { - mObject->setWHonorAspect( spinW ); - sizeHSpin->setValue( mObject->h().in() ); - } - else - { - mObject->setHHonorAspect( spinH ); - sizeWSpin->setValue( mObject->w().in() ); - } + mObject->setWHonorAspect( spinW ); + sizeHSpin->setValue( mObject->h().in() ); } else { - mObject->setSize( spinW, spinH ); + mObject->setHHonorAspect( spinH ); + sizeWSpin->setValue( mObject->w().in() ); } + } + else + { + mObject->setSize( spinW, spinH ); + } - mBlocked = false; - } + mBlocked = false; + } +} + + +void ObjectEditor::onShadowControlsChanged() +{ + if ( !mBlocked ) + { + mBlocked = true; + + mObject->setShadow( shadowEnableCheck->isChecked() ); + mObject->setShadowX( glabels::Distance::in(shadowXSpin->value()) ); + mObject->setShadowY( glabels::Distance::in(shadowYSpin->value()) ); + mObject->setShadowColorNode( shadowColorButton->colorNode() ); + mObject->setShadowOpacity( shadowOpacitySpin->value()/100.0 ); + + mBlocked = false; + } +} + + +void ObjectEditor::onChanged() +{ + if ( !mBlocked ) + { + mBlocked = true; + + qDebug() << "Form changed."; + + mBlocked = false; } - - - void ObjectEditor::onShadowControlsChanged() - { - if ( !mBlocked ) - { - mBlocked = true; - - mObject->setShadow( shadowEnableCheck->isChecked() ); - mObject->setShadowX( libglabels::Distance::in(shadowXSpin->value()) ); - mObject->setShadowY( libglabels::Distance::in(shadowYSpin->value()) ); - mObject->setShadowColorNode( shadowColorButton->colorNode() ); - mObject->setShadowOpacity( shadowOpacitySpin->value()/100.0 ); - - mBlocked = false; - } - } - - - void ObjectEditor::onChanged() - { - if ( !mBlocked ) - { - mBlocked = true; - - qDebug() << "Form changed."; - - mBlocked = false; - } - } - } diff --git a/glabels/ObjectEditor.h b/glabels/ObjectEditor.h index 4b35d30..a8367a1 100644 --- a/glabels/ObjectEditor.h +++ b/glabels/ObjectEditor.h @@ -18,77 +18,74 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_ObjectEditor_h -#define glabels_ObjectEditor_h +#ifndef ObjectEditor_h +#define ObjectEditor_h #include "ui_ObjectEditor.h" -namespace glabels -{ - class LabelModel; // Forward reference - class LabelModelObject; // Forward reference +class LabelModel; // Forward reference +class LabelModelObject; // Forward reference - /// - /// Object Editor Widget - /// - class ObjectEditor : public QWidget, public Ui_ObjectEditor - { - Q_OBJECT +/// +/// Object Editor Widget +/// +class ObjectEditor : public QWidget, public Ui_ObjectEditor +{ + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - ObjectEditor( QWidget *parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + ObjectEditor( QWidget *parent = 0 ); - ///////////////////////////////// - // Public methods - ///////////////////////////////// - void setModel( LabelModel* model ); + ///////////////////////////////// + // Public methods + ///////////////////////////////// + void setModel( LabelModel* model ); - ///////////////////////////////// - // Private methods - ///////////////////////////////// - private: - void hidePages(); - void loadLineFillPage(); - void loadPositionPage(); - void loadRectSizePage(); - void loadShadowPage(); + ///////////////////////////////// + // Private methods + ///////////////////////////////// +private: + void hidePages(); + void loadLineFillPage(); + void loadPositionPage(); + void loadRectSizePage(); + void loadShadowPage(); - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onLabelSizeChanged(); - void onSelectionChanged(); - void onObjectChanged(); - void onObjectMoved(); - void onObjectDestroyed(); - void onLineControlsChanged(); - void onFillControlsChanged(); - void onPositionControlsChanged(); - void onRectSizeControlsChanged(); - void onShadowControlsChanged(); - void onChanged(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onLabelSizeChanged(); + void onSelectionChanged(); + void onObjectChanged(); + void onObjectMoved(); + void onObjectDestroyed(); + void onLineControlsChanged(); + void onFillControlsChanged(); + void onPositionControlsChanged(); + void onRectSizeControlsChanged(); + void onShadowControlsChanged(); + void onChanged(); - ///////////////////////////////// - // Private data - ///////////////////////////////// - private: - LabelModel* mModel; - LabelModelObject* mObject; - bool mBlocked; + ///////////////////////////////// + // Private data + ///////////////////////////////// +private: + LabelModel* mModel; + LabelModelObject* mObject; + bool mBlocked; - }; +}; -} -#endif // glabels_ObjectEditor_h +#endif // ObjectEditor_h diff --git a/glabels/Outline.cpp b/glabels/Outline.cpp index 7f66776..1b496e3 100644 --- a/glabels/Outline.cpp +++ b/glabels/Outline.cpp @@ -40,7 +40,7 @@ namespace /// /// Outline Constructor /// -glabels::Outline::Outline( LabelModelObject* owner ) +Outline::Outline( LabelModelObject* owner ) : mOwner(owner) { mDashes << dashSize << dashSize; @@ -63,7 +63,7 @@ glabels::Outline::Outline( LabelModelObject* owner ) /// /// Outline Destructor /// -glabels::Outline::~Outline() +Outline::~Outline() { } @@ -71,7 +71,7 @@ glabels::Outline::~Outline() /// /// Draw Outline /// -void glabels::Outline::draw( QPainter* painter ) const +void Outline::draw( QPainter* painter ) const { painter->save(); @@ -90,7 +90,7 @@ void glabels::Outline::draw( QPainter* painter ) const /// /// Create path for testing for hover condition /// -QPainterPath glabels::Outline::hoverPath( double scale ) const +QPainterPath Outline::hoverPath( double scale ) const { double s = 1 / scale; diff --git a/glabels/Outline.h b/glabels/Outline.h index 4a9d680..aadf5dc 100644 --- a/glabels/Outline.h +++ b/glabels/Outline.h @@ -18,53 +18,49 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_Outline_h -#define glabels_Outline_h +#ifndef Outline_h +#define Outline_h #include #include -namespace glabels +class LabelModelObject; + + +/// +/// Outline Base Class +/// +class Outline { - - class LabelModelObject; + //////////////////////////// + // Lifecycle Methods + //////////////////////////// +public: + Outline( LabelModelObject* owner ); + virtual ~Outline(); - /// - /// Outline Base Class - /// - class Outline - { - //////////////////////////// - // Lifecycle Methods - //////////////////////////// - public: - Outline( LabelModelObject* owner ); - virtual ~Outline(); + //////////////////////////// + // Drawing Methods + //////////////////////////// +public: + void draw( QPainter* painter ) const; + QPainterPath hoverPath( double scale ) const; - //////////////////////////// - // Drawing Methods - //////////////////////////// - public: - void draw( QPainter* painter ) const; - QPainterPath hoverPath( double scale ) const; + //////////////////////////// + // Private Data + //////////////////////////// +private: + LabelModelObject* mOwner; - - //////////////////////////// - // Private Data - //////////////////////////// - private: - LabelModelObject* mOwner; - - QVector mDashes; - QPen mPen1; - QPen mPen2; + QVector mDashes; + QPen mPen1; + QPen mPen2; - }; +}; -} -#endif // glabels_Outline_h +#endif // Outline_h diff --git a/glabels/PageRenderer.cpp b/glabels/PageRenderer.cpp index 32e4f00..bb6cc5a 100644 --- a/glabels/PageRenderer.cpp +++ b/glabels/PageRenderer.cpp @@ -36,220 +36,215 @@ namespace } -namespace glabels +PageRenderer::PageRenderer() + : mModel(0), mNLabels(0), mStartLabel(0), + mPrintOutlines(false), mPrintCropMarks(false), mPrintReverse(false), + mIPage(0), mNPages(0) { - - PageRenderer::PageRenderer() - : mModel(0), mNLabels(0), mStartLabel(0), - mPrintOutlines(false), mPrintCropMarks(false), mPrintReverse(false), - mIPage(0), mNPages(0) - { - } +} - void PageRenderer::setModel( const LabelModel* model ) - { - mModel = model; - mOrigins = mModel->frame()->getOrigins(); - mNLabelsPerPage = mModel->frame()->nLabels(); - updateNPages(); - } +void PageRenderer::setModel( const LabelModel* model ) +{ + mModel = model; + mOrigins = mModel->frame()->getOrigins(); + mNLabelsPerPage = mModel->frame()->nLabels(); + updateNPages(); +} - void PageRenderer::setNLabels( int nLabels ) - { - mNLabels = nLabels; - updateNPages(); - } +void PageRenderer::setNLabels( int nLabels ) +{ + mNLabels = nLabels; + updateNPages(); +} - void PageRenderer::setStartLabel( int startLabel ) - { - mStartLabel = startLabel; - updateNPages(); - } +void PageRenderer::setStartLabel( int startLabel ) +{ + mStartLabel = startLabel; + updateNPages(); +} - void PageRenderer::setPrintOutlines( bool printOutlinesFlag ) - { - mPrintOutlines = printOutlinesFlag; - } +void PageRenderer::setPrintOutlines( bool printOutlinesFlag ) +{ + mPrintOutlines = printOutlinesFlag; +} - void PageRenderer::setPrintCropMarks( bool printCropMarksFlag ) - { - mPrintCropMarks = printCropMarksFlag; - } +void PageRenderer::setPrintCropMarks( bool printCropMarksFlag ) +{ + mPrintCropMarks = printCropMarksFlag; +} - void PageRenderer::setPrintReverse( bool printReverseFlag ) - { - mPrintReverse = printReverseFlag; - } +void PageRenderer::setPrintReverse( bool printReverseFlag ) +{ + mPrintReverse = printReverseFlag; +} - void PageRenderer::setIPage( int iPage ) - { - mIPage = iPage; - } +void PageRenderer::setIPage( int iPage ) +{ + mIPage = iPage; +} - int PageRenderer::nPages() const - { - return mNPages; - } +int PageRenderer::nPages() const +{ + return mNPages; +} - QRectF PageRenderer::pageRect() const +QRectF PageRenderer::pageRect() const +{ + if ( mModel ) { - if ( mModel ) - { - return QRectF( 0, 0, mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() ); - } - else - { - return QRectF( 0, 0, 0, 0 ); - } + return QRectF( 0, 0, mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() ); } + else + { + return QRectF( 0, 0, 0, 0 ); + } +} - void PageRenderer::updateNPages() - { - if ( mModel ) - { - /// @TODO merge case - - int lastLabel = mStartLabel + mNLabels; - - mNPages = lastLabel / mNLabelsPerPage; - if ( lastLabel % mNLabelsPerPage ) - { - mNPages++; - } - } - else - { - mNPages = 0; - } - } - - - /// - /// Print page using persistent page number - /// - void PageRenderer::printPage( QPainter* painter ) const - { - printPage( painter, mIPage ); - } - - - /// - /// Print page - /// - void PageRenderer::printPage( QPainter* painter, int iPage ) const - { - if ( mModel ) - { - /// @TODO merge case - - printSimplePage( painter, iPage ); - } - } - - - void PageRenderer::printSimplePage( QPainter* painter, int iPage ) const - { - int iStart = 0; - int iEnd = mNLabelsPerPage; - - if ( iPage == 0 ) - { - iStart = mStartLabel; - } - - int lastLabel = mStartLabel + mNLabels; - if ( (lastLabel / mNLabelsPerPage) == iPage ) - { - iEnd = lastLabel % mNLabelsPerPage; - } - - printCropMarks( painter ); - - for ( int i = iStart; i < iEnd; i++ ) - { - painter->save(); - painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() ); - - painter->save(); - clipLabel( painter ); - - printLabel( painter, 0 ); - - painter->restore(); // From before clip - - printOutline( painter ); - - painter->restore(); // From before translation - } - } - - - void PageRenderer::printMergePage( QPainter* painter, int iPage ) const +void PageRenderer::updateNPages() +{ + if ( mModel ) { /// @TODO merge case - } - - - void PageRenderer::printCropMarks( QPainter* painter ) const - { - if ( mPrintCropMarks ) - { - // TODO - } - } - - - void PageRenderer::printOutline( QPainter* painter ) const - { - if ( mPrintOutlines ) - { - painter->save(); - - painter->setBrush( QBrush( Qt::NoBrush ) ); - painter->setPen( QPen( labelOutlineColor, labelOutlineWidth ) ); - - painter->drawPath( mModel->frame()->path() ); - painter->restore(); + int lastLabel = mStartLabel + mNLabels; + + mNPages = lastLabel / mNLabelsPerPage; + if ( lastLabel % mNLabelsPerPage ) + { + mNPages++; } } + else + { + mNPages = 0; + } +} - void PageRenderer::clipLabel( QPainter* painter ) const +/// +/// Print page using persistent page number +/// +void PageRenderer::printPage( QPainter* painter ) const +{ + printPage( painter, mIPage ); +} + + +/// +/// Print page +/// +void PageRenderer::printPage( QPainter* painter, int iPage ) const +{ + if ( mModel ) { - // TODO: add clipPath() method to frame + /// @TODO merge case + + printSimplePage( painter, iPage ); + } +} + + +void PageRenderer::printSimplePage( QPainter* painter, int iPage ) const +{ + int iStart = 0; + int iEnd = mNLabelsPerPage; + + if ( iPage == 0 ) + { + iStart = mStartLabel; } + int lastLabel = mStartLabel + mNLabels; + if ( (lastLabel / mNLabelsPerPage) == iPage ) + { + iEnd = lastLabel % mNLabelsPerPage; + } + + printCropMarks( painter ); + + for ( int i = iStart; i < iEnd; i++ ) + { + painter->save(); + painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() ); + + painter->save(); + clipLabel( painter ); + + printLabel( painter, 0 ); + + painter->restore(); // From before clip + + printOutline( painter ); + + painter->restore(); // From before translation + } +} + - void PageRenderer::printLabel( QPainter* painter, MergeRecord* record ) const +void PageRenderer::printMergePage( QPainter* painter, int iPage ) const +{ + /// @TODO merge case +} + + +void PageRenderer::printCropMarks( QPainter* painter ) const +{ + if ( mPrintCropMarks ) + { + // TODO + } +} + + +void PageRenderer::printOutline( QPainter* painter ) const +{ + if ( mPrintOutlines ) { painter->save(); - if ( mModel->rotate() ) - { - painter->rotate( 90.0 ); - painter->translate( 0, mModel->h().pt() ); - } - - if ( mPrintReverse ) - { - painter->translate( mModel->w().pt(), 0 ); - painter->scale( -1, 1 ); - } - - mModel->draw( painter, false, record ); + painter->setBrush( QBrush( Qt::NoBrush ) ); + painter->setPen( QPen( labelOutlineColor, labelOutlineWidth ) ); + painter->drawPath( mModel->frame()->path() ); + painter->restore(); } - +} + + +void PageRenderer::clipLabel( QPainter* painter ) const +{ + // TODO: add clipPath() method to frame +} + + +void PageRenderer::printLabel( QPainter* painter, MergeRecord* record ) const +{ + painter->save(); + + if ( mModel->rotate() ) + { + painter->rotate( 90.0 ); + painter->translate( 0, mModel->h().pt() ); + } + + if ( mPrintReverse ) + { + painter->translate( mModel->w().pt(), 0 ); + painter->scale( -1, 1 ); + } + + mModel->draw( painter, false, record ); + + painter->restore(); } diff --git a/glabels/PageRenderer.h b/glabels/PageRenderer.h index b18fc77..d41896d 100644 --- a/glabels/PageRenderer.h +++ b/glabels/PageRenderer.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_PageRenderer_h -#define glabels_PageRenderer_h +#ifndef PageRenderer_h +#define PageRenderer_h #include "libglabels/Point.h" @@ -31,72 +31,69 @@ class QPainter; // Forward reference -namespace glabels +class LabelModel; // Forward reference +class MergeRecord; // Forward reference + + +/// +/// PageRenderer Widget +/// +class PageRenderer { - class LabelModel; // Forward reference - class MergeRecord; // Forward reference + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + PageRenderer(); - /// - /// PageRenderer Widget - /// - class PageRenderer - { - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - PageRenderer(); + ///////////////////////////////// + // Public Methods + ///////////////////////////////// +public: + void setModel( const LabelModel* model ); + void setNLabels( int nLabels ); + void setStartLabel( int startLabel ); + void setPrintOutlines( bool printOutlinesFlag ); + void setPrintCropMarks( bool printCropMarksFlag ); + void setPrintReverse( bool printReverseFlag ); + void setIPage( int iPage ); + int nPages() const; + QRectF pageRect() const; + void printPage( QPainter* painter ) const; + void printPage( QPainter* painter, int iPage ) const; - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - void setModel( const LabelModel* model ); - void setNLabels( int nLabels ); - void setStartLabel( int startLabel ); - void setPrintOutlines( bool printOutlinesFlag ); - void setPrintCropMarks( bool printCropMarksFlag ); - void setPrintReverse( bool printReverseFlag ); - void setIPage( int iPage ); - int nPages() const; - QRectF pageRect() const; - void printPage( QPainter* painter ) const; - void printPage( QPainter* painter, int iPage ) const; + ///////////////////////////////// + // Internal Methods + ///////////////////////////////// +private: + void updateNPages(); + void printSimplePage( QPainter* painter, int iPage ) const; + void printMergePage( QPainter* painter, int iPage ) const; + void printCropMarks( QPainter* painter ) const; + void printOutline( QPainter* painter ) const; + void clipLabel( QPainter* painter ) const; + void printLabel( QPainter* painter, MergeRecord* record ) const; - ///////////////////////////////// - // Internal Methods - ///////////////////////////////// - private: - void updateNPages(); - void printSimplePage( QPainter* painter, int iPage ) const; - void printMergePage( QPainter* painter, int iPage ) const; - void printCropMarks( QPainter* painter ) const; - void printOutline( QPainter* painter ) const; - void clipLabel( QPainter* painter ) const; - void printLabel( QPainter* painter, MergeRecord* record ) const; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + const LabelModel* mModel; + int mNLabels; + int mStartLabel; + bool mPrintOutlines; + bool mPrintCropMarks; + bool mPrintReverse; + int mIPage; + + int mNPages; + int mNLabelsPerPage; + + QVector mOrigins; +}; - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - const LabelModel* mModel; - int mNLabels; - int mStartLabel; - bool mPrintOutlines; - bool mPrintCropMarks; - bool mPrintReverse; - int mIPage; - - int mNPages; - int mNLabelsPerPage; - - QVector mOrigins; - }; - -} - -#endif // glabels_PageRenderer_h +#endif // PageRenderer_h diff --git a/glabels/Preview.cpp b/glabels/Preview.cpp index 53bf440..d64f46d 100644 --- a/glabels/Preview.cpp +++ b/glabels/Preview.cpp @@ -47,155 +47,149 @@ namespace } -namespace glabels +/// +/// Constructor +/// +Preview::Preview( QWidget *parent ) + : mModel(0), mRenderer(0), QGraphicsView(parent) { + mScene = new QGraphicsScene(); + setScene( mScene ); - /// - /// Constructor - /// - Preview::Preview( QWidget *parent ) - : mModel(0), mRenderer(0), QGraphicsView(parent) - { - mScene = new QGraphicsScene(); - setScene( mScene ); - - setAttribute(Qt::WA_TranslucentBackground); - viewport()->setAutoFillBackground(false); - - setFrameStyle( QFrame::NoFrame ); - setRenderHints( QPainter::Antialiasing ); - } - - - /// - /// Set model - /// - void Preview::setModel( const LabelModel* model ) - { - mModel = model; - - clearScene(); - - if ( mModel != NULL ) - { - // Set scene up with a 5% margin around paper - libglabels::Distance x = -0.05 * mModel->tmplate()->pageWidth(); - libglabels::Distance y = -0.05 * mModel->tmplate()->pageHeight(); - libglabels::Distance w = 1.10 * mModel->tmplate()->pageWidth(); - libglabels::Distance h = 1.10 * mModel->tmplate()->pageHeight(); - - mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() ); - fitInView( mScene->sceneRect(), Qt::KeepAspectRatio ); - - drawPaper( mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() ); - drawLabels(); - drawPreviewOverlay(); - } - } - - - /// - /// Set renderer - /// - void Preview::setRenderer( const PageRenderer* renderer ) - { - mRenderer = renderer; - } - - - /// - /// Resize Event Handler - /// - void Preview::resizeEvent( QResizeEvent* event ) - { - fitInView( mScene->sceneRect(), Qt::KeepAspectRatio ); - } - - - /// - /// Clear View - /// - void Preview::clearScene() - { - foreach ( QGraphicsItem *item, mScene->items() ) - { - mScene->removeItem( item ); - delete item; - } - } - - - /// - /// Draw Paper - /// - void Preview::drawPaper( const libglabels::Distance& pw, const libglabels::Distance& ph ) - { - QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(); - shadowEffect->setColor( shadowColor ); - shadowEffect->setOffset( shadowOffsetPixels ); - shadowEffect->setBlurRadius( shadowRadiusPixels ); - - QBrush brush( paperColor ); - QPen pen( paperOutlineColor ); - pen.setCosmetic( true ); - pen.setWidthF( paperOutlineWidthPixels ); - - QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw.pt(), ph.pt() ); - pageItem->setBrush( brush ); - pageItem->setPen( pen ); - pageItem->setGraphicsEffect( shadowEffect ); - - mScene->addItem( pageItem ); - } - - - /// - /// Draw Labels on Paper - /// - void Preview::drawLabels() - { - libglabels::Frame *frame = mModel->tmplate()->frames().first(); - - foreach (libglabels::Point origin, frame->getOrigins() ) - { - drawLabel( origin.x(), origin.y(), frame->path() ); - } - } - - - /// - /// Draw a Single Label at x,y - /// - void Preview::drawLabel( const libglabels::Distance& x, - const libglabels::Distance& y, - const QPainterPath& path ) - { - QBrush brush( Qt::NoBrush ); - QPen pen( labelOutlineColor ); - pen.setStyle( Qt::DotLine ); - pen.setCosmetic( true ); - pen.setWidthF( labelOutlineWidthPixels ); - - QGraphicsPathItem *labelOutlineItem = new QGraphicsPathItem( path ); - labelOutlineItem->setBrush( brush ); - labelOutlineItem->setPen( pen ); - labelOutlineItem->setPos( x.pt(), y.pt() ); - - mScene->addItem( labelOutlineItem ); - } - - - /// - /// Draw Preview Overlay - /// - void Preview::drawPreviewOverlay() - { - if ( mRenderer ) - { - PreviewOverlayItem* overlayItem = new PreviewOverlayItem( mRenderer ); - mScene->addItem( overlayItem ); - } - } - + setAttribute(Qt::WA_TranslucentBackground); + viewport()->setAutoFillBackground(false); + setFrameStyle( QFrame::NoFrame ); + setRenderHints( QPainter::Antialiasing ); +} + + +/// +/// Set model +/// +void Preview::setModel( const LabelModel* model ) +{ + mModel = model; + + clearScene(); + + if ( mModel != NULL ) + { + // Set scene up with a 5% margin around paper + glabels::Distance x = -0.05 * mModel->tmplate()->pageWidth(); + glabels::Distance y = -0.05 * mModel->tmplate()->pageHeight(); + glabels::Distance w = 1.10 * mModel->tmplate()->pageWidth(); + glabels::Distance h = 1.10 * mModel->tmplate()->pageHeight(); + + mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() ); + fitInView( mScene->sceneRect(), Qt::KeepAspectRatio ); + + drawPaper( mModel->tmplate()->pageWidth(), mModel->tmplate()->pageHeight() ); + drawLabels(); + drawPreviewOverlay(); + } +} + + +/// +/// Set renderer +/// +void Preview::setRenderer( const PageRenderer* renderer ) +{ + mRenderer = renderer; +} + + +/// +/// Resize Event Handler +/// +void Preview::resizeEvent( QResizeEvent* event ) +{ + fitInView( mScene->sceneRect(), Qt::KeepAspectRatio ); +} + + +/// +/// Clear View +/// +void Preview::clearScene() +{ + foreach ( QGraphicsItem *item, mScene->items() ) + { + mScene->removeItem( item ); + delete item; + } +} + + +/// +/// Draw Paper +/// +void Preview::drawPaper( const glabels::Distance& pw, const glabels::Distance& ph ) +{ + QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(); + shadowEffect->setColor( shadowColor ); + shadowEffect->setOffset( shadowOffsetPixels ); + shadowEffect->setBlurRadius( shadowRadiusPixels ); + + QBrush brush( paperColor ); + QPen pen( paperOutlineColor ); + pen.setCosmetic( true ); + pen.setWidthF( paperOutlineWidthPixels ); + + QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw.pt(), ph.pt() ); + pageItem->setBrush( brush ); + pageItem->setPen( pen ); + pageItem->setGraphicsEffect( shadowEffect ); + + mScene->addItem( pageItem ); +} + + +/// +/// Draw Labels on Paper +/// +void Preview::drawLabels() +{ + glabels::Frame *frame = mModel->tmplate()->frames().first(); + + foreach (glabels::Point origin, frame->getOrigins() ) + { + drawLabel( origin.x(), origin.y(), frame->path() ); + } +} + + +/// +/// Draw a Single Label at x,y +/// +void Preview::drawLabel( const glabels::Distance& x, + const glabels::Distance& y, + const QPainterPath& path ) +{ + QBrush brush( Qt::NoBrush ); + QPen pen( labelOutlineColor ); + pen.setStyle( Qt::DotLine ); + pen.setCosmetic( true ); + pen.setWidthF( labelOutlineWidthPixels ); + + QGraphicsPathItem *labelOutlineItem = new QGraphicsPathItem( path ); + labelOutlineItem->setBrush( brush ); + labelOutlineItem->setPen( pen ); + labelOutlineItem->setPos( x.pt(), y.pt() ); + + mScene->addItem( labelOutlineItem ); +} + + +/// +/// Draw Preview Overlay +/// +void Preview::drawPreviewOverlay() +{ + if ( mRenderer ) + { + PreviewOverlayItem* overlayItem = new PreviewOverlayItem( mRenderer ); + mScene->addItem( overlayItem ); + } } diff --git a/glabels/Preview.h b/glabels/Preview.h index 16f9dcb..686e00a 100644 --- a/glabels/Preview.h +++ b/glabels/Preview.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_Preview_h -#define glabels_Preview_h +#ifndef Preview_h +#define Preview_h #include #include @@ -27,65 +27,62 @@ #include "PageRenderer.h" -namespace glabels +class LabelModel; // Forward reference + + +/// +/// Preview Widget +/// +class Preview : public QGraphicsView { - class LabelModel; // Forward reference + Q_OBJECT - /// - /// Preview Widget - /// - class Preview : public QGraphicsView - { - Q_OBJECT + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + Preview( QWidget *parent = 0 ); - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - Preview( QWidget *parent = 0 ); + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + void setModel( const LabelModel* model ); + void setRenderer( const PageRenderer* renderer ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - void setModel( const LabelModel* model ); - void setRenderer( const PageRenderer* renderer ); - - - ///////////////////////////////////// - // Event handlers - ///////////////////////////////////// - protected: - void resizeEvent( QResizeEvent* event ); + ///////////////////////////////////// + // Event handlers + ///////////////////////////////////// +protected: + void resizeEvent( QResizeEvent* event ); - ///////////////////////////////// - // Internal Methods - ///////////////////////////////// - private: - void clearScene(); - void drawPaper( const libglabels::Distance& pw, const libglabels::Distance& ph ); - void drawLabels(); - void drawLabel( const libglabels::Distance& x, - const libglabels::Distance& y, - const QPainterPath& path ); + ///////////////////////////////// + // Internal Methods + ///////////////////////////////// +private: + void clearScene(); + void drawPaper( const glabels::Distance& pw, const glabels::Distance& ph ); + void drawLabels(); + void drawLabel( const glabels::Distance& x, + const glabels::Distance& y, + const QPainterPath& path ); - void drawPreviewOverlay(); + void drawPreviewOverlay(); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - const LabelModel* mModel; - const PageRenderer* mRenderer; - QGraphicsScene* mScene; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + const LabelModel* mModel; + const PageRenderer* mRenderer; + QGraphicsScene* mScene; - }; +}; -} -#endif // glabels_Preview_h +#endif // Preview_h diff --git a/glabels/PreviewOverlayItem.cpp b/glabels/PreviewOverlayItem.cpp index 9e22d68..d61b1c5 100644 --- a/glabels/PreviewOverlayItem.cpp +++ b/glabels/PreviewOverlayItem.cpp @@ -23,24 +23,19 @@ #include "PageRenderer.h" -namespace glabels +PreviewOverlayItem::PreviewOverlayItem( const PageRenderer* renderer, QGraphicsItem* parent ) + : QGraphicsItem(parent), mRenderer(renderer) { - - PreviewOverlayItem::PreviewOverlayItem( const PageRenderer* renderer, QGraphicsItem* parent ) - : QGraphicsItem(parent), mRenderer(renderer) - { - } - - - QRectF PreviewOverlayItem::boundingRect() const - { - return mRenderer->pageRect(); - } - - - void PreviewOverlayItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) - { - mRenderer->printPage( painter ); - } - +} + + +QRectF PreviewOverlayItem::boundingRect() const +{ + return mRenderer->pageRect(); +} + + +void PreviewOverlayItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) +{ + mRenderer->printPage( painter ); } diff --git a/glabels/PreviewOverlayItem.h b/glabels/PreviewOverlayItem.h index e74210e..f54310b 100644 --- a/glabels/PreviewOverlayItem.h +++ b/glabels/PreviewOverlayItem.h @@ -18,46 +18,43 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_PreviewOverlayItem_h -#define glabels_PreviewOverlayItem_h +#ifndef PreviewOverlayItem_h +#define PreviewOverlayItem_h #include -namespace glabels +class PageRenderer; // Forward reference + + +/// +/// PreviewOverlayItem Widget +/// +class PreviewOverlayItem : public QGraphicsItem { - class PageRenderer; // Forward reference + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + PreviewOverlayItem( const PageRenderer* renderer, QGraphicsItem* parent = 0 ); - /// - /// PreviewOverlayItem Widget - /// - class PreviewOverlayItem : public QGraphicsItem - { - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - PreviewOverlayItem( const PageRenderer* renderer, QGraphicsItem* parent = 0 ); - - - ///////////////////////////////////// - // Virtual method implementations - ///////////////////////////////////// - public: - QRectF boundingRect() const; - void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ); + ///////////////////////////////////// + // Virtual method implementations + ///////////////////////////////////// +public: + QRectF boundingRect() const; + void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - const PageRenderer* mRenderer; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + const PageRenderer* mRenderer; - }; +}; -} -#endif // glabels_PreviewOverlayItem_h +#endif // PreviewOverlayItem_h diff --git a/glabels/PrintView.cpp b/glabels/PrintView.cpp index 68227b0..d2c68bf 100644 --- a/glabels/PrintView.cpp +++ b/glabels/PrintView.cpp @@ -26,150 +26,145 @@ #include -namespace glabels +/// +/// Constructor +/// +PrintView::PrintView( QWidget *parent ) + : QWidget(parent), mModel(0), mBlocked(false) { + setupUi( this ); + preview->setRenderer( &mRenderer ); - /// - /// Constructor - /// - PrintView::PrintView( QWidget *parent ) - : QWidget(parent), mModel(0), mBlocked(false) - { - setupUi( this ); - preview->setRenderer( &mRenderer ); - - mPrinter = new QPrinter( QPrinter::HighResolution ); - } - - - /// - /// Destructor - /// - PrintView::~PrintView() - { - delete mPrinter; - } - - - /// - /// Set Model - /// - void PrintView::setModel( LabelModel* model ) - { - mModel = model; - - // TODO set visibility based on merge selection - copiesBox->setVisible( true ); - mergeBox->setVisible( false ); - - connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) ); - connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) ); - - onLabelSizeChanged(); - onFormChanged(); - } - - - /// - /// Label size changed handler - /// - void PrintView::onLabelSizeChanged() - { - preview->setModel( mModel ); - mRenderer.setModel( mModel ); - } - - - /// - /// Label changed handler - /// - void PrintView::onLabelChanged() - { - preview->update(); - } - - - /// - /// Form changed handler - /// - void PrintView::onFormChanged() - { - if ( !mBlocked ) - { - mBlocked = true; - - int nLabelsPerPage = mModel->frame()->nLabels(); - copiesFromSpin->setRange( 1, nLabelsPerPage ); - copiesToSpin->setRange( copiesFromSpin->value(), nLabelsPerPage ); - - // TODO select between simple and merge - if ( copiesSheetsRadio->isChecked() ) - { - mRenderer.setNLabels( copiesSheetsSpin->value()*nLabelsPerPage ); - mRenderer.setStartLabel( 0 ); - copiesFromSpin->setValue( 1 ); - copiesToSpin->setValue( nLabelsPerPage ); - } - else - { - mRenderer.setNLabels( copiesToSpin->value() - copiesFromSpin->value() + 1 ); - mRenderer.setStartLabel( copiesFromSpin->value() - 1 ); - copiesSheetsSpin->setValue( 1 ); - } - - mRenderer.setPrintOutlines( printOutlinesCheck->isChecked() ); - mRenderer.setPrintCropMarks( printCropMarksCheck->isChecked() ); - mRenderer.setPrintReverse( printReverseCheck->isChecked() ); - - pageSpin->setRange( 1, mRenderer.nPages() ); - nPagesLabel->setText( QString::number( mRenderer.nPages() ) ); - - mRenderer.setIPage( pageSpin->value() - 1 ); - - preview->update(); - - mBlocked = false; - } - } - - - /// - /// Print Button Clicked handler - /// - void PrintView::onPrintButtonClicked() - { - QSizeF pageSize( mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() ); - mPrinter->setPaperSize( pageSize, QPrinter::Point ); - mPrinter->setFullPage( true ); - mPrinter->setPageMargins( 0, 0, 0, 0, QPrinter::Point ); - - QPrintDialog printDialog( mPrinter, this ); - - printDialog.setOption( QAbstractPrintDialog::PrintToFile, true ); - printDialog.setOption( QAbstractPrintDialog::PrintSelection, false ); - printDialog.setOption( QAbstractPrintDialog::PrintPageRange, false ); - printDialog.setOption( QAbstractPrintDialog::PrintShowPageSize, true ); - printDialog.setOption( QAbstractPrintDialog::PrintCollateCopies, false ); - printDialog.setOption( QAbstractPrintDialog::PrintCurrentPage, false ); - - if ( printDialog.exec() == QDialog::Accepted ) - { - QPainter painter( mPrinter ); - - QSizeF sizePx = mPrinter->paperSize( QPrinter::DevicePixel ); - QSizeF sizePts = mPrinter->paperSize( QPrinter::Point ); - painter.scale( sizePx.width()/sizePts.width(), sizePx.height()/sizePts.height() ); - - for ( int iPage = 0; iPage < mRenderer.nPages(); iPage++ ) - { - if ( iPage ) - { - mPrinter->newPage(); - } - - mRenderer.printPage( &painter, iPage ); - } - } - } - + mPrinter = new QPrinter( QPrinter::HighResolution ); +} + + +/// +/// Destructor +/// +PrintView::~PrintView() +{ + delete mPrinter; +} + + +/// +/// Set Model +/// +void PrintView::setModel( LabelModel* model ) +{ + mModel = model; + + // TODO set visibility based on merge selection + copiesBox->setVisible( true ); + mergeBox->setVisible( false ); + + connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) ); + connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) ); + + onLabelSizeChanged(); + onFormChanged(); +} + + +/// +/// Label size changed handler +/// +void PrintView::onLabelSizeChanged() +{ + preview->setModel( mModel ); + mRenderer.setModel( mModel ); +} + + +/// +/// Label changed handler +/// +void PrintView::onLabelChanged() +{ + preview->update(); +} + + +/// +/// Form changed handler +/// +void PrintView::onFormChanged() +{ + if ( !mBlocked ) + { + mBlocked = true; + + int nLabelsPerPage = mModel->frame()->nLabels(); + copiesFromSpin->setRange( 1, nLabelsPerPage ); + copiesToSpin->setRange( copiesFromSpin->value(), nLabelsPerPage ); + + // TODO select between simple and merge + if ( copiesSheetsRadio->isChecked() ) + { + mRenderer.setNLabels( copiesSheetsSpin->value()*nLabelsPerPage ); + mRenderer.setStartLabel( 0 ); + copiesFromSpin->setValue( 1 ); + copiesToSpin->setValue( nLabelsPerPage ); + } + else + { + mRenderer.setNLabels( copiesToSpin->value() - copiesFromSpin->value() + 1 ); + mRenderer.setStartLabel( copiesFromSpin->value() - 1 ); + copiesSheetsSpin->setValue( 1 ); + } + + mRenderer.setPrintOutlines( printOutlinesCheck->isChecked() ); + mRenderer.setPrintCropMarks( printCropMarksCheck->isChecked() ); + mRenderer.setPrintReverse( printReverseCheck->isChecked() ); + + pageSpin->setRange( 1, mRenderer.nPages() ); + nPagesLabel->setText( QString::number( mRenderer.nPages() ) ); + + mRenderer.setIPage( pageSpin->value() - 1 ); + + preview->update(); + + mBlocked = false; + } +} + + +/// +/// Print Button Clicked handler +/// +void PrintView::onPrintButtonClicked() +{ + QSizeF pageSize( mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() ); + mPrinter->setPaperSize( pageSize, QPrinter::Point ); + mPrinter->setFullPage( true ); + mPrinter->setPageMargins( 0, 0, 0, 0, QPrinter::Point ); + + QPrintDialog printDialog( mPrinter, this ); + + printDialog.setOption( QAbstractPrintDialog::PrintToFile, true ); + printDialog.setOption( QAbstractPrintDialog::PrintSelection, false ); + printDialog.setOption( QAbstractPrintDialog::PrintPageRange, false ); + printDialog.setOption( QAbstractPrintDialog::PrintShowPageSize, true ); + printDialog.setOption( QAbstractPrintDialog::PrintCollateCopies, false ); + printDialog.setOption( QAbstractPrintDialog::PrintCurrentPage, false ); + + if ( printDialog.exec() == QDialog::Accepted ) + { + QPainter painter( mPrinter ); + + QSizeF sizePx = mPrinter->paperSize( QPrinter::DevicePixel ); + QSizeF sizePts = mPrinter->paperSize( QPrinter::Point ); + painter.scale( sizePx.width()/sizePts.width(), sizePx.height()/sizePts.height() ); + + for ( int iPage = 0; iPage < mRenderer.nPages(); iPage++ ) + { + if ( iPage ) + { + mPrinter->newPage(); + } + + mRenderer.printPage( &painter, iPage ); + } + } } diff --git a/glabels/PrintView.h b/glabels/PrintView.h index 89dc4eb..fbbac71 100644 --- a/glabels/PrintView.h +++ b/glabels/PrintView.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_PrintView_h -#define glabels_PrintView_h +#ifndef PrintView_h +#define PrintView_h #include "ui_PrintView.h" #include "PageRenderer.h" @@ -27,55 +27,52 @@ #include -namespace glabels -{ - class LabelModel; // Forward reference +class LabelModel; // Forward reference - /// - /// Print View Widget - /// - class PrintView : public QWidget, public Ui_PrintView - { - Q_OBJECT +/// +/// Print View Widget +/// +class PrintView : public QWidget, public Ui_PrintView +{ + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - PrintView( QWidget *parent = 0 ); - ~PrintView(); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + PrintView( QWidget *parent = 0 ); + ~PrintView(); - ///////////////////////////////// - // Public methods - ///////////////////////////////// - void setModel( LabelModel* model ); + ///////////////////////////////// + // Public methods + ///////////////////////////////// + void setModel( LabelModel* model ); - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onLabelChanged(); - void onLabelSizeChanged(); - void onFormChanged(); - void onPrintButtonClicked(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onLabelChanged(); + void onLabelSizeChanged(); + void onFormChanged(); + void onPrintButtonClicked(); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - LabelModel* mModel; - QPrinter* mPrinter; - PageRenderer mRenderer; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + LabelModel* mModel; + QPrinter* mPrinter; + PageRenderer mRenderer; - bool mBlocked; + bool mBlocked; - }; +}; -} -#endif // glabels_PrintView_h +#endif // PrintView_h diff --git a/glabels/PropertiesView.cpp b/glabels/PropertiesView.cpp index 96756f5..d5845b7 100644 --- a/glabels/PropertiesView.cpp +++ b/glabels/PropertiesView.cpp @@ -27,167 +27,162 @@ #include -namespace glabels +/// +/// Constructor +/// +PropertiesView::PropertiesView( QWidget *parent ) + : QWidget(parent), mModel(0) { + setupUi( this ); - /// - /// Constructor - /// - PropertiesView::PropertiesView( QWidget *parent ) - : QWidget(parent), mModel(0) + similarBrowser->setAttribute(Qt::WA_TranslucentBackground); + similarBrowser->viewport()->setAutoFillBackground(false); +} + + +/// +/// Destructor +/// +PropertiesView::~PropertiesView() +{ +} + + +/// +/// Set Model +/// +void PropertiesView::setModel( LabelModel* model ) +{ + mModel = model; + + connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) ); + + onLabelSizeChanged(); +} + + +/// +/// Label size changed handler +/// +void PropertiesView::onLabelSizeChanged() +{ + const glabels::Template *tmplate = mModel->tmplate(); + const glabels::Frame *frame = tmplate->frames().first(); + bool isRotated = mModel->rotate(); + + preview->setTemplate( tmplate ); + preview->setRotate( isRotated ); + + const glabels::Vendor *vendor = glabels::Db::lookupVendorFromName( tmplate->brand() ); + if ( (vendor != NULL) && (vendor->url() != NULL) ) { - setupUi( this ); - - similarBrowser->setAttribute(Qt::WA_TranslucentBackground); - similarBrowser->viewport()->setAutoFillBackground(false); + QString markup = "" + vendor->name() + ""; + vendorLabel->setText( markup ); + } + else + { + vendorLabel->setText( tmplate->brand() ); } - - /// - /// Destructor - /// - PropertiesView::~PropertiesView() + if ( tmplate->productUrl() != NULL ) { + QString markup = "" + tmplate->part() + ""; + partLabel->setText( markup ); + } + else + { + partLabel->setText( tmplate->part() ); } + descriptionLabel->setText( tmplate->description() ); - /// - /// Set Model - /// - void PropertiesView::setModel( LabelModel* model ) + QString pgSizeString = glabels::Db::lookupPaperNameFromId( tmplate->paperId() ); + pageSizeLabel->setText( pgSizeString ); + + QString labelSizeString = frame->sizeDescription( glabels::Distance::Units::IN ); + labelSizeLabel->setText( labelSizeString ); + + QString layoutString = frame->layoutDescription(); + layoutLabel->setText( layoutString ); + + QStringList list = glabels::Db::getNameListOfSimilarTemplates( tmplate->name() ); + if ( list.isEmpty() ) { - mModel = model; + similarProductsGroupBox->hide(); + similarProductsNullBox->show(); + } + else + { + similarProductsGroupBox->show(); + similarProductsNullBox->hide(); - connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) ); - - onLabelSizeChanged(); + QString similarListString; + foreach ( QString name, list ) + { + similarListString += name + "\n"; + } + similarBrowser->setText( similarListString ); } - - /// - /// Label size changed handler - /// - void PropertiesView::onLabelSizeChanged() + orientationCombo->setEnabled( frame->w() != frame->h() ); + if ( frame->w() == frame->h() ) { - const libglabels::Template *tmplate = mModel->tmplate(); - const libglabels::Frame *frame = tmplate->frames().first(); - bool isRotated = mModel->rotate(); - - preview->setTemplate( tmplate ); - preview->setRotate( isRotated ); - - const libglabels::Vendor *vendor = libglabels::Db::lookupVendorFromName( tmplate->brand() ); - if ( (vendor != NULL) && (vendor->url() != NULL) ) - { - QString markup = "" + vendor->name() + ""; - vendorLabel->setText( markup ); - } - else - { - vendorLabel->setText( tmplate->brand() ); - } - - if ( tmplate->productUrl() != NULL ) - { - QString markup = "" + tmplate->part() + ""; - partLabel->setText( markup ); - } - else - { - partLabel->setText( tmplate->part() ); - } - - descriptionLabel->setText( tmplate->description() ); - - QString pgSizeString = libglabels::Db::lookupPaperNameFromId( tmplate->paperId() ); - pageSizeLabel->setText( pgSizeString ); - - QString labelSizeString = frame->sizeDescription( libglabels::Distance::Units::IN ); - labelSizeLabel->setText( labelSizeString ); - - QString layoutString = frame->layoutDescription(); - layoutLabel->setText( layoutString ); - - QStringList list = libglabels::Db::getNameListOfSimilarTemplates( tmplate->name() ); - if ( list.isEmpty() ) - { - similarProductsGroupBox->hide(); - similarProductsNullBox->show(); - } - else - { - similarProductsGroupBox->show(); - similarProductsNullBox->hide(); - - QString similarListString; - foreach ( QString name, list ) - { - similarListString += name + "\n"; - } - similarBrowser->setText( similarListString ); - } - - orientationCombo->setEnabled( frame->w() != frame->h() ); - if ( frame->w() == frame->h() ) - { - orientationCombo->setCurrentIndex(0); - } - else if ( frame->w() > frame->h() ) - { - orientationCombo->setCurrentIndex( isRotated ? 1 : 0 ); - } - else - { - orientationCombo->setCurrentIndex( isRotated ? 0 : 1 ); - } + orientationCombo->setCurrentIndex(0); } - - - /// - /// Form changed handler - /// - void PropertiesView::onFormChanged() + else if ( frame->w() > frame->h() ) { - const libglabels::Template *tmplate = mModel->tmplate(); - const libglabels::Frame *frame = tmplate->frames().first(); + orientationCombo->setCurrentIndex( isRotated ? 1 : 0 ); + } + else + { + orientationCombo->setCurrentIndex( isRotated ? 0 : 1 ); + } +} + +/// +/// Form changed handler +/// +void PropertiesView::onFormChanged() +{ + const glabels::Template *tmplate = mModel->tmplate(); + const glabels::Frame *frame = tmplate->frames().first(); + + if ( frame->w() == frame->h() ) + { + mModel->setRotate( false ); + } + else if ( frame->w() > frame->h() ) + { + int index = orientationCombo->currentIndex(); + mModel->setRotate( index == 1 ); + } + else + { + int index = orientationCombo->currentIndex(); + mModel->setRotate( index == 0 ); + } +} + + +/// +/// Change Product Button Clicked handler +/// +void PropertiesView::onChangeProductButtonClicked() +{ + SelectProductDialog selectProductDialog( this ); + selectProductDialog.exec(); + + const glabels::Template* tmplate = selectProductDialog.tmplate(); + if ( tmplate ) + { + mModel->setTmplate( tmplate ); + + // Don't rotate circular or round labels + const glabels::Frame *frame = tmplate->frames().first(); if ( frame->w() == frame->h() ) { mModel->setRotate( false ); } - else if ( frame->w() > frame->h() ) - { - int index = orientationCombo->currentIndex(); - mModel->setRotate( index == 1 ); - } - else - { - int index = orientationCombo->currentIndex(); - mModel->setRotate( index == 0 ); - } } - - - /// - /// Change Product Button Clicked handler - /// - void PropertiesView::onChangeProductButtonClicked() - { - SelectProductDialog selectProductDialog( this ); - selectProductDialog.exec(); - - const libglabels::Template* tmplate = selectProductDialog.tmplate(); - if ( tmplate ) - { - mModel->setTmplate( tmplate ); - - // Don't rotate circular or round labels - const libglabels::Frame *frame = tmplate->frames().first(); - if ( frame->w() == frame->h() ) - { - mModel->setRotate( false ); - } - } - } - } diff --git a/glabels/PropertiesView.h b/glabels/PropertiesView.h index d959149..e527001 100644 --- a/glabels/PropertiesView.h +++ b/glabels/PropertiesView.h @@ -18,56 +18,53 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_PropertiesView_h -#define glabels_PropertiesView_h +#ifndef PropertiesView_h +#define PropertiesView_h #include "ui_PropertiesView.h" -namespace glabels -{ - class LabelModel; // Forward reference +class LabelModel; // Forward reference - /// - /// Properties View Widget - /// - class PropertiesView : public QWidget, public Ui_PropertiesView - { - Q_OBJECT +/// +/// Properties View Widget +/// +class PropertiesView : public QWidget, public Ui_PropertiesView +{ + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - PropertiesView( QWidget *parent = 0 ); - ~PropertiesView(); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + PropertiesView( QWidget *parent = 0 ); + ~PropertiesView(); - ///////////////////////////////// - // Public methods - ///////////////////////////////// - void setModel( LabelModel* model ); + ///////////////////////////////// + // Public methods + ///////////////////////////////// + void setModel( LabelModel* model ); - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onLabelSizeChanged(); - void onFormChanged(); - void onChangeProductButtonClicked(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onLabelSizeChanged(); + void onFormChanged(); + void onChangeProductButtonClicked(); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - LabelModel* mModel; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + LabelModel* mModel; - }; +}; -} -#endif // glabels_PropertiesView_h +#endif // PropertiesView_h diff --git a/glabels/SelectProductDialog.cpp b/glabels/SelectProductDialog.cpp index 66ff7bc..c9e0134 100644 --- a/glabels/SelectProductDialog.cpp +++ b/glabels/SelectProductDialog.cpp @@ -26,108 +26,103 @@ #include "TemplatePickerItem.h" -namespace glabels +/// +/// Constructor +/// +SelectProductDialog::SelectProductDialog( QWidget *parent ) + : QDialog(parent), mCanceled(false) { + setupUi( this ); - /// - /// Constructor - /// - SelectProductDialog::SelectProductDialog( QWidget *parent ) - : QDialog(parent), mCanceled(false) - { - setupUi( this ); + // TODO: Set default based on locale and/or saved preferences + // Perhaps move to checkboxes + pageSizeIsoCheck->setChecked( false ); + pageSizeUsCheck->setChecked( true ); + pageSizeOtherCheck->setChecked( true ); - // TODO: Set default based on locale and/or saved preferences - // Perhaps move to checkboxes - pageSizeIsoCheck->setChecked( false ); - pageSizeUsCheck->setChecked( true ); - pageSizeOtherCheck->setChecked( true ); - - QList tmplates = libglabels::Db::templates(); - templatePicker->setTemplates( tmplates ); - - templatePicker->applyFilter( searchEntry->text(), - pageSizeIsoCheck->isChecked(), - pageSizeUsCheck->isChecked(), - pageSizeOtherCheck->isChecked() ); - } - - /// - /// Get selected template - /// - const libglabels::Template* SelectProductDialog::tmplate() const - { - if ( !mCanceled ) - { - return templatePicker->selectedTemplate(); - } - else - { - return 0; - } - } - - - /// - /// Search Entry Text Changed Slot - /// - void SelectProductDialog::onSearchEntryTextChanged() - { - templatePicker->applyFilter( searchEntry->text(), - pageSizeIsoCheck->isChecked(), - pageSizeUsCheck->isChecked(), - pageSizeOtherCheck->isChecked() ); - } - - - /// - /// Search Entry Text Changed Slot - /// - void SelectProductDialog::onSearchClearButtonClicked() - { - searchEntry->setText( "" ); - } - - - /// - /// Page Size Check Toggled Slot - /// - void SelectProductDialog::onPageSizeCheckToggled() - { - templatePicker->applyFilter( searchEntry->text(), - pageSizeIsoCheck->isChecked(), - pageSizeUsCheck->isChecked(), - pageSizeOtherCheck->isChecked() ); - } - - - /// - /// Template Picker Selection Changed Slot - /// - void SelectProductDialog::onTemplatePickerSelectionChanged() - { - const libglabels::Template *tmplate = templatePicker->selectedTemplate(); - - selectButton->setEnabled( tmplate != NULL ); - } - - - /// - /// Select Button Clicked Slot - /// - void SelectProductDialog::onSelectButtonClicked() - { - close(); - } - - - /// - /// Cancel Button Clicked Slot - /// - void SelectProductDialog::onCancelButtonClicked() - { - mCanceled = true; - close(); - } + QList tmplates = glabels::Db::templates(); + templatePicker->setTemplates( tmplates ); + templatePicker->applyFilter( searchEntry->text(), + pageSizeIsoCheck->isChecked(), + pageSizeUsCheck->isChecked(), + pageSizeOtherCheck->isChecked() ); +} + +/// +/// Get selected template +/// +const glabels::Template* SelectProductDialog::tmplate() const +{ + if ( !mCanceled ) + { + return templatePicker->selectedTemplate(); + } + else + { + return 0; + } +} + + +/// +/// Search Entry Text Changed Slot +/// +void SelectProductDialog::onSearchEntryTextChanged() +{ + templatePicker->applyFilter( searchEntry->text(), + pageSizeIsoCheck->isChecked(), + pageSizeUsCheck->isChecked(), + pageSizeOtherCheck->isChecked() ); +} + + +/// +/// Search Entry Text Changed Slot +/// +void SelectProductDialog::onSearchClearButtonClicked() +{ + searchEntry->setText( "" ); +} + + +/// +/// Page Size Check Toggled Slot +/// +void SelectProductDialog::onPageSizeCheckToggled() +{ + templatePicker->applyFilter( searchEntry->text(), + pageSizeIsoCheck->isChecked(), + pageSizeUsCheck->isChecked(), + pageSizeOtherCheck->isChecked() ); +} + + +/// +/// Template Picker Selection Changed Slot +/// +void SelectProductDialog::onTemplatePickerSelectionChanged() +{ + const glabels::Template *tmplate = templatePicker->selectedTemplate(); + + selectButton->setEnabled( tmplate != NULL ); +} + + +/// +/// Select Button Clicked Slot +/// +void SelectProductDialog::onSelectButtonClicked() +{ + close(); +} + + +/// +/// Cancel Button Clicked Slot +/// +void SelectProductDialog::onCancelButtonClicked() +{ + mCanceled = true; + close(); } diff --git a/glabels/SelectProductDialog.h b/glabels/SelectProductDialog.h index a4f0da1..b4540d9 100644 --- a/glabels/SelectProductDialog.h +++ b/glabels/SelectProductDialog.h @@ -18,56 +18,52 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_SelectProductDialog_h -#define glabels_SelectProductDialog_h +#ifndef SelectProductDialog_h +#define SelectProductDialog_h #include "ui_SelectProductDialog.h" -namespace glabels +/// +/// New Label Dialog Widget +/// +class SelectProductDialog : public QDialog, public Ui_SelectProductDialog { - - /// - /// New Label Dialog Widget - /// - class SelectProductDialog : public QDialog, public Ui_SelectProductDialog - { - Q_OBJECT + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - SelectProductDialog( QWidget *parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + SelectProductDialog( QWidget *parent = 0 ); - ///////////////////////////////// - // Accessors - ///////////////////////////////// - const libglabels::Template* tmplate() const; + ///////////////////////////////// + // Accessors + ///////////////////////////////// + const glabels::Template* tmplate() const; - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onSearchEntryTextChanged(); - void onSearchClearButtonClicked(); - void onPageSizeCheckToggled(); - void onTemplatePickerSelectionChanged(); - void onSelectButtonClicked(); - void onCancelButtonClicked(); + ///////////////////////////////// + // Slots + ///////////////////////////////// +private slots: + void onSearchEntryTextChanged(); + void onSearchClearButtonClicked(); + void onPageSizeCheckToggled(); + void onTemplatePickerSelectionChanged(); + void onSelectButtonClicked(); + void onCancelButtonClicked(); - ///////////////////////////////// - // Private data - ///////////////////////////////// - private: - bool mCanceled; + ///////////////////////////////// + // Private data + ///////////////////////////////// +private: + bool mCanceled; - }; +}; -} -#endif // glabels_SelectProductDialog_h +#endif // SelectProductDialog_h diff --git a/glabels/SimplePreview.cpp b/glabels/SimplePreview.cpp index e3cf8fa..ab0b616 100644 --- a/glabels/SimplePreview.cpp +++ b/glabels/SimplePreview.cpp @@ -51,207 +51,202 @@ namespace } -namespace glabels +/// +/// Constructor +/// +SimplePreview::SimplePreview( QWidget *parent ) + : mTmplate(NULL), mRotateFlag(false), QGraphicsView(parent) { + mScene = new QGraphicsScene(); + setScene( mScene ); - /// - /// Constructor - /// - SimplePreview::SimplePreview( QWidget *parent ) - : mTmplate(NULL), mRotateFlag(false), QGraphicsView(parent) - { - mScene = new QGraphicsScene(); - setScene( mScene ); - - setAttribute(Qt::WA_TranslucentBackground); - viewport()->setAutoFillBackground(false); - - setFrameStyle( QFrame::NoFrame ); - setRenderHints( QPainter::Antialiasing ); - } - - - /// - /// Template Property Setter - /// - void SimplePreview::setTemplate( const libglabels::Template *tmplate ) - { - mTmplate = tmplate; - update(); - } - - - /// - /// Rotate Property Setter - /// - void SimplePreview::setRotate( bool rotateFlag ) - { - mRotateFlag = rotateFlag; - update(); - } - - - /// - /// Resize Event Handler - /// - void SimplePreview::resizeEvent( QResizeEvent* event ) - { - fitInView( mScene->sceneRect(), Qt::KeepAspectRatio ); - } - - - /// - /// Update View - /// - void SimplePreview::update() - { - clearScene(); - - if ( mTmplate != NULL ) - { - // Set scene up with a 5% margin around paper - libglabels::Distance x = -0.05 * mTmplate->pageWidth(); - libglabels::Distance y = -0.05 * mTmplate->pageHeight(); - libglabels::Distance w = 1.10 * mTmplate->pageWidth(); - libglabels::Distance h = 1.10 * mTmplate->pageHeight(); - - mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() ); - fitInView( mScene->sceneRect(), Qt::KeepAspectRatio ); - - drawPaper( mTmplate->pageWidth(), mTmplate->pageHeight() ); - drawLabels(); - drawArrow(); - } - } - - - /// - /// Clear View - /// - void SimplePreview::clearScene() - { - foreach ( QGraphicsItem *item, mScene->items() ) - { - mScene->removeItem( item ); - delete item; - } - } - - - /// - /// Draw Paper - /// - void SimplePreview::drawPaper( const libglabels::Distance& pw, const libglabels::Distance& ph ) - { - QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(); - shadowEffect->setColor( shadowColor ); - shadowEffect->setOffset( shadowOffsetPixels ); - shadowEffect->setBlurRadius( shadowRadiusPixels ); - - QBrush brush( paperColor ); - QPen pen( paperOutlineColor ); - pen.setCosmetic( true ); - pen.setWidthF( paperOutlineWidthPixels ); - - QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw.pt(), ph.pt() ); - pageItem->setBrush( brush ); - pageItem->setPen( pen ); - pageItem->setGraphicsEffect( shadowEffect ); - - mScene->addItem( pageItem ); - } - - - /// - /// Draw Labels on Paper - /// - void SimplePreview::drawLabels() - { - libglabels::Frame *frame = mTmplate->frames().first(); - - foreach (libglabels::Point origin, frame->getOrigins() ) - { - drawLabel( origin.x(), origin.y(), frame->path() ); - } - } - - - /// - /// Draw a Single Label at x,y - /// - void SimplePreview::drawLabel( const libglabels::Distance& x, - const libglabels::Distance& y, - const QPainterPath& path ) - { - QBrush brush( labelColor ); - QPen pen( labelOutlineColor ); - pen.setCosmetic( true ); - pen.setWidthF( labelOutlineWidthPixels ); - - QGraphicsPathItem *labelItem = new QGraphicsPathItem( path ); - labelItem->setBrush( brush ); - labelItem->setPen( pen ); - labelItem->setPos( x.pt(), y.pt() ); - - mScene->addItem( labelItem ); - } - - - /// - /// Draw Arrow Indicating Top of First Label - /// - void SimplePreview::drawArrow() - { - libglabels::Frame *frame = mTmplate->frames().first(); - - libglabels::Distance w = frame->w(); - libglabels::Distance h = frame->h(); - - libglabels::Distance min = libglabels::min( w, h ); - - QPen pen( arrowColor ); - pen.setWidthF( 0.25*min.pt()*arrowScale ); - pen.setCapStyle( Qt::FlatCap ); - pen.setJoinStyle( Qt::MiterJoin ); - - QBrush brush( upColor ); - - libglabels::Point origin = frame->getOrigins().first(); - libglabels::Distance x0 = origin.x(); - libglabels::Distance y0 = origin.y(); - - QPainterPath path; - path.moveTo( 0, min.pt()*arrowScale/3 ); - path.lineTo( 0, -min.pt()*arrowScale ); - path.moveTo( -min.pt()*arrowScale/2, -min.pt()*arrowScale/2 ); - path.lineTo( 0, -min.pt()*arrowScale ); - path.lineTo( min.pt()*arrowScale/2, -min.pt()*arrowScale/2 ); - - QGraphicsPathItem *arrowItem = new QGraphicsPathItem( path ); - arrowItem->setPen( pen ); - arrowItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() ); - if ( mRotateFlag ) - { - arrowItem->setRotation( 90 ); - } - - QGraphicsSimpleTextItem *upItem = new QGraphicsSimpleTextItem( tr("Up") ); - upItem->setBrush( brush ); - upItem->setFont( QFont( upFontFamily, min.pt()*upScale, QFont::Bold ) ); - upItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() ); - QRectF rect = upItem->boundingRect(); - if ( mRotateFlag ) - { - upItem->setPos( upItem->x()-min.pt()/8, upItem->y()-rect.width()/2 ); - upItem->setRotation( 90 ); - } - else - { - upItem->setPos( upItem->x()-rect.width()/2, upItem->y()+min.pt()/8 ); - } - - mScene->addItem( arrowItem ); - mScene->addItem( upItem ); - } + setAttribute(Qt::WA_TranslucentBackground); + viewport()->setAutoFillBackground(false); + setFrameStyle( QFrame::NoFrame ); + setRenderHints( QPainter::Antialiasing ); +} + + +/// +/// Template Property Setter +/// +void SimplePreview::setTemplate( const glabels::Template *tmplate ) +{ + mTmplate = tmplate; + update(); +} + + +/// +/// Rotate Property Setter +/// +void SimplePreview::setRotate( bool rotateFlag ) +{ + mRotateFlag = rotateFlag; + update(); +} + + +/// +/// Resize Event Handler +/// +void SimplePreview::resizeEvent( QResizeEvent* event ) +{ + fitInView( mScene->sceneRect(), Qt::KeepAspectRatio ); +} + + +/// +/// Update View +/// +void SimplePreview::update() +{ + clearScene(); + + if ( mTmplate != NULL ) + { + // Set scene up with a 5% margin around paper + glabels::Distance x = -0.05 * mTmplate->pageWidth(); + glabels::Distance y = -0.05 * mTmplate->pageHeight(); + glabels::Distance w = 1.10 * mTmplate->pageWidth(); + glabels::Distance h = 1.10 * mTmplate->pageHeight(); + + mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() ); + fitInView( mScene->sceneRect(), Qt::KeepAspectRatio ); + + drawPaper( mTmplate->pageWidth(), mTmplate->pageHeight() ); + drawLabels(); + drawArrow(); + } +} + + +/// +/// Clear View +/// +void SimplePreview::clearScene() +{ + foreach ( QGraphicsItem *item, mScene->items() ) + { + mScene->removeItem( item ); + delete item; + } +} + + +/// +/// Draw Paper +/// +void SimplePreview::drawPaper( const glabels::Distance& pw, const glabels::Distance& ph ) +{ + QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect(); + shadowEffect->setColor( shadowColor ); + shadowEffect->setOffset( shadowOffsetPixels ); + shadowEffect->setBlurRadius( shadowRadiusPixels ); + + QBrush brush( paperColor ); + QPen pen( paperOutlineColor ); + pen.setCosmetic( true ); + pen.setWidthF( paperOutlineWidthPixels ); + + QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw.pt(), ph.pt() ); + pageItem->setBrush( brush ); + pageItem->setPen( pen ); + pageItem->setGraphicsEffect( shadowEffect ); + + mScene->addItem( pageItem ); +} + + +/// +/// Draw Labels on Paper +/// +void SimplePreview::drawLabels() +{ + glabels::Frame *frame = mTmplate->frames().first(); + + foreach (glabels::Point origin, frame->getOrigins() ) + { + drawLabel( origin.x(), origin.y(), frame->path() ); + } +} + + +/// +/// Draw a Single Label at x,y +/// +void SimplePreview::drawLabel( const glabels::Distance& x, + const glabels::Distance& y, + const QPainterPath& path ) +{ + QBrush brush( labelColor ); + QPen pen( labelOutlineColor ); + pen.setCosmetic( true ); + pen.setWidthF( labelOutlineWidthPixels ); + + QGraphicsPathItem *labelItem = new QGraphicsPathItem( path ); + labelItem->setBrush( brush ); + labelItem->setPen( pen ); + labelItem->setPos( x.pt(), y.pt() ); + + mScene->addItem( labelItem ); +} + + +/// +/// Draw Arrow Indicating Top of First Label +/// +void SimplePreview::drawArrow() +{ + glabels::Frame *frame = mTmplate->frames().first(); + + glabels::Distance w = frame->w(); + glabels::Distance h = frame->h(); + + glabels::Distance min = glabels::min( w, h ); + + QPen pen( arrowColor ); + pen.setWidthF( 0.25*min.pt()*arrowScale ); + pen.setCapStyle( Qt::FlatCap ); + pen.setJoinStyle( Qt::MiterJoin ); + + QBrush brush( upColor ); + + glabels::Point origin = frame->getOrigins().first(); + glabels::Distance x0 = origin.x(); + glabels::Distance y0 = origin.y(); + + QPainterPath path; + path.moveTo( 0, min.pt()*arrowScale/3 ); + path.lineTo( 0, -min.pt()*arrowScale ); + path.moveTo( -min.pt()*arrowScale/2, -min.pt()*arrowScale/2 ); + path.lineTo( 0, -min.pt()*arrowScale ); + path.lineTo( min.pt()*arrowScale/2, -min.pt()*arrowScale/2 ); + + QGraphicsPathItem *arrowItem = new QGraphicsPathItem( path ); + arrowItem->setPen( pen ); + arrowItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() ); + if ( mRotateFlag ) + { + arrowItem->setRotation( 90 ); + } + + QGraphicsSimpleTextItem *upItem = new QGraphicsSimpleTextItem( tr("Up") ); + upItem->setBrush( brush ); + upItem->setFont( QFont( upFontFamily, min.pt()*upScale, QFont::Bold ) ); + upItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() ); + QRectF rect = upItem->boundingRect(); + if ( mRotateFlag ) + { + upItem->setPos( upItem->x()-min.pt()/8, upItem->y()-rect.width()/2 ); + upItem->setRotation( 90 ); + } + else + { + upItem->setPos( upItem->x()-rect.width()/2, upItem->y()+min.pt()/8 ); + } + + mScene->addItem( arrowItem ); + mScene->addItem( upItem ); } diff --git a/glabels/SimplePreview.h b/glabels/SimplePreview.h index 2478014..d8a1dd8 100644 --- a/glabels/SimplePreview.h +++ b/glabels/SimplePreview.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_SimplePreview_h -#define glabels_SimplePreview_h +#ifndef SimplePreview_h +#define SimplePreview_h #include #include @@ -29,64 +29,60 @@ #include "libglabels/Template.h" -namespace glabels +/// +/// Simple Preview Widget +/// +class SimplePreview : public QGraphicsView { - - /// - /// Simple Preview Widget - /// - class SimplePreview : public QGraphicsView - { - Q_OBJECT + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - SimplePreview( QWidget *parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + SimplePreview( QWidget *parent = 0 ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - void setTemplate( const libglabels::Template *tmplate ); - void setRotate( bool rotateFlag ); + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + void setTemplate( const glabels::Template *tmplate ); + void setRotate( bool rotateFlag ); - ///////////////////////////////////// - // Event handlers - ///////////////////////////////////// - protected: - void resizeEvent( QResizeEvent* event ); + ///////////////////////////////////// + // Event handlers + ///////////////////////////////////// +protected: + void resizeEvent( QResizeEvent* event ); - ///////////////////////////////// - // Internal Methods - ///////////////////////////////// - private: - void update(); - void clearScene(); - void drawPaper( const libglabels::Distance& pw, const libglabels::Distance& ph ); - void drawLabels(); - void drawLabel( const libglabels::Distance& x, - const libglabels::Distance& y, - const QPainterPath& path ); - void drawArrow(); + ///////////////////////////////// + // Internal Methods + ///////////////////////////////// +private: + void update(); + void clearScene(); + void drawPaper( const glabels::Distance& pw, const glabels::Distance& ph ); + void drawLabels(); + void drawLabel( const glabels::Distance& x, + const glabels::Distance& y, + const QPainterPath& path ); + void drawArrow(); - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - const libglabels::Template *mTmplate; - bool mRotateFlag; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + const glabels::Template *mTmplate; + bool mRotateFlag; - QGraphicsScene *mScene; + QGraphicsScene *mScene; - }; +}; -} -#endif // glabels_SimplePreview_h +#endif // SimplePreview_h diff --git a/glabels/TemplatePicker.cpp b/glabels/TemplatePicker.cpp index 6c9a2d2..f722273 100644 --- a/glabels/TemplatePicker.cpp +++ b/glabels/TemplatePicker.cpp @@ -25,79 +25,73 @@ #include "TemplatePickerItem.h" -namespace glabels +/// +/// Constructor +/// +TemplatePicker::TemplatePicker( QWidget *parent ) : QListWidget(parent) { + setViewMode( QListView::IconMode ); + setResizeMode( QListView::Adjust ); + setSpacing( 24 ); + setWordWrap( true ); + setUniformItemSizes( true ); + setIconSize( QSize(glabels::TEMPLATE_PREVIEW_SIZE, glabels::TEMPLATE_PREVIEW_SIZE) ); +} - /// - /// Constructor - /// - TemplatePicker::TemplatePicker( QWidget *parent ) : QListWidget(parent) + +/// +/// Set List of Templates to Pick From +/// +void TemplatePicker::setTemplates( const QList &tmplates ) +{ + foreach (glabels::Template *tmplate, tmplates) { - setViewMode( QListView::IconMode ); - setResizeMode( QListView::Adjust ); - setSpacing( 24 ); - setWordWrap( true ); - setUniformItemSizes( true ); - setIconSize( QSize(libglabels::TEMPLATE_PREVIEW_SIZE, libglabels::TEMPLATE_PREVIEW_SIZE) ); + TemplatePickerItem *item = new TemplatePickerItem( tmplate, this ); } +} - /// - /// Set List of Templates to Pick From - /// - void TemplatePicker::setTemplates( const QList &tmplates ) +/// +/// Apply Filter to Narrow Template Choices +/// +void TemplatePicker::applyFilter( const QString &searchString, + bool isoMask, bool usMask, bool otherMask ) +{ + foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) ) { - foreach (libglabels::Template *tmplate, tmplates) + TemplatePickerItem *tItem = dynamic_cast(item); + + bool sizeMask = + (isoMask && tItem->tmplate()->isSizeIso()) || + (usMask && tItem->tmplate()->isSizeUs()) || + (otherMask && tItem->tmplate()->isSizeOther()); + + if ( tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) && sizeMask ) { - TemplatePickerItem *item = new TemplatePickerItem( tmplate, this ); - } - } - - - /// - /// Apply Filter to Narrow Template Choices - /// - void TemplatePicker::applyFilter( const QString &searchString, - bool isoMask, bool usMask, bool otherMask ) - { - foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) ) - { - TemplatePickerItem *tItem = dynamic_cast(item); - - bool sizeMask = - (isoMask && tItem->tmplate()->isSizeIso()) || - (usMask && tItem->tmplate()->isSizeUs()) || - (otherMask && tItem->tmplate()->isSizeOther()); - - if ( tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) && sizeMask ) - { - item->setHidden( false ); - } - else - { - item->setHidden( true ); - item->setSelected( false ); - } - } - } - - - /// - /// Get Currently Selected Template - /// - const libglabels::Template *TemplatePicker::selectedTemplate() - { - QList items = selectedItems(); - if ( items.isEmpty() ) - { - return NULL; + item->setHidden( false ); } else { - TemplatePickerItem *tItem = dynamic_cast(items.first()); - return tItem->tmplate(); + item->setHidden( true ); + item->setSelected( false ); } } - } + +/// +/// Get Currently Selected Template +/// +const glabels::Template *TemplatePicker::selectedTemplate() +{ + QList items = selectedItems(); + if ( items.isEmpty() ) + { + return NULL; + } + else + { + TemplatePickerItem *tItem = dynamic_cast(items.first()); + return tItem->tmplate(); + } +} diff --git a/glabels/TemplatePicker.h b/glabels/TemplatePicker.h index bbd96f0..b379b30 100644 --- a/glabels/TemplatePicker.h +++ b/glabels/TemplatePicker.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_TemplatePicker_h -#define glabels_TemplatePicker_h +#ifndef TemplatePicker_h +#define TemplatePicker_h #include @@ -28,40 +28,36 @@ #include "libglabels/Template.h" -namespace glabels +/// +/// Template Picker Widget +/// +class TemplatePicker : public QListWidget { - - /// - /// Template Picker Widget - /// - class TemplatePicker : public QListWidget - { - Q_OBJECT + Q_OBJECT - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - TemplatePicker( QWidget *parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + TemplatePicker( QWidget *parent = 0 ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - void setTemplates( const QList &tmplates ); + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + void setTemplates( const QList &tmplates ); - ///////////////////////////////// - // Methods - ///////////////////////////////// - void applyFilter( const QString &searchString, bool isoMask, bool usMask, bool otherMask ); + ///////////////////////////////// + // Methods + ///////////////////////////////// + void applyFilter( const QString &searchString, bool isoMask, bool usMask, bool otherMask ); - const libglabels::Template *selectedTemplate(); + const glabels::Template *selectedTemplate(); - }; +}; -} -#endif // glabels_TemplatePicker_h +#endif // TemplatePicker_h diff --git a/glabels/TemplatePickerItem.cpp b/glabels/TemplatePickerItem.cpp index 1097330..63928d6 100644 --- a/glabels/TemplatePickerItem.cpp +++ b/glabels/TemplatePickerItem.cpp @@ -25,32 +25,27 @@ #include -namespace glabels +/// +/// Constructor +/// +TemplatePickerItem::TemplatePickerItem( glabels::Template *tmplate, + QListWidget *parent ) + : QListWidgetItem(parent) { + mTmplate = tmplate; - /// - /// Constructor - /// - TemplatePickerItem::TemplatePickerItem( libglabels::Template *tmplate, - QListWidget *parent ) - : QListWidgetItem(parent) - { - mTmplate = tmplate; - - setIcon( QIcon(tmplate->preview()) ); - setText( tmplate->name() ); - - setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); - } - - - /// - /// Template Property Getter - /// - const libglabels::Template *TemplatePickerItem::tmplate() const - { - return mTmplate; - } + setIcon( QIcon(tmplate->preview()) ); + setText( tmplate->name() ); + setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled ); +} + + +/// +/// Template Property Getter +/// +const glabels::Template *TemplatePickerItem::tmplate() const +{ + return mTmplate; } diff --git a/glabels/TemplatePickerItem.h b/glabels/TemplatePickerItem.h index 4153876..5898aa2 100644 --- a/glabels/TemplatePickerItem.h +++ b/glabels/TemplatePickerItem.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_TemplatePickerItem_h -#define glabels_TemplatePickerItem_h +#ifndef TemplatePickerItem_h +#define TemplatePickerItem_h #include @@ -28,37 +28,33 @@ #include "libglabels/Template.h" -namespace glabels +/// +/// Template Picker Item Widget +/// +class TemplatePickerItem : public QListWidgetItem { - /// - /// Template Picker Item Widget - /// - class TemplatePickerItem : public QListWidgetItem - { - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - TemplatePickerItem( libglabels::Template *tmplate, QListWidget *parent = 0 ); + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + TemplatePickerItem( glabels::Template *tmplate, QListWidget *parent = 0 ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - const libglabels::Template *tmplate() const; + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + const glabels::Template *tmplate() const; - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - libglabels::Template *mTmplate; + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: + glabels::Template *mTmplate; - }; +}; -} -#endif // glabels_TemplatePickerItem_h +#endif // TemplatePickerItem_h diff --git a/glabels/TextNode.cpp b/glabels/TextNode.cpp index d1476cd..d22dec8 100644 --- a/glabels/TextNode.cpp +++ b/glabels/TextNode.cpp @@ -33,212 +33,209 @@ namespace { } -namespace glabels +/// +/// Default Constructor +/// +TextNode::TextNode() + : mFieldFlag(false), mData("") { +} - /// - /// Default Constructor - /// - TextNode::TextNode() - : mFieldFlag(false), mData("") + +/// +/// Constructor from Data +/// +TextNode::TextNode( bool field_flag, const QString &data ) + : mFieldFlag(field_flag), mData(data) +{ +} + + +/// +/// Constructor from Parsing Next Token in Text +/// +TextNode::TextNode( const QString &text, int i_start, int &i_next ) +{ + State state = START; + QString literal_text; + QString field_name; + bool field_flag = false; + + int i = i_start; + + while ( state != DONE ) { - } + QChar c = text[i]; + switch (state) { - /// - /// Constructor from Data - /// - TextNode::TextNode( bool field_flag, const QString &data ) - : mFieldFlag(field_flag), mData(data) - { - } - - - /// - /// Constructor from Parsing Next Token in Text - /// - TextNode::TextNode( const QString &text, int i_start, int &i_next ) - { - State state = START; - QString literal_text; - QString field_name; - bool field_flag = false; - - int i = i_start; - - while ( state != DONE ) - { - QChar c = text[i]; - - switch (state) { - - case START: - switch (c.unicode()) { - case '$': - /* May be start of a field node. */ - i++; - state = START_DOLLAR; - break; - case '\n': - state = DONE; - break; - case 0: - state = DONE; - break; - default: - /* Start a literal text node. */ - literal_text.append( c ); - i++; - state = LITERAL; - break; - } + case START: + switch (c.unicode()) { + case '$': + /* May be start of a field node. */ + i++; + state = START_DOLLAR; break; - - case LITERAL: - switch (c.unicode()) { - case '$': - /* May be the beginning of a field node. */ - i++; - state = LITERAL_DOLLAR; - break; - case '\n': - state = DONE; - break; - case 0: - state = DONE; - break; - default: - literal_text.append( c ); - i++; - state = LITERAL; - break; - } + case '\n': + state = DONE; break; - - case LITERAL_DOLLAR: - switch (c.unicode()) { - case '{': - /* "${" indicates the start of a new field node, gather for literal too. */ - literal_text.append( '$' ); - i++; - state = DONE; - break; - case '\n': - /* Append "$" to literal text, don't gather newline. */ - literal_text.append( '$' ); - i++; - state = DONE; - break; - case 0: - /* Append "$" to literal text, don't gather null. */ - literal_text.append( '$' ); - i++; - state = DONE; - break; - default: - /* Append "$" to literal text, gather this character too. */ - literal_text.append( '$' ); - literal_text.append( c ); - i+=2; - state = LITERAL; - break; - } + case 0: + state = DONE; break; - - case START_DOLLAR: - switch (c.unicode()) { - case '{': - /* This is probably the begining of a field node, gather for literal too. */ - literal_text.append( c ); - i++; - state = FIELD; - break; - case '\n': - state = DONE; - break; - case 0: - state = DONE; - break; - default: - /* The "$" was literal. */ - literal_text.append( c ); - i++; - state = LITERAL; - break; - } + default: + /* Start a literal text node. */ + literal_text.append( c ); + i++; + state = LITERAL; break; - - case FIELD: - switch (c.unicode()) { - case '}': - /* We now finally know that this node is really field node. */ - field_flag = true; - i++; - state = DONE; - break; - case '\n': - state = DONE; - break; - case 0: - state = DONE; - break; - default: - /* Gather for field name and literal, just in case. */ - field_name.append( c ); - literal_text.append( c ); - i++; - state = FIELD; - break; - } - break; - } + break; + + case LITERAL: + switch (c.unicode()) { + case '$': + /* May be the beginning of a field node. */ + i++; + state = LITERAL_DOLLAR; + break; + case '\n': + state = DONE; + break; + case 0: + state = DONE; + break; + default: + literal_text.append( c ); + i++; + state = LITERAL; + break; + } + break; + + case LITERAL_DOLLAR: + switch (c.unicode()) { + case '{': + /* "${" indicates the start of a new field node, gather for literal too. */ + literal_text.append( '$' ); + i++; + state = DONE; + break; + case '\n': + /* Append "$" to literal text, don't gather newline. */ + literal_text.append( '$' ); + i++; + state = DONE; + break; + case 0: + /* Append "$" to literal text, don't gather null. */ + literal_text.append( '$' ); + i++; + state = DONE; + break; + default: + /* Append "$" to literal text, gather this character too. */ + literal_text.append( '$' ); + literal_text.append( c ); + i+=2; + state = LITERAL; + break; + } + break; + + case START_DOLLAR: + switch (c.unicode()) { + case '{': + /* This is probably the begining of a field node, gather for literal too. */ + literal_text.append( c ); + i++; + state = FIELD; + break; + case '\n': + state = DONE; + break; + case 0: + state = DONE; + break; + default: + /* The "$" was literal. */ + literal_text.append( c ); + i++; + state = LITERAL; + break; + } + break; + + case FIELD: + switch (c.unicode()) { + case '}': + /* We now finally know that this node is really field node. */ + field_flag = true; + i++; + state = DONE; + break; + case '\n': + state = DONE; + break; + case 0: + state = DONE; + break; + default: + /* Gather for field name and literal, just in case. */ + field_name.append( c ); + literal_text.append( c ); + i++; + state = FIELD; + break; + } + break; } - mFieldFlag = field_flag; - mData = field_flag ? field_name : literal_text; - - i_next = i; } + mFieldFlag = field_flag; + mData = field_flag ? field_name : literal_text; - /// - /// == Operator - /// - bool TextNode::operator==( const TextNode& other ) - { - return ( (mFieldFlag == other.mFieldFlag) && - (mData == other.mData) ); - } + i_next = i; +} - /// - /// != Operator - /// - bool TextNode::operator!=( const TextNode& other ) - { - return ( (mFieldFlag != other.mFieldFlag) || - (mData != other.mData) ); - } +/// +/// == Operator +/// +bool TextNode::operator==( const TextNode& other ) +{ + return ( (mFieldFlag == other.mFieldFlag) && + (mData == other.mData) ); +} - /// - /// Field Flag Property Getter - /// - bool TextNode::fieldFlag( void ) const - { - return mFieldFlag; - } +/// +/// != Operator +/// +bool TextNode::operator!=( const TextNode& other ) +{ + return ( (mFieldFlag != other.mFieldFlag) || + (mData != other.mData) ); +} - /// - /// Data Property Getter - /// - const QString& TextNode::data( void ) const - { - return mData; - } +/// +/// Field Flag Property Getter +/// +bool TextNode::fieldFlag( void ) const +{ + return mFieldFlag; +} + + +/// +/// Data Property Getter +/// +const QString& TextNode::data( void ) const +{ + return mData; +} #if TODO @@ -285,6 +282,3 @@ namespace glabels } } #endif - -} - diff --git a/glabels/TextNode.h b/glabels/TextNode.h index 497da4d..a8e050f 100644 --- a/glabels/TextNode.h +++ b/glabels/TextNode.h @@ -18,76 +18,72 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_TextNode_h -#define glabels_TextNode_h +#ifndef TextNode_h +#define TextNode_h #include -namespace glabels +/// +/// Text Node Type +/// +struct TextNode { - /// - /// Text Node Type - /// - struct TextNode - { + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// +public: + TextNode(); - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - TextNode(); + TextNode( bool field_flag, const QString &data ); - TextNode( bool field_flag, const QString &data ); - - TextNode( const QString &text, int i_start, int &i_next ); + TextNode( const QString &text, int i_start, int &i_next ); - ///////////////////////////////// - // Operators - ///////////////////////////////// - public: - bool operator==( const TextNode& other ); + ///////////////////////////////// + // Operators + ///////////////////////////////// +public: + bool operator==( const TextNode& other ); - bool operator!=( const TextNode& other ); + bool operator!=( const TextNode& other ); - ///////////////////////////////// - // Properties - ///////////////////////////////// - public: - // - // Field Flag Property - // - bool fieldFlag( void ) const; + ///////////////////////////////// + // Properties + ///////////////////////////////// +public: + // + // Field Flag Property + // + bool fieldFlag( void ) const; - // - // Data Property - // - const QString& data( void ) const; + // + // Data Property + // + const QString& data( void ) const; - ///////////////////////////////// - // Methods - ///////////////////////////////// + ///////////////////////////////// + // Methods + ///////////////////////////////// #if TODO - string expand( MergeRecord? record ); - bool is_empty_field( MergeRecord? record ); + string expand( MergeRecord? record ); + bool is_empty_field( MergeRecord? record ); #endif - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: + ///////////////////////////////// + // Private Data + ///////////////////////////////// +private: - bool mFieldFlag; - QString mData; + bool mFieldFlag; + QString mData; - }; +}; -} -#endif // glabels_TextNode_h +#endif // TextNode_h diff --git a/glabels/View.cpp b/glabels/View.cpp index bbf4b51..653526a 100644 --- a/glabels/View.cpp +++ b/glabels/View.cpp @@ -59,7 +59,7 @@ namespace const QColor gridLineColor( 192, 192, 192 ); const double gridLineWidthPixels = 1; - const libglabels::Distance gridSpacing = libglabels::Distance::pt(9); // TODO: determine from locale. + const glabels::Distance gridSpacing = glabels::Distance::pt(9); // TODO: determine from locale. const QColor markupLineColor( 240, 99, 99 ); const double markupLineWidthPixels = 1; @@ -74,7 +74,7 @@ namespace /// /// Constructor /// -glabels::View::View( QScrollArea* scrollArea, QWidget* parent ) +View::View( QScrollArea* scrollArea, QWidget* parent ) : QWidget(parent), mScrollArea(scrollArea) { mState = IdleState; @@ -92,7 +92,7 @@ glabels::View::View( QScrollArea* scrollArea, QWidget* parent ) /// Zoom property /// double -glabels::View::zoom() const +View::zoom() const { return mZoom; } @@ -102,7 +102,7 @@ glabels::View::zoom() const /// Markup visible? property /// bool -glabels::View::markupVisible() const +View::markupVisible() const { return mMarkupVisible; } @@ -112,7 +112,7 @@ glabels::View::markupVisible() const /// Grid visible? property /// bool -glabels::View::qridVisible() const +View::qridVisible() const { return mGridVisible; } @@ -122,7 +122,7 @@ glabels::View::qridVisible() const /// Model Parameter Setter /// void -glabels::View::setModel( LabelModel* model ) +View::setModel( LabelModel* model ) { mModel = model; @@ -143,7 +143,7 @@ glabels::View::setModel( LabelModel* model ) /// Grid Visibility Parameter Setter /// void -glabels::View::setGridVisible( bool visibleFlag ) +View::setGridVisible( bool visibleFlag ) { mGridVisible = visibleFlag; update(); @@ -154,7 +154,7 @@ glabels::View::setGridVisible( bool visibleFlag ) /// Markup Visibility Parameter Setter /// void -glabels::View::setMarkupVisible( bool visibleFlag ) +View::setMarkupVisible( bool visibleFlag ) { mMarkupVisible = visibleFlag; update(); @@ -165,7 +165,7 @@ glabels::View::setMarkupVisible( bool visibleFlag ) /// Zoom In "One Notch" /// void -glabels::View::zoomIn() +View::zoomIn() { // Find closest standard zoom level to our current zoom // Start with 2nd largest scale @@ -191,7 +191,7 @@ glabels::View::zoomIn() /// Zoom Out "One Notch" /// void -glabels::View::zoomOut() +View::zoomOut() { // Find closest standard zoom level to our current zoom // Start with largest scale, end on 2nd smallest @@ -217,7 +217,7 @@ glabels::View::zoomOut() /// Zoom To 1:1 Scale /// void -glabels::View::zoom1To1() +View::zoom1To1() { setZoomReal( 1.0, false ); } @@ -227,7 +227,7 @@ glabels::View::zoom1To1() /// Zoom To Fit /// void -glabels::View::zoomToFit() +View::zoomToFit() { using std::min; using std::max; @@ -251,7 +251,7 @@ glabels::View::zoomToFit() /// Is Zoom at Maximum? /// bool -glabels::View::isZoomMax() const +View::isZoomMax() const { return ( mZoom >= zoomLevels[0] ); } @@ -261,7 +261,7 @@ glabels::View::isZoomMax() const /// Is Zoom at Minimum? /// bool -glabels::View::isZoomMin() const +View::isZoomMin() const { return ( mZoom <= zoomLevels[nZoomLevels-1] ); } @@ -271,7 +271,7 @@ glabels::View::isZoomMin() const /// Set Zoom to Value /// void -glabels::View::setZoomReal( double zoom, bool zoomToFitFlag ) +View::setZoomReal( double zoom, bool zoomToFitFlag ) { mZoom = zoom; mZoomToFitFlag = zoomToFitFlag; @@ -296,7 +296,7 @@ glabels::View::setZoomReal( double zoom, bool zoomToFitFlag ) /// Arrow mode (normal mode) /// void -glabels::View::arrowMode() +View::arrowMode() { setCursor( Qt::ArrowCursor ); @@ -308,7 +308,7 @@ glabels::View::arrowMode() /// Create box mode /// void -glabels::View::createBoxMode() +View::createBoxMode() { setCursor( Cursors::Box() ); @@ -321,7 +321,7 @@ glabels::View::createBoxMode() /// Resize Event Handler /// void -glabels::View::resizeEvent( QResizeEvent *event ) +View::resizeEvent( QResizeEvent *event ) { if ( mModel ) { @@ -345,7 +345,7 @@ glabels::View::resizeEvent( QResizeEvent *event ) /// Mouse Button Press Event Handler /// void -glabels::View::mousePressEvent( QMouseEvent* event ) +View::mousePressEvent( QMouseEvent* event ) { if ( mModel ) { @@ -358,8 +358,8 @@ glabels::View::mousePressEvent( QMouseEvent* event ) transform.translate( mX0.pt(), mY0.pt() ); QPointF pWorld = transform.inverted().map( event->posF() ); - libglabels::Distance xWorld = libglabels::Distance::pt( pWorld.x() ); - libglabels::Distance yWorld = libglabels::Distance::pt( pWorld.y() ); + glabels::Distance xWorld = glabels::Distance::pt( pWorld.x() ); + glabels::Distance yWorld = glabels::Distance::pt( pWorld.y() ); if ( event->button() & Qt::LeftButton ) @@ -511,7 +511,7 @@ glabels::View::mousePressEvent( QMouseEvent* event ) /// Mouse Movement Event Handler /// void -glabels::View::mouseMoveEvent( QMouseEvent* event ) +View::mouseMoveEvent( QMouseEvent* event ) { using std::min; using std::max; @@ -527,8 +527,8 @@ glabels::View::mouseMoveEvent( QMouseEvent* event ) transform.translate( mX0.pt(), mY0.pt() ); QPointF pWorld = transform.inverted().map( event->posF() ); - libglabels::Distance xWorld = libglabels::Distance::pt( pWorld.x() ); - libglabels::Distance yWorld = libglabels::Distance::pt( pWorld.y() ); + glabels::Distance xWorld = glabels::Distance::pt( pWorld.x() ); + glabels::Distance yWorld = glabels::Distance::pt( pWorld.y() ); /* @@ -615,7 +615,7 @@ glabels::View::mouseMoveEvent( QMouseEvent* event ) /// Mouse Button Release Event Handler /// void -glabels::View::mouseReleaseEvent( QMouseEvent* event ) +View::mouseReleaseEvent( QMouseEvent* event ) { if ( mModel ) { @@ -628,8 +628,8 @@ glabels::View::mouseReleaseEvent( QMouseEvent* event ) transform.translate( mX0.pt(), mY0.pt() ); QPointF pWorld = transform.inverted().map( event->posF() ); - libglabels::Distance xWorld = libglabels::Distance::pt( pWorld.x() ); - libglabels::Distance yWorld = libglabels::Distance::pt( pWorld.y() ); + glabels::Distance xWorld = glabels::Distance::pt( pWorld.x() ); + glabels::Distance yWorld = glabels::Distance::pt( pWorld.y() ); if ( event->button() & Qt::LeftButton ) @@ -691,7 +691,7 @@ glabels::View::mouseReleaseEvent( QMouseEvent* event ) /// Leave Event Handler /// void -glabels::View::leaveEvent( QEvent* event ) +View::leaveEvent( QEvent* event ) { if ( mModel ) { @@ -704,8 +704,8 @@ glabels::View::leaveEvent( QEvent* event ) /// Handle resize motion /// void -glabels::View::handleResizeMotion( const libglabels::Distance& xWorld, - const libglabels::Distance& yWorld ) +View::handleResizeMotion( const glabels::Distance& xWorld, + const glabels::Distance& yWorld ) { QPointF p( xWorld.pt(), yWorld.pt() ); Handle::Location location = mResizeHandle->location(); @@ -795,22 +795,22 @@ glabels::View::handleResizeMotion( const libglabels::Distance& xWorld, { case Handle::E: case Handle::W: - mResizeObject->setWHonorAspect( libglabels::Distance::pt(w) ); + mResizeObject->setWHonorAspect( glabels::Distance::pt(w) ); break; case Handle::N: case Handle::S: - mResizeObject->setHHonorAspect( libglabels::Distance::pt(h) ); + mResizeObject->setHHonorAspect( glabels::Distance::pt(h) ); break; default: - mResizeObject->setSizeHonorAspect( libglabels::Distance::pt(w), - libglabels::Distance::pt(h) ); + mResizeObject->setSizeHonorAspect( glabels::Distance::pt(w), + glabels::Distance::pt(h) ); break; } } else { - mResizeObject->setSize( libglabels::Distance::pt(w), - libglabels::Distance::pt(h) ); + mResizeObject->setSize( glabels::Distance::pt(w), + glabels::Distance::pt(h) ); } /* @@ -836,8 +836,8 @@ glabels::View::handleResizeMotion( const libglabels::Distance& xWorld, } else { - mResizeObject->setSize( libglabels::Distance::pt(w), - libglabels::Distance::pt(h) ); + mResizeObject->setSize( glabels::Distance::pt(w), + glabels::Distance::pt(h) ); } /* @@ -846,8 +846,8 @@ glabels::View::handleResizeMotion( const libglabels::Distance& xWorld, QPointF p0( x0, y0 ); p0 = mResizeObject->matrix().map( p0 ); p0 += QPointF( mResizeObject->x0().pt(), mResizeObject->y0().pt() ); - mResizeObject->setPosition( libglabels::Distance::pt(p0.x()), - libglabels::Distance::pt(p0.y()) ); + mResizeObject->setPosition( glabels::Distance::pt(p0.x()), + glabels::Distance::pt(p0.y()) ); } @@ -855,7 +855,7 @@ glabels::View::handleResizeMotion( const libglabels::Distance& xWorld, /// Paint Event Handler /// void -glabels::View::paintEvent( QPaintEvent* event ) +View::paintEvent( QPaintEvent* event ) { if ( mModel ) { @@ -890,7 +890,7 @@ glabels::View::paintEvent( QPaintEvent* event ) /// Draw Background Layer /// void -glabels::View::drawBgLayer( QPainter* painter ) +View::drawBgLayer( QPainter* painter ) { /* * Draw shadow @@ -935,15 +935,15 @@ glabels::View::drawBgLayer( QPainter* painter ) /// Draw Grid Layer /// void -glabels::View::drawGridLayer( QPainter* painter ) +View::drawGridLayer( QPainter* painter ) { if ( mGridVisible ) { - libglabels::Distance w = mModel->frame()->w(); - libglabels::Distance h = mModel->frame()->h(); + glabels::Distance w = mModel->frame()->w(); + glabels::Distance h = mModel->frame()->h(); - libglabels::Distance x0, y0; - if ( dynamic_cast( mModel->frame() ) ) + glabels::Distance x0, y0; + if ( dynamic_cast( mModel->frame() ) ) { x0 = gridSpacing; y0 = gridSpacing; @@ -968,12 +968,12 @@ glabels::View::drawGridLayer( QPainter* painter ) pen.setCosmetic( true ); painter->setPen( pen ); - for ( libglabels::Distance x = x0; x < w; x += gridSpacing ) + for ( glabels::Distance x = x0; x < w; x += gridSpacing ) { painter->drawLine( x.pt(), 0, x.pt(), h.pt() ); } - for ( libglabels::Distance y = y0; y < h; y += gridSpacing ) + for ( glabels::Distance y = y0; y < h; y += gridSpacing ) { painter->drawLine( 0, y.pt(), w.pt(), y.pt() ); } @@ -987,7 +987,7 @@ glabels::View::drawGridLayer( QPainter* painter ) /// Draw Markup Layer /// void -glabels::View::drawMarkupLayer( QPainter* painter ) +View::drawMarkupLayer( QPainter* painter ) { if ( mMarkupVisible ) { @@ -1002,7 +1002,7 @@ glabels::View::drawMarkupLayer( QPainter* painter ) painter->translate( -mModel->frame()->w().pt(), 0 ); } - foreach( libglabels::Markup* markup, mModel->frame()->markups() ) + foreach( glabels::Markup* markup, mModel->frame()->markups() ) { painter->drawPath( markup->path() ); } @@ -1016,7 +1016,7 @@ glabels::View::drawMarkupLayer( QPainter* painter ) /// Draw Objects Layer /// void -glabels::View::drawObjectsLayer( QPainter* painter ) +View::drawObjectsLayer( QPainter* painter ) { mModel->draw( painter ); } @@ -1026,7 +1026,7 @@ glabels::View::drawObjectsLayer( QPainter* painter ) /// Draw Foreground Layer /// void -glabels::View::drawFgLayer( QPainter* painter ) +View::drawFgLayer( QPainter* painter ) { /* * Draw label outline @@ -1053,7 +1053,7 @@ glabels::View::drawFgLayer( QPainter* painter ) /// Draw Highlight Layer /// void -glabels::View::drawHighlightLayer( QPainter* painter ) +View::drawHighlightLayer( QPainter* painter ) { painter->save(); @@ -1073,7 +1073,7 @@ glabels::View::drawHighlightLayer( QPainter* painter ) /// Draw Select Region Layer /// void -glabels::View::drawSelectRegionLayer( QPainter* painter ) +View::drawSelectRegionLayer( QPainter* painter ) { if ( mSelectRegionVisible ) { @@ -1090,3 +1090,19 @@ glabels::View::drawSelectRegionLayer( QPainter* painter ) } } + + +/// +/// Model changed handler +/// +void View::onModelChanged() +{ +} + + +/// +/// Model size changed handler +/// +void View::onModelSizeChanged() +{ +} diff --git a/glabels/View.h b/glabels/View.h index fd4f4d5..90131e2 100644 --- a/glabels/View.h +++ b/glabels/View.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_View_h -#define glabels_View_h +#ifndef View_h +#define View_h #include #include @@ -28,190 +28,184 @@ #include "LabelRegion.h" -namespace glabels +// Forward References +class LabelModel; +class LabelModelObject; +class Handle; + + +/// +/// View Widget +/// +class View : public QWidget { - // Forward References - class LabelModel; - class LabelModelObject; - class Handle; + Q_OBJECT + + ///////////////////////////////////// + // Lifecycle + ///////////////////////////////////// +public: + View( QScrollArea* scrollArea, QWidget* parent = 0 ); - /// - /// View Widget - /// - class View : public QWidget - { - Q_OBJECT - - ///////////////////////////////////// - // Lifecycle - ///////////////////////////////////// - public: - View( QScrollArea* scrollArea, QWidget* parent = 0 ); + ///////////////////////////////////// + // Signals + ///////////////////////////////////// +signals: + void contextMenuActivate(); + void zoomChanged(); + void pointerMoved( const glabels::Distance& x, const glabels::Distance& y ); + void pointerExited(); + void modeChanged(); - ///////////////////////////////////// - // Signals - ///////////////////////////////////// - signals: - void contextMenuActivate(); - void zoomChanged(); - void pointerMoved( const libglabels::Distance& x, const libglabels::Distance& y ); - void pointerExited(); - void modeChanged(); + ///////////////////////////////////// + // Parameters + ///////////////////////////////////// +public: + double zoom() const; + bool markupVisible() const; + bool qridVisible() const; - ///////////////////////////////////// - // Parameters - ///////////////////////////////////// - public: - double zoom() const; - bool markupVisible() const; - bool qridVisible() const; + ///////////////////////////////////// + // Model + ///////////////////////////////////// +public: + void setModel( LabelModel* model ); - ///////////////////////////////////// - // Model - ///////////////////////////////////// - public: - void setModel( LabelModel* model ); + ///////////////////////////////////// + // Visibility operations + ///////////////////////////////////// +public: + void setGridVisible( bool visibleFlag ); + void setMarkupVisible( bool visibleFlag ); - ///////////////////////////////////// - // Visibility operations - ///////////////////////////////////// - public: - void setGridVisible( bool visibleFlag ); - void setMarkupVisible( bool visibleFlag ); + ///////////////////////////////////// + // Zoom operations + ///////////////////////////////////// +public: + void zoomIn(); + void zoomOut(); + void zoom1To1(); + void zoomToFit(); + bool isZoomMax() const; + bool isZoomMin() const; +private: + void setZoomReal( double zoom, bool zoomToFitFlag ); - ///////////////////////////////////// - // Zoom operations - ///////////////////////////////////// - public: - void zoomIn(); - void zoomOut(); - void zoom1To1(); - void zoomToFit(); - bool isZoomMax() const; - bool isZoomMin() const; - private: - void setZoomReal( double zoom, bool zoomToFitFlag ); + ///////////////////////////////////// + // Mode operations + ///////////////////////////////////// +public: + void arrowMode(); + void createBoxMode(); + void createEllipseMode(); + void createLineMode(); + void createImageMode(); + void createTextMode(); + void createBarcodeMode(); - ///////////////////////////////////// - // Mode operations - ///////////////////////////////////// - public: - void arrowMode(); - void createBoxMode(); - void createEllipseMode(); - void createLineMode(); - void createImageMode(); - void createTextMode(); - void createBarcodeMode(); + ///////////////////////////////////// + // Event handlers + ///////////////////////////////////// +protected: + void resizeEvent( QResizeEvent* event ); + void mousePressEvent( QMouseEvent* event ); + void mouseMoveEvent( QMouseEvent* event ); + void mouseReleaseEvent( QMouseEvent* event ); + void leaveEvent( QEvent* event ); + void paintEvent( QPaintEvent* event ); - ///////////////////////////////////// - // Event handlers - ///////////////////////////////////// - protected: - void resizeEvent( QResizeEvent* event ); - void mousePressEvent( QMouseEvent* event ); - void mouseMoveEvent( QMouseEvent* event ); - void mouseReleaseEvent( QMouseEvent* event ); - void leaveEvent( QEvent* event ); - void paintEvent( QPaintEvent* event ); + ///////////////////////////////////// + // Private methods + ///////////////////////////////////// +private: + void handleResizeMotion( const glabels::Distance& xWorld, + const glabels::Distance& yWorld ); + + void drawBgLayer( QPainter* painter ); + void drawGridLayer( QPainter* painter ); + void drawMarkupLayer( QPainter* painter ); + void drawObjectsLayer( QPainter* painter ); + void drawFgLayer( QPainter* painter ); + void drawHighlightLayer( QPainter* painter ); + void drawSelectRegionLayer( QPainter* painter ); - ///////////////////////////////////// - // Private methods - ///////////////////////////////////// - private: - void handleResizeMotion( const libglabels::Distance& xWorld, - const libglabels::Distance& yWorld ); - - void drawBgLayer( QPainter* painter ); - void drawGridLayer( QPainter* painter ); - void drawMarkupLayer( QPainter* painter ); - void drawObjectsLayer( QPainter* painter ); - void drawFgLayer( QPainter* painter ); - void drawHighlightLayer( QPainter* painter ); - void drawSelectRegionLayer( QPainter* painter ); - - - ///////////////////////////////////// - // Private slots - ///////////////////////////////////// - private: - void onModelChanged(); - void onModelSizeChanged(); - - - ///////////////////////////////////// - // Private data - ///////////////////////////////////// - private: - enum State { - IdleState, - ArrowSelectRegion, - ArrowMove, - ArrowResize, - CreateIdle, - CreateDrag - }; - - enum CreateType { - Box, - Ellipse, - Line, - Image, - Text, - Barcode - }; - - QScrollArea* mScrollArea; - - double mZoom; - bool mZoomToFitFlag; - double mScale; - libglabels::Distance mX0; - libglabels::Distance mY0; - - bool mMarkupVisible; - bool mGridVisible; - - double mGridSpacing; - - LabelModel* mModel; - - State mState; - - /* ArrowSelectRegion state */ - bool mSelectRegionVisible; - LabelRegion mSelectRegion; - - /* ArrowMove state */ - libglabels::Distance mMoveLastX; - libglabels::Distance mMoveLastY; - - /* ArrowResize state */ - LabelModelObject* mResizeObject; - Handle* mResizeHandle; - bool mResizeHonorAspect; - - /* CreateDrag state */ - CreateType mCreateObjectType; - LabelModelObject* mCreateObject; - libglabels::Distance mCreateX0; - libglabels::Distance mCreateY0; + ///////////////////////////////////// + // Private slots + ///////////////////////////////////// +private slots: + void onModelChanged(); + void onModelSizeChanged(); + ///////////////////////////////////// + // Private data + ///////////////////////////////////// +private: + enum State { + IdleState, + ArrowSelectRegion, + ArrowMove, + ArrowResize, + CreateIdle, + CreateDrag }; + enum CreateType { + Box, + Ellipse, + Line, + Image, + Text, + Barcode + }; -} + QScrollArea* mScrollArea; + + double mZoom; + bool mZoomToFitFlag; + double mScale; + glabels::Distance mX0; + glabels::Distance mY0; + + bool mMarkupVisible; + bool mGridVisible; + + double mGridSpacing; + + LabelModel* mModel; + + State mState; + + /* ArrowSelectRegion state */ + bool mSelectRegionVisible; + LabelRegion mSelectRegion; + + /* ArrowMove state */ + glabels::Distance mMoveLastX; + glabels::Distance mMoveLastY; + + /* ArrowResize state */ + LabelModelObject* mResizeObject; + Handle* mResizeHandle; + bool mResizeHonorAspect; + + /* CreateDrag state */ + CreateType mCreateObjectType; + LabelModelObject* mCreateObject; + glabels::Distance mCreateX0; + glabels::Distance mCreateY0; +}; -#endif // glabels_View_h + +#endif // View_h diff --git a/glabels/XmlLabelCreator.cpp b/glabels/XmlLabelCreator.cpp index ac87065..7a7795b 100644 --- a/glabels/XmlLabelCreator.cpp +++ b/glabels/XmlLabelCreator.cpp @@ -36,7 +36,7 @@ void -glabels::XmlLabelCreator::writeFile( const LabelModel* label, const QString& fileName ) +XmlLabelCreator::writeFile( const LabelModel* label, const QString& fileName ) { QDomDocument doc; @@ -56,7 +56,7 @@ glabels::XmlLabelCreator::writeFile( const LabelModel* label, const QString& fil void -glabels::XmlLabelCreator::writeBuffer( const LabelModel* label, QString& buffer ) +XmlLabelCreator::writeBuffer( const LabelModel* label, QString& buffer ) { QDomDocument doc; @@ -66,7 +66,7 @@ glabels::XmlLabelCreator::writeBuffer( const LabelModel* label, QString& buffer void -glabels::XmlLabelCreator::createDoc( QDomDocument& doc, const LabelModel* label ) +XmlLabelCreator::createDoc( QDomDocument& doc, const LabelModel* label ) { QDomNode xmlNode( doc.createProcessingInstruction( "xml", "version=\"1.0\"" ) ); doc.appendChild( xmlNode ); @@ -74,7 +74,7 @@ glabels::XmlLabelCreator::createDoc( QDomDocument& doc, const LabelModel* label QDomElement root = doc.createElement( "Glabels-document" ); doc.appendChild( root ); - libglabels::XmlTemplateCreator().createTemplateNode( root, label->tmplate() ); + glabels::XmlTemplateCreator().createTemplateNode( root, label->tmplate() ); createObjectsNode( root, label ); @@ -85,14 +85,14 @@ glabels::XmlLabelCreator::createDoc( QDomDocument& doc, const LabelModel* label void -glabels::XmlLabelCreator::createObjectsNode( QDomElement &parent, const LabelModel* label ) +XmlLabelCreator::createObjectsNode( QDomElement &parent, const LabelModel* label ) { QDomDocument doc = parent.ownerDocument(); QDomElement node = doc.createElement( "Objects" ); parent.appendChild( node ); - libglabels::XmlUtil::setStringAttr( node, "id", "0" ); - libglabels::XmlUtil::setBoolAttr( node, "rotate", label->rotate() ); + glabels::XmlUtil::setStringAttr( node, "id", "0" ); + glabels::XmlUtil::setBoolAttr( node, "rotate", label->rotate() ); foreach ( LabelModelObject* object, label->objectList() ) { @@ -110,39 +110,39 @@ glabels::XmlLabelCreator::createObjectsNode( QDomElement &parent, const LabelMod void -glabels::XmlLabelCreator::createObjectBoxNode( QDomElement &parent, const LabelModelBoxObject* object ) +XmlLabelCreator::createObjectBoxNode( QDomElement &parent, const LabelModelBoxObject* object ) { QDomDocument doc = parent.ownerDocument(); QDomElement node = doc.createElement( "Object-box" ); parent.appendChild( node ); /* position attrs */ - libglabels::XmlUtil::setLengthAttr( node, "x", object->x0() ); - libglabels::XmlUtil::setLengthAttr( node, "y", object->y0() ); + glabels::XmlUtil::setLengthAttr( node, "x", object->x0() ); + glabels::XmlUtil::setLengthAttr( node, "y", object->y0() ); /* size attrs */ - libglabels::XmlUtil::setLengthAttr( node, "w", object->w() ); - libglabels::XmlUtil::setLengthAttr( node, "h", object->h() ); + glabels::XmlUtil::setLengthAttr( node, "w", object->w() ); + glabels::XmlUtil::setLengthAttr( node, "h", object->h() ); /* line attrs */ - libglabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); + glabels::XmlUtil::setLengthAttr( node, "line_width", object->lineWidth() ); if ( object->lineColorNode().fieldFlag() ) { - libglabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); + glabels::XmlUtil::setStringAttr( node, "line_color_field", object->lineColorNode().key() ); } else { - libglabels::XmlUtil::setUIntAttr( node, "line_color", object->lineColorNode().rgba() ); + glabels::XmlUtil::setUIntAttr( node, "line_color", object->lineColorNode().rgba() ); } /* fill attrs */ if ( object->fillColorNode().fieldFlag() ) { - libglabels::XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() ); + glabels::XmlUtil::setStringAttr( node, "fill_color_field", object->fillColorNode().key() ); } else { - libglabels::XmlUtil::setUIntAttr( node, "fill_color", object->fillColorNode().rgba() ); + glabels::XmlUtil::setUIntAttr( node, "fill_color", object->fillColorNode().rgba() ); } /* affine attrs */ @@ -154,108 +154,108 @@ glabels::XmlLabelCreator::createObjectBoxNode( QDomElement &parent, const LabelM void -glabels::XmlLabelCreator::createObjectEllipseNode( QDomElement &parent, const LabelModelEllipseObject* object ) +XmlLabelCreator::createObjectEllipseNode( QDomElement &parent, const LabelModelEllipseObject* object ) { // TODO } void -glabels::XmlLabelCreator::createObjectLineNode( QDomElement &parent, const LabelModelLineObject* object ) +XmlLabelCreator::createObjectLineNode( QDomElement &parent, const LabelModelLineObject* object ) { // TODO } void -glabels::XmlLabelCreator::createObjectImageNode( QDomElement &parent, const LabelModelImageObject* object ) +XmlLabelCreator::createObjectImageNode( QDomElement &parent, const LabelModelImageObject* object ) { // TODO } void -glabels::XmlLabelCreator::createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object ) +XmlLabelCreator::createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object ) { // TODO } void -glabels::XmlLabelCreator::createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object ) +XmlLabelCreator::createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object ) { // TODO } void -glabels::XmlLabelCreator::createObjectTopLevelSpanNode( QDomElement &parent, const LabelModelTextObject* object ) +XmlLabelCreator::createObjectTopLevelSpanNode( QDomElement &parent, const LabelModelTextObject* object ) { // TODO } void -glabels::XmlLabelCreator::createAffineAttrs( QDomElement &node, const LabelModelObject* object ) +XmlLabelCreator::createAffineAttrs( QDomElement &node, const LabelModelObject* object ) { QMatrix a = object->matrix(); - libglabels::XmlUtil::setDoubleAttr( node, "a0", a.m11() ); - libglabels::XmlUtil::setDoubleAttr( node, "a1", a.m12() ); - libglabels::XmlUtil::setDoubleAttr( node, "a2", a.m21() ); - libglabels::XmlUtil::setDoubleAttr( node, "a3", a.m22() ); - libglabels::XmlUtil::setDoubleAttr( node, "a4", a.dx() ); - libglabels::XmlUtil::setDoubleAttr( node, "a5", a.dy() ); + glabels::XmlUtil::setDoubleAttr( node, "a0", a.m11() ); + glabels::XmlUtil::setDoubleAttr( node, "a1", a.m12() ); + glabels::XmlUtil::setDoubleAttr( node, "a2", a.m21() ); + glabels::XmlUtil::setDoubleAttr( node, "a3", a.m22() ); + glabels::XmlUtil::setDoubleAttr( node, "a4", a.dx() ); + glabels::XmlUtil::setDoubleAttr( node, "a5", a.dy() ); } void -glabels::XmlLabelCreator::createShadowAttrs( QDomElement &node, const LabelModelObject* object ) +XmlLabelCreator::createShadowAttrs( QDomElement &node, const LabelModelObject* object ) { if ( object->shadow() ) { - libglabels::XmlUtil::setBoolAttr( node, "shadow", object->shadow() ); + glabels::XmlUtil::setBoolAttr( node, "shadow", object->shadow() ); - libglabels::XmlUtil::setLengthAttr( node, "shadow_x", object->shadowX() ); - libglabels::XmlUtil::setLengthAttr( node, "shadow_y", object->shadowY() ); + glabels::XmlUtil::setLengthAttr( node, "shadow_x", object->shadowX() ); + glabels::XmlUtil::setLengthAttr( node, "shadow_y", object->shadowY() ); if ( object->fillColorNode().fieldFlag() ) { - libglabels::XmlUtil::setStringAttr( node, "shadow_color_field", object->shadowColorNode().key() ); + glabels::XmlUtil::setStringAttr( node, "shadow_color_field", object->shadowColorNode().key() ); } else { - libglabels::XmlUtil::setUIntAttr( node, "shadow_color", object->shadowColorNode().rgba() ); + glabels::XmlUtil::setUIntAttr( node, "shadow_color", object->shadowColorNode().rgba() ); } - libglabels::XmlUtil::setDoubleAttr( node, "shadow_opacity", object->shadowOpacity() ); + glabels::XmlUtil::setDoubleAttr( node, "shadow_opacity", object->shadowOpacity() ); } } void -glabels::XmlLabelCreator::createMergeNode( QDomElement &parent, const LabelModel* label ) +XmlLabelCreator::createMergeNode( QDomElement &parent, const LabelModel* label ) { // TODO } void -glabels::XmlLabelCreator::createDataNode( QDomElement &parent, const LabelModel* label ) +XmlLabelCreator::createDataNode( QDomElement &parent, const LabelModel* label ) { // TODO } void -glabels::XmlLabelCreator::createPixdataNode( QDomElement &parent, const LabelModel* label, const QString& name ) +XmlLabelCreator::createPixdataNode( QDomElement &parent, const LabelModel* label, const QString& name ) { // TODO } void -glabels::XmlLabelCreator::createSvgFileNode( QDomElement &parent, const LabelModel* label, const QString& name ) +XmlLabelCreator::createSvgFileNode( QDomElement &parent, const LabelModel* label, const QString& name ) { // TODO } diff --git a/glabels/XmlLabelCreator.h b/glabels/XmlLabelCreator.h index 5220677..a681c82 100644 --- a/glabels/XmlLabelCreator.h +++ b/glabels/XmlLabelCreator.h @@ -18,57 +18,54 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_XmlLabelCreator_h -#define glabels_XmlLabelCreator_h +#ifndef XmlLabelCreator_h +#define XmlLabelCreator_h #include #include -namespace glabels +class LabelModel; +class LabelModelObject; +class LabelModelBoxObject; +class LabelModelEllipseObject; +class LabelModelLineObject; +class LabelModelImageObject; +class LabelModelBarcodeObject; +class LabelModelTextObject; + + +/// +/// XmlLabelCreator +/// +class XmlLabelCreator : public QObject { - class LabelModel; - class LabelModelObject; - class LabelModelBoxObject; - class LabelModelEllipseObject; - class LabelModelLineObject; - class LabelModelImageObject; - class LabelModelBarcodeObject; - class LabelModelTextObject; + Q_OBJECT + +public: + static void writeFile( const LabelModel* label, const QString& fileName ); + static void writeBuffer( const LabelModel* label, QString& buffer ); + +private: + static void createDoc( QDomDocument& doc, const LabelModel* label ); + static void createRootNode( const LabelModel* label ); + static void createObjectsNode( QDomElement &parent, const LabelModel* label ); + static void createObjectBoxNode( QDomElement &parent, const LabelModelBoxObject* object ); + static void createObjectEllipseNode( QDomElement &parent, const LabelModelEllipseObject* object ); + static void createObjectLineNode( QDomElement &parent, const LabelModelLineObject* object ); + static void createObjectImageNode( QDomElement &parent, const LabelModelImageObject* object ); + static void createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object ); + static void createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object ); + static void createObjectTopLevelSpanNode( QDomElement &parent, const LabelModelTextObject* object ); + static void createAffineAttrs( QDomElement &node, const LabelModelObject* object ); + static void createShadowAttrs( QDomElement &node, const LabelModelObject* object ); + static void createMergeNode( QDomElement &parent, const LabelModel* label ); + static void createDataNode( QDomElement &parent, const LabelModel* label ); + static void createPixdataNode( QDomElement &parent, const LabelModel* label, const QString& name ); + static void createSvgFileNode( QDomElement &parent, const LabelModel* label, const QString& name ); + +}; - /// - /// XmlLabelCreator - /// - class XmlLabelCreator : public QObject - { - Q_OBJECT - - public: - static void writeFile( const LabelModel* label, const QString& fileName ); - static void writeBuffer( const LabelModel* label, QString& buffer ); - - private: - static void createDoc( QDomDocument& doc, const LabelModel* label ); - static void createRootNode( const LabelModel* label ); - static void createObjectsNode( QDomElement &parent, const LabelModel* label ); - static void createObjectBoxNode( QDomElement &parent, const LabelModelBoxObject* object ); - static void createObjectEllipseNode( QDomElement &parent, const LabelModelEllipseObject* object ); - static void createObjectLineNode( QDomElement &parent, const LabelModelLineObject* object ); - static void createObjectImageNode( QDomElement &parent, const LabelModelImageObject* object ); - static void createObjectBarcodeNode( QDomElement &parent, const LabelModelBarcodeObject* object ); - static void createObjectTextNode( QDomElement &parent, const LabelModelTextObject* object ); - static void createObjectTopLevelSpanNode( QDomElement &parent, const LabelModelTextObject* object ); - static void createAffineAttrs( QDomElement &node, const LabelModelObject* object ); - static void createShadowAttrs( QDomElement &node, const LabelModelObject* object ); - static void createMergeNode( QDomElement &parent, const LabelModel* label ); - static void createDataNode( QDomElement &parent, const LabelModel* label ); - static void createPixdataNode( QDomElement &parent, const LabelModel* label, const QString& name ); - static void createSvgFileNode( QDomElement &parent, const LabelModel* label, const QString& name ); - - }; - -} - -#endif // glabels_XmlLabelCreator_h +#endif // XmlLabelCreator_h diff --git a/glabels/XmlLabelParser.cpp b/glabels/XmlLabelParser.cpp index 6153916..40f439c 100644 --- a/glabels/XmlLabelParser.cpp +++ b/glabels/XmlLabelParser.cpp @@ -36,8 +36,8 @@ #include -glabels::LabelModel* -glabels::XmlLabelParser::readFile( const QString& fileName ) +LabelModel* +XmlLabelParser::readFile( const QString& fileName ) { QFile file( fileName ); @@ -88,8 +88,8 @@ glabels::XmlLabelParser::readFile( const QString& fileName ) } -glabels::LabelModel* -glabels::XmlLabelParser::readBuffer( const QString& buffer ) +LabelModel* +XmlLabelParser::readBuffer( const QString& buffer ) { QDomDocument doc; QString errorString; @@ -116,7 +116,7 @@ glabels::XmlLabelParser::readBuffer( const QString& buffer ) void -glabels::XmlLabelParser::gunzip( const QByteArray& data, QByteArray& result ) +XmlLabelParser::gunzip( const QByteArray& data, QByteArray& result ) { result.clear(); @@ -165,10 +165,10 @@ glabels::XmlLabelParser::gunzip( const QByteArray& data, QByteArray& result ) } -glabels::LabelModel* -glabels::XmlLabelParser::parseRootNode( const QDomElement &node ) +LabelModel* +XmlLabelParser::parseRootNode( const QDomElement &node ) { - using namespace libglabels; + using namespace glabels; LabelModel* label = new LabelModel(); @@ -220,7 +220,7 @@ glabels::XmlLabelParser::parseRootNode( const QDomElement &node ) void -glabels::XmlLabelParser::parseObjectsNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseObjectsNode( const QDomElement &node, LabelModel* label ) { for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() ) { @@ -259,9 +259,9 @@ glabels::XmlLabelParser::parseObjectsNode( const QDomElement &node, LabelModel* void -glabels::XmlLabelParser::parseObjectBoxNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseObjectBoxNode( const QDomElement &node, LabelModel* label ) { - using namespace libglabels; + using namespace glabels; LabelModelBoxObject* object = new LabelModelBoxObject(); label->addObject( object ); @@ -303,45 +303,45 @@ glabels::XmlLabelParser::parseObjectBoxNode( const QDomElement &node, LabelModel void -glabels::XmlLabelParser::parseObjectEllipseNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseObjectEllipseNode( const QDomElement &node, LabelModel* label ) { } void -glabels::XmlLabelParser::parseObjectLineNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseObjectLineNode( const QDomElement &node, LabelModel* label ) { } void -glabels::XmlLabelParser::parseObjectImageNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseObjectImageNode( const QDomElement &node, LabelModel* label ) { } void -glabels::XmlLabelParser::parseObjectBarcodeNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseObjectBarcodeNode( const QDomElement &node, LabelModel* label ) { } void -glabels::XmlLabelParser::parseObjectTextNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseObjectTextNode( const QDomElement &node, LabelModel* label ) { } void -glabels::XmlLabelParser::parseTopLevelSpanNode( const QDomElement &node, LabelModelTextObject* object ) +XmlLabelParser::parseTopLevelSpanNode( const QDomElement &node, LabelModelTextObject* object ) { } void -glabels::XmlLabelParser::parseAffineAttrs( const QDomElement &node, LabelModelObject* object ) +XmlLabelParser::parseAffineAttrs( const QDomElement &node, LabelModelObject* object ) { - using namespace libglabels; + using namespace glabels; double a[6]; @@ -357,9 +357,9 @@ glabels::XmlLabelParser::parseAffineAttrs( const QDomElement &node, LabelModelOb void -glabels::XmlLabelParser::parseShadowAttrs( const QDomElement &node, LabelModelObject* object ) +XmlLabelParser::parseShadowAttrs( const QDomElement &node, LabelModelObject* object ) { - using namespace libglabels; + using namespace glabels; object->setShadow( XmlUtil::getBoolAttr( node, "shadow", false ) ); @@ -380,25 +380,25 @@ glabels::XmlLabelParser::parseShadowAttrs( const QDomElement &node, LabelModelOb void -glabels::XmlLabelParser::parseMergeNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseMergeNode( const QDomElement &node, LabelModel* label ) { } void -glabels::XmlLabelParser::parseDataNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseDataNode( const QDomElement &node, LabelModel* label ) { } void -glabels::XmlLabelParser::parsePixdataNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parsePixdataNode( const QDomElement &node, LabelModel* label ) { } void -glabels::XmlLabelParser::parseFileNode( const QDomElement &node, LabelModel* label ) +XmlLabelParser::parseFileNode( const QDomElement &node, LabelModel* label ) { } diff --git a/glabels/XmlLabelParser.h b/glabels/XmlLabelParser.h index 5536c92..ad985c0 100644 --- a/glabels/XmlLabelParser.h +++ b/glabels/XmlLabelParser.h @@ -18,57 +18,54 @@ * along with gLabels-qt. If not, see . */ -#ifndef glabels_XmlLabelParser_h -#define glabels_XmlLabelParser_h +#ifndef XmlLabelParser_h +#define XmlLabelParser_h #include #include -namespace glabels +class LabelModel; +class LabelModelObject; +class LabelModelBoxObject; +class LabelModelEllipseObject; +class LabelModelLineObject; +class LabelModelImageObject; +class LabelModelBarcodeObject; +class LabelModelTextObject; + + +/// +/// XmlLabelParser +/// +class XmlLabelParser : public QObject { - class LabelModel; - class LabelModelObject; - class LabelModelBoxObject; - class LabelModelEllipseObject; - class LabelModelLineObject; - class LabelModelImageObject; - class LabelModelBarcodeObject; - class LabelModelTextObject; + Q_OBJECT + +public: + static LabelModel* readFile( const QString& fileName ); + static LabelModel* readBuffer( const QString& buffer ); + +private: + static void gunzip( const QByteArray& gzippedData, QByteArray& data ); + static LabelModel* parseRootNode( const QDomElement &node ); + static void parseObjectsNode( const QDomElement &node, LabelModel* label ); + static void parseObjectBoxNode( const QDomElement &node, LabelModel* label ); + static void parseObjectEllipseNode( const QDomElement &node, LabelModel* label ); + static void parseObjectLineNode( const QDomElement &node, LabelModel* label ); + static void parseObjectImageNode( const QDomElement &node, LabelModel* label ); + static void parseObjectBarcodeNode( const QDomElement &node, LabelModel* label ); + static void parseObjectTextNode( const QDomElement &node, LabelModel* label ); + static void parseTopLevelSpanNode( const QDomElement &node, LabelModelTextObject* object ); + static void parseAffineAttrs( const QDomElement &node, LabelModelObject* object ); + static void parseShadowAttrs( const QDomElement &node, LabelModelObject* object ); + static void parseMergeNode( const QDomElement &node, LabelModel* label ); + static void parseDataNode( const QDomElement &node, LabelModel* label ); + static void parsePixdataNode( const QDomElement &node, LabelModel* label ); + static void parseFileNode( const QDomElement &node, LabelModel* label ); + +}; - /// - /// XmlLabelParser - /// - class XmlLabelParser : public QObject - { - Q_OBJECT - - public: - static LabelModel* readFile( const QString& fileName ); - static LabelModel* readBuffer( const QString& buffer ); - - private: - static void gunzip( const QByteArray& gzippedData, QByteArray& data ); - static LabelModel* parseRootNode( const QDomElement &node ); - static void parseObjectsNode( const QDomElement &node, LabelModel* label ); - static void parseObjectBoxNode( const QDomElement &node, LabelModel* label ); - static void parseObjectEllipseNode( const QDomElement &node, LabelModel* label ); - static void parseObjectLineNode( const QDomElement &node, LabelModel* label ); - static void parseObjectImageNode( const QDomElement &node, LabelModel* label ); - static void parseObjectBarcodeNode( const QDomElement &node, LabelModel* label ); - static void parseObjectTextNode( const QDomElement &node, LabelModel* label ); - static void parseTopLevelSpanNode( const QDomElement &node, LabelModelTextObject* object ); - static void parseAffineAttrs( const QDomElement &node, LabelModelObject* object ); - static void parseShadowAttrs( const QDomElement &node, LabelModelObject* object ); - static void parseMergeNode( const QDomElement &node, LabelModel* label ); - static void parseDataNode( const QDomElement &node, LabelModel* label ); - static void parsePixdataNode( const QDomElement &node, LabelModel* label ); - static void parseFileNode( const QDomElement &node, LabelModel* label ); - - }; - -} - -#endif // glabels_XmlLabelParser_h +#endif // XmlLabelParser_h diff --git a/glabels/glabels_main.cpp b/glabels/glabels_main.cpp index 39db4c8..9eeee7c 100644 --- a/glabels/glabels_main.cpp +++ b/glabels/glabels_main.cpp @@ -24,9 +24,6 @@ #include "File.h" #include "libglabels/Db.h" -using namespace glabels; -using namespace libglabels; - int main( int argc, char **argv ) { @@ -36,13 +33,13 @@ int main( int argc, char **argv ) QCoreApplication::setOrganizationDomain( "glabels.org" ); QCoreApplication::setApplicationName( "glabels-qt" ); - Db::init(); + glabels::Db::init(); ////// TEMPORARY TESTING //////// #if 0 - Db::printKnownPapers(); - Db::printKnownCategories(); - Db::printKnownVendors(); - Db::printKnownTemplates(); + glabels::Db::printKnownPapers(); + glabels::Db::printKnownCategories(); + glabels::Db::printKnownVendors(); + glabels::Db::printKnownTemplates(); #endif ///////////////////////////////// diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index 5632232..46aa330 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -372,7 +372,7 @@ - + @@ -451,7 +451,7 @@ - + @@ -539,7 +539,7 @@ - + @@ -679,7 +679,7 @@ - + @@ -802,7 +802,7 @@ - + @@ -889,7 +889,7 @@ - + @@ -950,7 +950,7 @@ - + @@ -1373,7 +1373,7 @@ - + @@ -1433,7 +1433,7 @@ - glabels::ColorButton + ColorButton QPushButton
ColorButton.h
@@ -1441,7 +1441,7 @@
- glabels::FieldButton + FieldButton QPushButton
FieldButton.h
diff --git a/glabels/ui/PrintView.ui b/glabels/ui/PrintView.ui index 178d373..c4f82fe 100644 --- a/glabels/ui/PrintView.ui +++ b/glabels/ui/PrintView.ui @@ -26,7 +26,7 @@ QLayout::SetDefaultConstraint - + 0 @@ -453,7 +453,7 @@ - glabels::Preview + Preview QWidget
Preview.h
1 diff --git a/glabels/ui/PropertiesView.ui b/glabels/ui/PropertiesView.ui index e495f98..9407214 100644 --- a/glabels/ui/PropertiesView.ui +++ b/glabels/ui/PropertiesView.ui @@ -29,7 +29,7 @@ - + 0 @@ -356,7 +356,7 @@ - glabels::SimplePreview + SimplePreview QGraphicsView
SimplePreview.h
1 diff --git a/glabels/ui/SelectProductDialog.ui b/glabels/ui/SelectProductDialog.ui index 7112b45..e06629c 100644 --- a/glabels/ui/SelectProductDialog.ui +++ b/glabels/ui/SelectProductDialog.ui @@ -134,7 +134,7 @@
- + false @@ -182,7 +182,7 @@ - glabels::TemplatePicker + TemplatePicker QListWidget
TemplatePicker.h
diff --git a/libglabels/Category.cpp b/libglabels/Category.cpp index 8f41a8e..ef9451f 100644 --- a/libglabels/Category.cpp +++ b/libglabels/Category.cpp @@ -1,6 +1,6 @@ /* Category.cpp * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -21,7 +21,7 @@ #include "Category.h" -namespace libglabels +namespace glabels { Category::Category( const QString &id, const QString &name ) diff --git a/libglabels/Category.h b/libglabels/Category.h index 41fb37e..a4054ff 100644 --- a/libglabels/Category.h +++ b/libglabels/Category.h @@ -1,6 +1,6 @@ /* Category.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,14 +18,14 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Category_h -#define libglabels_Category_h +#ifndef glabels_Category_h +#define glabels_Category_h #include -namespace libglabels +namespace glabels { class Category @@ -50,4 +50,4 @@ namespace libglabels #include "Category.inl" -#endif // libglabels_Category_h +#endif // glabels_Category_h diff --git a/libglabels/Category.inl b/libglabels/Category.inl index 7f9f47f..7838e8a 100644 --- a/libglabels/Category.inl +++ b/libglabels/Category.inl @@ -1,6 +1,6 @@ /* Category.inl * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline const QString& Category::id() const diff --git a/libglabels/Config.h.in b/libglabels/Config.h.in index 71af495..22e95c8 100644 --- a/libglabels/Config.h.in +++ b/libglabels/Config.h.in @@ -1,6 +1,6 @@ /* Config.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,11 +18,11 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Config_h -#define libglabels_Config_h +#ifndef glabels_Config_h +#define glabels_Config_h -namespace libglabels +namespace glabels { namespace Config @@ -33,4 +33,4 @@ namespace libglabels } -#endif // libglabels_Config_h +#endif // glabels_Config_h diff --git a/libglabels/Constants.h b/libglabels/Constants.h index 6bbf98b..3695b22 100644 --- a/libglabels/Constants.h +++ b/libglabels/Constants.h @@ -18,11 +18,11 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Constants_h -#define libglabels_Constants_h +#ifndef glabels_Constants_h +#define glabels_Constants_h -namespace libglabels +namespace glabels { const double PTS_PER_PT = 1.0; @@ -33,4 +33,4 @@ namespace libglabels } -#endif // libglabels_Constants_h +#endif // glabels_Constants_h diff --git a/libglabels/Db.cpp b/libglabels/Db.cpp index 3e3e4d5..5f16816 100644 --- a/libglabels/Db.cpp +++ b/libglabels/Db.cpp @@ -33,14 +33,14 @@ namespace { - bool partNameLessThan( const libglabels::Template *a, const libglabels::Template *b ) + bool partNameLessThan( const glabels::Template *a, const glabels::Template *b ) { - return libglabels::StrUtil::comparePartNames( a->name(), b->name() ) < 0; + return glabels::StrUtil::comparePartNames( a->name(), b->name() ) < 0; } } -namespace libglabels +namespace glabels { QList Db::mPapers; diff --git a/libglabels/Db.h b/libglabels/Db.h index 03b112e..50b0c38 100644 --- a/libglabels/Db.h +++ b/libglabels/Db.h @@ -1,6 +1,6 @@ /* Db.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Db_h -#define libglabels_Db_h +#ifndef glabels_Db_h +#define glabels_Db_h #include @@ -33,7 +33,7 @@ #include "Template.h" -namespace libglabels +namespace glabels { class Db @@ -140,4 +140,4 @@ namespace libglabels #include "Db.inl" -#endif // libglabels_Db_h +#endif // glabels_Db_h diff --git a/libglabels/Db.inl b/libglabels/Db.inl index 5501ddb..9c2dfaf 100644 --- a/libglabels/Db.inl +++ b/libglabels/Db.inl @@ -1,6 +1,6 @@ /* Db.inl * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline const QList& Db::papers() diff --git a/libglabels/Distance.cpp b/libglabels/Distance.cpp index feee0f9..dc45e0c 100644 --- a/libglabels/Distance.cpp +++ b/libglabels/Distance.cpp @@ -24,7 +24,7 @@ #include -namespace libglabels +namespace glabels { QString Distance::toId( Units units ) diff --git a/libglabels/Distance.h b/libglabels/Distance.h index c128ee8..fb35bc1 100644 --- a/libglabels/Distance.h +++ b/libglabels/Distance.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Distance_h -#define libglabels_Distance_h +#ifndef glabels_Distance_h +#define glabels_Distance_h #include @@ -27,7 +27,7 @@ #include "Constants.h" -namespace libglabels +namespace glabels { @@ -104,4 +104,4 @@ namespace libglabels #include "Distance.inl" -#endif // libglabels_Distance_h +#endif // glabels_Distance_h diff --git a/libglabels/Distance.inl b/libglabels/Distance.inl index 4cbf628..0317941 100644 --- a/libglabels/Distance.inl +++ b/libglabels/Distance.inl @@ -22,7 +22,7 @@ #include -namespace libglabels +namespace glabels { inline Distance::Distance() : mDPts(0) diff --git a/libglabels/Frame.cpp b/libglabels/Frame.cpp index 24de7e1..7c17c5c 100644 --- a/libglabels/Frame.cpp +++ b/libglabels/Frame.cpp @@ -1,6 +1,6 @@ /* Frame.cpp * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -23,7 +23,7 @@ #include "Markup.h" -namespace libglabels +namespace glabels { Frame::Frame( const QString& id ) diff --git a/libglabels/Frame.h b/libglabels/Frame.h index 59c7771..7a97ae4 100644 --- a/libglabels/Frame.h +++ b/libglabels/Frame.h @@ -1,6 +1,6 @@ /* Frame.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Frame_h -#define libglabels_Frame_h +#ifndef glabels_Frame_h +#define glabels_Frame_h #include #include @@ -32,7 +32,7 @@ #include "Layout.h" -namespace libglabels +namespace glabels { class Markup; // Forward reference @@ -84,4 +84,4 @@ namespace libglabels #include "Frame.inl" -#endif // libglabels_Frame_h +#endif // glabels_Frame_h diff --git a/libglabels/Frame.inl b/libglabels/Frame.inl index 0b5edb0..e585d90 100644 --- a/libglabels/Frame.inl +++ b/libglabels/Frame.inl @@ -1,6 +1,6 @@ /* Frame.inl * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline const QString& Frame::id() const diff --git a/libglabels/FrameCd.cpp b/libglabels/FrameCd.cpp index 351a9e2..48054a6 100644 --- a/libglabels/FrameCd.cpp +++ b/libglabels/FrameCd.cpp @@ -27,7 +27,7 @@ #include -namespace libglabels +namespace glabels { FrameCd::FrameCd( const Distance& r1, diff --git a/libglabels/FrameCd.h b/libglabels/FrameCd.h index f5df236..e006020 100644 --- a/libglabels/FrameCd.h +++ b/libglabels/FrameCd.h @@ -18,13 +18,13 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_FrameCd_h -#define libglabels_FrameCd_h +#ifndef glabels_FrameCd_h +#define glabels_FrameCd_h #include "Frame.h" -namespace libglabels +namespace glabels { class FrameCd : public Frame @@ -72,4 +72,4 @@ namespace libglabels #include "FrameCd.inl" -#endif // libglabels_FrameCd_h +#endif // glabels_FrameCd_h diff --git a/libglabels/FrameCd.inl b/libglabels/FrameCd.inl index 02872a4..e61d702 100644 --- a/libglabels/FrameCd.inl +++ b/libglabels/FrameCd.inl @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline Distance FrameCd::r1() const diff --git a/libglabels/FrameEllipse.cpp b/libglabels/FrameEllipse.cpp index 75da514..1aa9aaf 100644 --- a/libglabels/FrameEllipse.cpp +++ b/libglabels/FrameEllipse.cpp @@ -26,7 +26,7 @@ #include "privateConstants.h" -namespace libglabels +namespace glabels { FrameEllipse::FrameEllipse( const Distance& w, diff --git a/libglabels/FrameEllipse.h b/libglabels/FrameEllipse.h index 9d09a84..0cace5e 100644 --- a/libglabels/FrameEllipse.h +++ b/libglabels/FrameEllipse.h @@ -18,13 +18,13 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_FrameEllipse_h -#define libglabels_FrameEllipse_h +#ifndef glabels_FrameEllipse_h +#define glabels_FrameEllipse_h #include "Frame.h" -namespace libglabels +namespace glabels { class FrameEllipse : public Frame @@ -67,4 +67,4 @@ namespace libglabels #include "FrameEllipse.inl" -#endif // libglabels_FrameEllipse_h +#endif // glabels_FrameEllipse_h diff --git a/libglabels/FrameEllipse.inl b/libglabels/FrameEllipse.inl index a403cb9..0aee57a 100644 --- a/libglabels/FrameEllipse.inl +++ b/libglabels/FrameEllipse.inl @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline Distance FrameEllipse::waste() const diff --git a/libglabels/FrameRect.cpp b/libglabels/FrameRect.cpp index 76a0ab5..d2f1039 100644 --- a/libglabels/FrameRect.cpp +++ b/libglabels/FrameRect.cpp @@ -26,7 +26,7 @@ #include "privateConstants.h" -namespace libglabels +namespace glabels { FrameRect::FrameRect( const Distance& w, diff --git a/libglabels/FrameRect.h b/libglabels/FrameRect.h index 01442e0..11f4ca2 100644 --- a/libglabels/FrameRect.h +++ b/libglabels/FrameRect.h @@ -1,6 +1,6 @@ /* FrameRect.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,13 +18,13 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_FrameRect_h -#define libglabels_FrameRect_h +#ifndef glabels_FrameRect_h +#define glabels_FrameRect_h #include "Frame.h" -namespace libglabels +namespace glabels { class FrameRect : public Frame @@ -73,4 +73,4 @@ namespace libglabels #include "FrameRect.inl" -#endif // libglabels_FrameRect_h +#endif // glabels_FrameRect_h diff --git a/libglabels/FrameRect.inl b/libglabels/FrameRect.inl index b3be22f..ab6abb8 100644 --- a/libglabels/FrameRect.inl +++ b/libglabels/FrameRect.inl @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline Distance FrameRect::r() const diff --git a/libglabels/FrameRound.cpp b/libglabels/FrameRound.cpp index 865380f..d429bcc 100644 --- a/libglabels/FrameRound.cpp +++ b/libglabels/FrameRound.cpp @@ -26,7 +26,7 @@ #include "privateConstants.h" -namespace libglabels +namespace glabels { FrameRound::FrameRound( const Distance& r, diff --git a/libglabels/FrameRound.h b/libglabels/FrameRound.h index 694c588..e8ae5bd 100644 --- a/libglabels/FrameRound.h +++ b/libglabels/FrameRound.h @@ -18,13 +18,13 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_FrameRound_h -#define libglabels_FrameRound_h +#ifndef glabels_FrameRound_h +#define glabels_FrameRound_h #include "Frame.h" -namespace libglabels +namespace glabels { class FrameRound : public Frame @@ -66,4 +66,4 @@ namespace libglabels #include "FrameRound.inl" -#endif // libglabels_FrameRound_h +#endif // glabels_FrameRound_h diff --git a/libglabels/FrameRound.inl b/libglabels/FrameRound.inl index fb8a727..bade556 100644 --- a/libglabels/FrameRound.inl +++ b/libglabels/FrameRound.inl @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline Distance FrameRound::r() const diff --git a/libglabels/Layout.cpp b/libglabels/Layout.cpp index bd5f300..03e583b 100644 --- a/libglabels/Layout.cpp +++ b/libglabels/Layout.cpp @@ -25,7 +25,7 @@ #include "privateConstants.h" -namespace libglabels +namespace glabels { Layout::Layout( int nx, diff --git a/libglabels/Layout.h b/libglabels/Layout.h index 5598127..308717a 100644 --- a/libglabels/Layout.h +++ b/libglabels/Layout.h @@ -18,13 +18,13 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Layout_h -#define libglabels_Layout_h +#ifndef glabels_Layout_h +#define glabels_Layout_h #include "Distance.h" -namespace libglabels +namespace glabels { class Layout @@ -70,4 +70,4 @@ namespace libglabels #include "Layout.inl" -#endif // libglabels_Layout_h +#endif // glabels_Layout_h diff --git a/libglabels/Layout.inl b/libglabels/Layout.inl index 70e8e03..a4b41e4 100644 --- a/libglabels/Layout.inl +++ b/libglabels/Layout.inl @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline int Layout::nx() const diff --git a/libglabels/Markup.cpp b/libglabels/Markup.cpp index e178284..b965457 100644 --- a/libglabels/Markup.cpp +++ b/libglabels/Markup.cpp @@ -21,7 +21,7 @@ #include "Markup.h" -namespace libglabels +namespace glabels { const QPainterPath& Markup::path() const diff --git a/libglabels/Markup.h b/libglabels/Markup.h index df5b814..c2dd5c4 100644 --- a/libglabels/Markup.h +++ b/libglabels/Markup.h @@ -18,15 +18,15 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Markup_h -#define libglabels_Markup_h +#ifndef glabels_Markup_h +#define glabels_Markup_h #include #include "Frame.h" -namespace libglabels +namespace glabels { class Markup @@ -155,4 +155,4 @@ namespace libglabels #include "Markup.inl" -#endif // libglabels_Markup_h +#endif // glabels_Markup_h diff --git a/libglabels/Markup.inl b/libglabels/Markup.inl index f06e60c..ff41ece 100644 --- a/libglabels/Markup.inl +++ b/libglabels/Markup.inl @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline Distance MarkupMargin::size() const { return mSize; } diff --git a/libglabels/MiniPreviewPixmap.cpp b/libglabels/MiniPreviewPixmap.cpp index e08da3f..8637f89 100644 --- a/libglabels/MiniPreviewPixmap.cpp +++ b/libglabels/MiniPreviewPixmap.cpp @@ -35,7 +35,7 @@ namespace } -namespace libglabels +namespace glabels { MiniPreviewPixmap::MiniPreviewPixmap() diff --git a/libglabels/MiniPreviewPixmap.h b/libglabels/MiniPreviewPixmap.h index 5771bf8..4996c64 100644 --- a/libglabels/MiniPreviewPixmap.h +++ b/libglabels/MiniPreviewPixmap.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_MiniPreviewPixmap_h -#define libglabels_MiniPreviewPixmap_h +#ifndef glabels_MiniPreviewPixmap_h +#define glabels_MiniPreviewPixmap_h #include @@ -27,7 +27,7 @@ #include "Point.h" -namespace libglabels +namespace glabels { class Template; // Forward reference class Frame; // Forward reference @@ -52,4 +52,4 @@ namespace libglabels } -#endif // libglabels_MiniPreviewPixmap_h +#endif // glabels_MiniPreviewPixmap_h diff --git a/libglabels/Paper.cpp b/libglabels/Paper.cpp index f9e4ce7..8b21fa6 100644 --- a/libglabels/Paper.cpp +++ b/libglabels/Paper.cpp @@ -21,7 +21,7 @@ #include "Paper.h" -namespace libglabels +namespace glabels { Paper::Paper( const QString& id, diff --git a/libglabels/Paper.h b/libglabels/Paper.h index 1adc0de..a19b2c7 100644 --- a/libglabels/Paper.h +++ b/libglabels/Paper.h @@ -18,15 +18,15 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Paper_h -#define libglabels_Paper_h +#ifndef glabels_Paper_h +#define glabels_Paper_h #include #include "Distance.h" -namespace libglabels +namespace glabels { class Paper @@ -67,4 +67,4 @@ namespace libglabels #include "Paper.inl" -#endif // libglabels_Paper_h +#endif // glabels_Paper_h diff --git a/libglabels/Paper.inl b/libglabels/Paper.inl index 4000dbc..65a03ea 100644 --- a/libglabels/Paper.inl +++ b/libglabels/Paper.inl @@ -1,6 +1,6 @@ /* Paper.inl * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline const QString& Paper::id() const { return mId; } diff --git a/libglabels/Point.cpp b/libglabels/Point.cpp index e103c5e..0dac720 100644 --- a/libglabels/Point.cpp +++ b/libglabels/Point.cpp @@ -1,6 +1,6 @@ /* Point.cpp * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -21,7 +21,7 @@ #include "Point.h" -namespace libglabels +namespace glabels { Point::Point() : mX(Distance(0)), mY(Distance(0)) diff --git a/libglabels/Point.h b/libglabels/Point.h index 13ca035..a597efa 100644 --- a/libglabels/Point.h +++ b/libglabels/Point.h @@ -18,13 +18,13 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Point_h -#define libglabels_Point_h +#ifndef glabels_Point_h +#define glabels_Point_h #include "Distance.h" -namespace libglabels +namespace glabels { class Point @@ -51,4 +51,4 @@ namespace libglabels #include "Point.inl" -#endif // libglabels_Point_h +#endif // glabels_Point_h diff --git a/libglabels/Point.inl b/libglabels/Point.inl index 6da97b5..5930528 100644 --- a/libglabels/Point.inl +++ b/libglabels/Point.inl @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline Distance Point::x() const diff --git a/libglabels/StrUtil.cpp b/libglabels/StrUtil.cpp index 3cd887a..6e354c1 100644 --- a/libglabels/StrUtil.cpp +++ b/libglabels/StrUtil.cpp @@ -1,6 +1,6 @@ /* StrUtil.cpp * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -35,7 +35,7 @@ namespace } -namespace libglabels +namespace glabels { namespace StrUtil diff --git a/libglabels/StrUtil.h b/libglabels/StrUtil.h index 04bc1c0..9bc47f9 100644 --- a/libglabels/StrUtil.h +++ b/libglabels/StrUtil.h @@ -1,6 +1,6 @@ /* StrUtil.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,13 +18,13 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_StrUtil_h -#define libglabels_StrUtil_h +#ifndef glabels_StrUtil_h +#define glabels_StrUtil_h #include -namespace libglabels +namespace glabels { namespace StrUtil @@ -38,4 +38,4 @@ namespace libglabels } -#endif // libglabels_StrUtil_h +#endif // glabels_StrUtil_h diff --git a/libglabels/Template.cpp b/libglabels/Template.cpp index 77b5c67..8e9ac1f 100644 --- a/libglabels/Template.cpp +++ b/libglabels/Template.cpp @@ -25,7 +25,7 @@ #include "Db.h" -namespace libglabels +namespace glabels { Template::Template( const QString& brand, diff --git a/libglabels/Template.h b/libglabels/Template.h index f578782..09bfa35 100644 --- a/libglabels/Template.h +++ b/libglabels/Template.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Template_h -#define libglabels_Template_h +#ifndef glabels_Template_h +#define glabels_Template_h #include #include @@ -34,7 +34,7 @@ #include "MiniPreviewPixmap.h" -namespace libglabels +namespace glabels { const int TEMPLATE_PREVIEW_SIZE = 80; @@ -127,4 +127,4 @@ namespace libglabels #include "Template.inl" -#endif // libglabels_Template_h +#endif // glabels_Template_h diff --git a/libglabels/Template.inl b/libglabels/Template.inl index 1679f5e..56a0228 100644 --- a/libglabels/Template.inl +++ b/libglabels/Template.inl @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline const QString& Template::brand() const { return mBrand; } diff --git a/libglabels/Vendor.cpp b/libglabels/Vendor.cpp index 864feb0..e056264 100644 --- a/libglabels/Vendor.cpp +++ b/libglabels/Vendor.cpp @@ -1,6 +1,6 @@ /* Vendor.cpp * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -21,7 +21,7 @@ #include "Vendor.h" -namespace libglabels +namespace glabels { Vendor::Vendor( const QString &name, const QString &url ) : mName(name), mUrl(url) diff --git a/libglabels/Vendor.h b/libglabels/Vendor.h index afe8df8..a2140a9 100644 --- a/libglabels/Vendor.h +++ b/libglabels/Vendor.h @@ -1,6 +1,6 @@ /* Vendor.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,14 +18,14 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_Vendor_h -#define libglabels_Vendor_h +#ifndef glabels_Vendor_h +#define glabels_Vendor_h #include -namespace libglabels +namespace glabels { class Vendor @@ -47,4 +47,4 @@ namespace libglabels #include "Vendor.inl" -#endif // libglabels_Vendor_h +#endif // glabels_Vendor_h diff --git a/libglabels/Vendor.inl b/libglabels/Vendor.inl index 089f808..614c4f2 100644 --- a/libglabels/Vendor.inl +++ b/libglabels/Vendor.inl @@ -1,6 +1,6 @@ /* Vendor.inl * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -19,7 +19,7 @@ */ -namespace libglabels +namespace glabels { inline const QString& Vendor::name() const { return mName; } diff --git a/libglabels/XmlCategoryParser.cpp b/libglabels/XmlCategoryParser.cpp index f410089..7c9c419 100644 --- a/libglabels/XmlCategoryParser.cpp +++ b/libglabels/XmlCategoryParser.cpp @@ -1,6 +1,6 @@ /* XmlCategoryParser.cpp * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -30,7 +30,7 @@ #include "Db.h" -namespace libglabels +namespace glabels { bool XmlCategoryParser::readFile( const QString &fileName ) diff --git a/libglabels/XmlCategoryParser.h b/libglabels/XmlCategoryParser.h index 953e98c..843f10d 100644 --- a/libglabels/XmlCategoryParser.h +++ b/libglabels/XmlCategoryParser.h @@ -1,6 +1,6 @@ /* XmlCategoryParser.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,15 +18,15 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_XmlCategoryParser_h -#define libglabels_XmlCategoryParser_h +#ifndef glabels_XmlCategoryParser_h +#define glabels_XmlCategoryParser_h #include #include -namespace libglabels +namespace glabels { class XmlCategoryParser @@ -43,4 +43,4 @@ namespace libglabels } -#endif // libglabels_XmlCategoryParser_h +#endif // glabels_XmlCategoryParser_h diff --git a/libglabels/XmlPaperParser.cpp b/libglabels/XmlPaperParser.cpp index 1c4f27c..0d09189 100644 --- a/libglabels/XmlPaperParser.cpp +++ b/libglabels/XmlPaperParser.cpp @@ -1,6 +1,6 @@ /* XmlPaperParser.cpp * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -30,7 +30,7 @@ #include "Db.h" -namespace libglabels +namespace glabels { bool XmlPaperParser::readFile( const QString &fileName ) diff --git a/libglabels/XmlPaperParser.h b/libglabels/XmlPaperParser.h index 92c549e..1936472 100644 --- a/libglabels/XmlPaperParser.h +++ b/libglabels/XmlPaperParser.h @@ -1,6 +1,6 @@ /* XmlPaperParser.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,15 +18,15 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_XmlPaperParser_h -#define libglabels_XmlPaperParser_h +#ifndef glabels_XmlPaperParser_h +#define glabels_XmlPaperParser_h #include #include -namespace libglabels +namespace glabels { class XmlPaperParser @@ -43,4 +43,4 @@ namespace libglabels } -#endif // libglabels_XmlPaperParser_h +#endif // glabels_XmlPaperParser_h diff --git a/libglabels/XmlTemplateCreator.cpp b/libglabels/XmlTemplateCreator.cpp index ced9ff0..ee29470 100644 --- a/libglabels/XmlTemplateCreator.cpp +++ b/libglabels/XmlTemplateCreator.cpp @@ -30,7 +30,7 @@ #include "Db.h" -namespace libglabels +namespace glabels { bool XmlTemplateCreator::writeTemplates( const QList tmplates, const QString &fileName ) diff --git a/libglabels/XmlTemplateCreator.h b/libglabels/XmlTemplateCreator.h index 3607a82..2a1787b 100644 --- a/libglabels/XmlTemplateCreator.h +++ b/libglabels/XmlTemplateCreator.h @@ -1,6 +1,6 @@ /* XmlTemplateCreator.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_XmlTemplateCreator_h -#define libglabels_XmlTemplateCreator_h +#ifndef glabels_XmlTemplateCreator_h +#define glabels_XmlTemplateCreator_h #include @@ -34,7 +34,7 @@ #include "Markup.h" -namespace libglabels +namespace glabels { class XmlTemplateCreator @@ -65,4 +65,4 @@ namespace libglabels } -#endif // libglabels_XmlTemplateCreator_h +#endif // glabels_XmlTemplateCreator_h diff --git a/libglabels/XmlTemplateParser.cpp b/libglabels/XmlTemplateParser.cpp index 260a37d..1f7a69c 100644 --- a/libglabels/XmlTemplateParser.cpp +++ b/libglabels/XmlTemplateParser.cpp @@ -36,7 +36,7 @@ #include "Markup.h" -namespace libglabels +namespace glabels { bool XmlTemplateParser::readFile( const QString &fileName ) diff --git a/libglabels/XmlTemplateParser.h b/libglabels/XmlTemplateParser.h index 933696f..ad6e2b6 100644 --- a/libglabels/XmlTemplateParser.h +++ b/libglabels/XmlTemplateParser.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_XmlTemplateParser_h -#define libglabels_XmlTemplateParser_h +#ifndef glabels_XmlTemplateParser_h +#define glabels_XmlTemplateParser_h #include @@ -28,7 +28,7 @@ #include "Template.h" -namespace libglabels +namespace glabels { class XmlTemplateParser @@ -58,4 +58,4 @@ namespace libglabels } -#endif // libglabels_XmlTemplateParser_h +#endif // glabels_XmlTemplateParser_h diff --git a/libglabels/XmlUtil.cpp b/libglabels/XmlUtil.cpp index 917b18e..547bdcf 100644 --- a/libglabels/XmlUtil.cpp +++ b/libglabels/XmlUtil.cpp @@ -24,7 +24,7 @@ #include -namespace libglabels +namespace glabels { Distance::Units XmlUtil::mUnits; diff --git a/libglabels/XmlUtil.h b/libglabels/XmlUtil.h index 56e2863..334c54a 100644 --- a/libglabels/XmlUtil.h +++ b/libglabels/XmlUtil.h @@ -18,8 +18,8 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_XmlUtil_h -#define libglabels_XmlUtil_h +#ifndef glabels_XmlUtil_h +#define glabels_XmlUtil_h #include #include @@ -28,7 +28,7 @@ #include "Distance.h" -namespace libglabels +namespace glabels { class XmlUtil @@ -103,4 +103,4 @@ namespace libglabels } -#endif // libglabels_XmlUtil_h +#endif // glabels_XmlUtil_h diff --git a/libglabels/XmlVendorParser.cpp b/libglabels/XmlVendorParser.cpp index 65cf71c..d494996 100644 --- a/libglabels/XmlVendorParser.cpp +++ b/libglabels/XmlVendorParser.cpp @@ -1,6 +1,6 @@ /* XmlVendorParser.cpp * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -30,7 +30,7 @@ #include "Db.h" -namespace libglabels +namespace glabels { bool XmlVendorParser::readFile( const QString &fileName ) diff --git a/libglabels/XmlVendorParser.h b/libglabels/XmlVendorParser.h index baccd1d..e489e38 100644 --- a/libglabels/XmlVendorParser.h +++ b/libglabels/XmlVendorParser.h @@ -1,6 +1,6 @@ /* XmlVendorParser.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,15 +18,15 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_XmlVendorParser_h -#define libglabels_XmlVendorParser_h +#ifndef glabels_XmlVendorParser_h +#define glabels_XmlVendorParser_h #include #include -namespace libglabels +namespace glabels { class XmlVendorParser @@ -43,4 +43,4 @@ namespace libglabels } -#endif // libglabels_XmlVendorParser_h +#endif // glabels_XmlVendorParser_h diff --git a/libglabels/privateConstants.h b/libglabels/privateConstants.h index dc56bbb..2f8c368 100644 --- a/libglabels/privateConstants.h +++ b/libglabels/privateConstants.h @@ -1,6 +1,6 @@ /* privateConstants.h * - * Copyright (C) 2013 Jim Evins + * Copyright (C) 2013-2016 Jim Evins * * This file is part of gLabels-qt. * @@ -18,14 +18,14 @@ * along with gLabels-qt. If not, see . */ -#ifndef libglabels_privateConstants_h -#define libglabels_privateConstants_h +#ifndef glabels_privateConstants_h +#define glabels_privateConstants_h #include "Distance.h" -namespace libglabels +namespace glabels { namespace Constants @@ -37,4 +37,4 @@ namespace libglabels } -#endif // libglabels_privateConstants_h +#endif // glabels_privateConstants_h