Reconcile style accross all source files.

- All glabels code is in "glabels" top-level namespace.
- Other assorted cleanup.
This commit is contained in:
Jim Evins
2017-01-15 22:58:53 -05:00
parent 44aa31d074
commit b797d13e40
153 changed files with 17673 additions and 16841 deletions
+38 -1
View File
@@ -57,7 +57,38 @@ information.
- Never use parens in return statements when not necessary. - Never use parens in return statements when not necessary.
File Organization Naming
------
### Type Names
- Start with a capital letter.
- Each new word is capitalized.
- No underscores.
### Variable Names
- Start each variable name with a lowercase letter.
- Each subsequent word is capitalized.
- No underscores.
- Data members start with a lowercase "m" with the 2nd letter capitalized.
- Use "i" prefix for indexes and "n" prefix for total number of indexes.
### Function names
- Start each function name with a lowercase letter.
- Each subsequent word is capitalized.
- No underscores.
### Constant Names
- TBD (currently not uniform)
Code Organization
----------------- -----------------
Generally code is organized into modules. Usually a module defines a single Generally code is organized into modules. Usually a module defines a single
@@ -87,6 +118,7 @@ All header files should have an ifndef guard to prevent multiple inclusion.
#endif // ns_Module_h #endif // ns_Module_h
``` ```
### Include Directives ### Include Directives
Header files should be included in the following order. Header files should be included in the following order.
@@ -111,3 +143,8 @@ glabels header files.
Do not use forward declarations to any external entities. Use the appropriate Do not use forward declarations to any external entities. Use the appropriate
include directives instead. include directives instead.
### Namespaces
- Private definitions are placed in unnamed namespaces to limit scope to the current translation unit.
- All other glabels code is placed in the top-level "glabels" namespace.
+52 -47
View File
@@ -28,56 +28,61 @@
#include "Version.h" #include "Version.h"
/// namespace glabels
/// Constructor
///
AboutDialog::AboutDialog( QWidget *parent )
: QDialog(parent)
{ {
setupUi( this );
QString version = tr("Version") + " " + Version::STRING; ///
/// Constructor
QString description = tr("A program to create labels and business cards."); ///
AboutDialog::AboutDialog( QWidget *parent )
QString copyright = "Copyright &copy; 2017 Jim Evins <evins@snaught.com>"; : QDialog(parent)
{
QString licenseParagraph1 = setupUi( this );
tr( "gLabels is free software: you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version." );
QString licenseParagraph2 = QString version = tr("Version") + " " + Version::STRING;
tr( "gLabels is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
"GNU General Public License for more details." );
QString markup = QString description = tr("A program to create labels and business cards.");
"<p align='center'>" + version + "</p>" +
"<p align='center'>" + description + "</p>" + QString copyright = "Copyright &copy; 2017 Jim Evins <evins@snaught.com>";
"<p align='center'>" + copyright + "</p>" +
"<p align='left'>" + licenseParagraph1 + "</p>" + QString licenseParagraph1 =
"<p align='left'>" + licenseParagraph2 + "</p>"; tr( "gLabels is free software: you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version." );
QString licenseParagraph2 =
tr( "gLabels is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
"GNU General Public License for more details." );
QString markup =
"<p align='center'>" + version + "</p>" +
"<p align='center'>" + description + "</p>" +
"<p align='center'>" + copyright + "</p>" +
"<p align='left'>" + licenseParagraph1 + "</p>" +
"<p align='left'>" + licenseParagraph2 + "</p>";
aboutLabel->setText( markup );
}
///
/// "License" Button Clicked Slot
///
void AboutDialog::onLicenseButtonClicked()
{
QDesktopServices::openUrl( QUrl("http://www.gnu.org/licenses/gpl-3.0.txt") );
}
///
/// "Website" Button Clicked Slot
///
void AboutDialog::onWebsiteButtonClicked()
{
QDesktopServices::openUrl( QUrl(Version::WEBSITE) );
}
aboutLabel->setText( markup );
}
///
/// "License" Button Clicked Slot
///
void AboutDialog::onLicenseButtonClicked()
{
QDesktopServices::openUrl( QUrl("http://www.gnu.org/licenses/gpl-3.0.txt") );
}
///
/// "Website" Button Clicked Slot
///
void AboutDialog::onWebsiteButtonClicked()
{
QDesktopServices::openUrl( QUrl(Version::WEBSITE) );
} }
+22 -17
View File
@@ -25,29 +25,34 @@
#include "ui_AboutDialog.h" #include "ui_AboutDialog.h"
/// namespace glabels
/// About Dialog Widget
///
class AboutDialog : public QDialog, public Ui_AboutDialog
{ {
Q_OBJECT
///
/// About Dialog Widget
///
class AboutDialog : public QDialog, public Ui_AboutDialog
{
Q_OBJECT
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
AboutDialog( QWidget *parent = 0 ); AboutDialog( QWidget *parent = 0 );
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onLicenseButtonClicked(); void onLicenseButtonClicked();
void onWebsiteButtonClicked(); void onWebsiteButtonClicked();
}; };
}
#endif // AboutDialog_h #endif // AboutDialog_h
+125 -121
View File
@@ -21,159 +21,163 @@
#include "BarcodeBackends.h" #include "BarcodeBackends.h"
namespace namespace glabels
{ {
const std::string default_id = "code39";
} //
// Static data
//
BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap;
BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap;
BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap; BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap;
BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap; BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap;
BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap; QList<QString> BarcodeBackends::mBackendNameList;
BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap; QList<QString> BarcodeBackends::mNameList;
QList<QString> BarcodeBackends::mBackendNameList;
QList<QString> BarcodeBackends::mNameList;
BarcodeBackends::BarcodeBackends() BarcodeBackends::BarcodeBackends()
{ {
registerStyle( "postnet", "", tr("POSTNET (any)"), registerStyle( "postnet", "", tr("POSTNET (any)"),
false, false, true, false, "12345-6789-12", false, 11 ); false, false, true, false, "12345-6789-12", false, 11 );
registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"), registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"),
false, false, true, false, "12345", false, 5 ); false, false, true, false, "12345", false, 5 );
registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"), registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"),
false, false, true, false, "12345-6789", false, 9 ); false, false, true, false, "12345-6789", false, 9 );
registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"), registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"),
false, false, true, false, "12345-6789-12", false, 11 ); false, false, true, false, "12345-6789-12", false, 11 );
registerStyle( "cepnet", "", tr("CEPNET"), registerStyle( "cepnet", "", tr("CEPNET"),
false, false, true, false, "12345-678", false, 8 ); false, false, true, false, "12345-678", false, 8 );
registerStyle( "onecode", "", tr("USPS Intelligent Mail"), registerStyle( "onecode", "", tr("USPS Intelligent Mail"),
false, false, true, false, "12345678901234567890", false, 20 ); false, false, true, false, "12345678901234567890", false, 20 );
registerStyle( "code39", "", tr("Code 39"), registerStyle( "code39", "", tr("Code 39"),
true, true, true, true, "1234567890", true, 10 ); true, true, true, true, "1234567890", true, 10 );
registerStyle( "code39ext", "", tr("Code 39 Extended"), registerStyle( "code39ext", "", tr("Code 39 Extended"),
true, true, true, true, "1234567890", true, 10 ); true, true, true, true, "1234567890", true, 10 );
registerStyle( "upc-A", "", tr("UPC-A"), registerStyle( "upc-A", "", tr("UPC-A"),
true, false, true, false, "12345678901", false, 11 ); true, false, true, false, "12345678901", false, 11 );
registerStyle( "ean-13", "", tr("EAN-13"), registerStyle( "ean-13", "", tr("EAN-13"),
true, false, true, false, "123456789012", false, 12 ); true, false, true, false, "123456789012", false, 12 );
registerStyle( "datamatrix", "", tr("DataMatrix"), registerStyle( "datamatrix", "", tr("DataMatrix"),
false, false, true, false, "1234567890AB", false, 12 ); false, false, true, false, "1234567890AB", false, 12 );
registerStyle( "qrcode", "", tr("QRCode"), registerStyle( "qrcode", "", tr("QRCode"),
false, false, true, false, "1234567890AB", false, 12 ); false, false, true, false, "1234567890AB", false, 12 );
} }
void BarcodeBackends::init( void ) void BarcodeBackends::init( void )
{ {
static BarcodeBackends* singletonInstance = NULL; static BarcodeBackends* singletonInstance = NULL;
if ( singletonInstance == NULL ) if ( singletonInstance == NULL )
{ {
singletonInstance = new BarcodeBackends(); singletonInstance = new BarcodeBackends();
}
} }
}
QString BarcodeBackends::BackendIdToName( const QString& backendId ) QString BarcodeBackends::BackendIdToName( const QString& backendId )
{
BackendMap::iterator i = mBackendIdMap.find( backendId );
if ( i != mBackendIdMap.end() )
{ {
return i.value(); BackendMap::iterator i = mBackendIdMap.find( backendId );
} if ( i != mBackendIdMap.end() )
{
return i.value();
}
return ""; return "";
}
QString BarcodeBackends::BackendNameToId( const QString& backendName )
{
BackendMap::iterator i = mBackendNameMap.find( backendName );
if ( i != mBackendNameMap.end() )
{
return i.value();
} }
return "";
}
const QList<QString>& BarcodeBackends::getBackendNameList() QString BarcodeBackends::BackendNameToId( const QString& backendName )
{
return mBackendNameList;
}
const QList<QString>& BarcodeBackends::getNameList()
{
return mNameList;
}
const BarcodeStyle* BarcodeBackends::lookupStyleFromId( const QString& id )
{
StyleMap::iterator i = mStyleIdMap.find( id );
if ( i != mStyleIdMap.end() )
{ {
return i.value(); BackendMap::iterator i = mBackendNameMap.find( backendName );
} if ( i != mBackendNameMap.end() )
{
return i.value();
}
return 0; return "";
} }
const BarcodeStyle* BarcodeBackends::lookupStyleFromName( const QString& name ) const QList<QString>& BarcodeBackends::getBackendNameList()
{
StyleMap::iterator i = mStyleNameMap.find( name );
if ( i != mStyleNameMap.end() )
{ {
return i.value(); return mBackendNameList;
} }
const QList<QString>& 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; return 0;
} }
void BarcodeBackends::registerBackend( QString& id, QString& name) const BarcodeStyle* BarcodeBackends::lookupStyleFromName( const QString& name )
{ {
mBackendNameList.append( name ); StyleMap::iterator i = mStyleNameMap.find( name );
mBackendIdMap.insert( id, name ); if ( i != mStyleNameMap.end() )
mBackendNameMap.insert( name, id ); {
} return i.value();
}
void BarcodeBackends::registerStyle( const char* id, return 0;
const char* backendId, }
const QString& name,
bool canText,
bool textOptional, void BarcodeBackends::registerBackend( QString& id, QString& name)
bool canChecksum, {
bool checksumOptional, mBackendNameList.append( name );
const char* defaultDigits, mBackendIdMap.insert( id, name );
bool canFreeForm, mBackendNameMap.insert( name, id );
int preferedN ) }
{
BarcodeStyle* style = new BarcodeStyle( QString(id), QString(backendId), name,
canText, textOptional, void BarcodeBackends::registerStyle( const char* id,
canChecksum, checksumOptional, const char* backendId,
QString(defaultDigits), canFreeForm, preferedN ); const QString& name,
bool canText,
QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique bool textOptional,
bool canChecksum,
mNameList.append( name ); bool checksumOptional,
mStyleIdMap.insert( id, style ); const char* defaultDigits,
mStyleNameMap.insert( fqName, style ); 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 );
}
} }
+53 -48
View File
@@ -30,68 +30,73 @@
#include "BarcodeStyle.h" #include "BarcodeStyle.h"
/// namespace glabels
/// Barcode Backends Database
///
class BarcodeBackends : public QObject
{ {
///
/// Barcode Backends Database
///
class BarcodeBackends : public QObject
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
BarcodeBackends(); BarcodeBackends();
public: public:
static void init( void ); static void init( void );
///////////////////////////////// /////////////////////////////////
// Public Methods // Public Methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString BackendIdToName( const QString& backendId ); static QString BackendIdToName( const QString& backendId );
static QString BackendNameToId( const QString& backendName ); static QString BackendNameToId( const QString& backendName );
static const QList<QString>& getBackendNameList(); static const QList<QString>& getBackendNameList();
static const QList<QString>& getNameList(); static const QList<QString>& getNameList();
static const BarcodeStyle* lookupStyleFromId( const QString& id ); static const BarcodeStyle* lookupStyleFromId( const QString& id );
static const BarcodeStyle* lookupStyleFromName( const QString& name ); static const BarcodeStyle* lookupStyleFromName( const QString& name );
///////////////////////////////// /////////////////////////////////
// Private Methods // Private Methods
///////////////////////////////// /////////////////////////////////
private: private:
static void registerBackend( QString &id, QString &name); static void registerBackend( QString &id, QString &name);
static void registerStyle( const char* id, static void registerStyle( const char* id,
const char* backendId, const char* backendId,
const QString& name, const QString& name,
bool canText, bool canText,
bool textOptional, bool textOptional,
bool canChecksum, bool canChecksum,
bool checksumOptional, bool checksumOptional,
const char* defaultDigits, const char* defaultDigits,
bool canFreeForm, bool canFreeForm,
int preferedN ); int preferedN );
///////////////////////////////// /////////////////////////////////
// Private Members // Private Members
///////////////////////////////// /////////////////////////////////
typedef QMap<QString,QString> BackendMap; typedef QMap<QString,QString> BackendMap;
static BackendMap mBackendIdMap; static BackendMap mBackendIdMap;
static BackendMap mBackendNameMap; static BackendMap mBackendNameMap;
typedef QMap<QString,BarcodeStyle*> StyleMap; typedef QMap<QString,BarcodeStyle*> StyleMap;
static StyleMap mStyleIdMap; static StyleMap mStyleIdMap;
static StyleMap mStyleNameMap; static StyleMap mStyleNameMap;
static QList<QString> mBackendNameList; static QList<QString> mBackendNameList;
static QList<QString> mNameList; static QList<QString> mNameList;
}; };
}
#endif // BarcodeBackends_h #endif // BarcodeBackends_h
+34 -29
View File
@@ -25,38 +25,43 @@
#include "BarcodeMenuItem.h" #include "BarcodeMenuItem.h"
/// namespace glabels
/// Constructor
///
BarcodeMenu::BarcodeMenu()
{ {
foreach ( QString name, BarcodeBackends::getNameList() )
///
/// Constructor
///
BarcodeMenu::BarcodeMenu()
{ {
const BarcodeStyle* bcStyle = BarcodeBackends::lookupStyleFromName( name ); foreach ( QString name, BarcodeBackends::getNameList() )
{
const BarcodeStyle* bcStyle = BarcodeBackends::lookupStyleFromName( name );
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle ); BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) ); connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) );
addAction( bcMenuItem ); addAction( bcMenuItem );
}
} }
}
///
/// /// bcStyle getter
/// bcStyle getter ///
/// const BarcodeStyle* BarcodeMenu::bcStyle() const
const BarcodeStyle* BarcodeMenu::bcStyle() const {
{ return mBcStyle;
return mBcStyle; }
}
///
/// /// onMenuItemActivated slot
/// onMenuItemActivated slot ///
/// void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle )
void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle ) {
{ mBcStyle = bcStyle;
mBcStyle = bcStyle;
emit styleChanged();
emit styleChanged(); }
} }
+36 -31
View File
@@ -27,48 +27,53 @@
#include "BarcodeStyle.h" #include "BarcodeStyle.h"
/// namespace glabels
/// Barcode Menu
///
class BarcodeMenu : public QMenu
{ {
Q_OBJECT
///
/// Barcode Menu
///
class BarcodeMenu : public QMenu
{
Q_OBJECT
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
BarcodeMenu(); BarcodeMenu();
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void styleChanged(); void styleChanged();
///////////////////////////////// /////////////////////////////////
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
const BarcodeStyle* bcStyle() const; const BarcodeStyle* bcStyle() const;
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onMenuItemActivated( BarcodeStyle *bcStyle ); void onMenuItemActivated( BarcodeStyle *bcStyle );
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
BarcodeStyle* mBcStyle; BarcodeStyle* mBcStyle;
}; };
}
#endif // BarcodeMenu_h #endif // BarcodeMenu_h
+36 -31
View File
@@ -25,38 +25,43 @@
#include "BarcodeMenuItem.h" #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 mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style
setText( mBcStyle->name() ); 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();
}
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();
} }
+37 -32
View File
@@ -28,49 +28,54 @@
#include "BarcodeStyle.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 // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
BarcodeMenuButton( QWidget* parent = 0 ); BarcodeMenuButton( QWidget* parent = 0 );
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void styleChanged(); void styleChanged();
///////////////////////////////// /////////////////////////////////
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
const BarcodeStyle* bcStyle() const; const BarcodeStyle* bcStyle() const;
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onMenuStyleChanged(); void onMenuStyleChanged();
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
BarcodeMenu* mMenu; BarcodeMenu* mMenu;
const BarcodeStyle* mBcStyle; const BarcodeStyle* mBcStyle;
}; };
}
#endif // BarcodeMenuButton_h #endif // BarcodeMenuButton_h
+30 -25
View File
@@ -21,31 +21,36 @@
#include "BarcodeMenuItem.h" #include "BarcodeMenuItem.h"
/// namespace glabels
/// Constructor From Data
///
BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent )
: QAction(parent), mBcStyle(bcStyle)
{ {
setText( bcStyle->name() );
connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) ); ///
} /// Constructor From Data
///
BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent )
/// : QAction(parent), mBcStyle(bcStyle)
/// bcStyle Property Getter {
/// setText( bcStyle->name() );
const BarcodeStyle* BarcodeMenuItem::bcStyle() const
{ connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) );
return mBcStyle; }
}
///
/// /// bcStyle Property Getter
/// onTriggered slot ///
/// const BarcodeStyle* BarcodeMenuItem::bcStyle() const
void BarcodeMenuItem::onTriggered() {
{ return mBcStyle;
emit activated( mBcStyle ); }
///
/// onTriggered slot
///
void BarcodeMenuItem::onTriggered()
{
emit activated( mBcStyle );
}
} }
+36 -31
View File
@@ -27,48 +27,53 @@
#include "BarcodeStyle.h" #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 // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = 0 ); BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = 0 );
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void activated( const BarcodeStyle* bcStyle ); void activated( const BarcodeStyle* bcStyle );
///////////////////////////////// /////////////////////////////////
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
const BarcodeStyle* bcStyle() const; const BarcodeStyle* bcStyle() const;
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onTriggered(); void onTriggered();
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
const BarcodeStyle* mBcStyle; const BarcodeStyle* mBcStyle;
}; };
}
#endif // BarcodeMenuItem_h #endif // BarcodeMenuItem_h
+137 -130
View File
@@ -21,37 +21,41 @@
#include "BarcodeStyle.h" #include "BarcodeStyle.h"
/// 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 )
{
// empty
}
/// ///
/// Constructor From Data /// Constructor From Data
/// ///
BarcodeStyle::BarcodeStyle ( const QString& id, BarcodeStyle::BarcodeStyle ( const QString& id,
const QString& backendId, const QString& backendId,
const QString& name, const QString& name,
bool canText, bool canText,
bool textOptional, bool textOptional,
bool canChecksum, bool canChecksum,
bool checksumOptional, bool checksumOptional,
const QString& defaultDigits, const QString& defaultDigits,
bool canFreeform, bool canFreeform,
int preferedN ) int preferedN )
: mId( id ), : mId( id ),
mBackendId( backendId ), mBackendId( backendId ),
mName( name ), mName( name ),
@@ -62,111 +66,114 @@ BarcodeStyle::BarcodeStyle ( const QString& id,
mDefaultDigits( defaultDigits ), mDefaultDigits( defaultDigits ),
mCanFreeform( canFreeform ), mCanFreeform( canFreeform ),
mPreferedN( preferedN ) 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
{
if ( mCanFreeform )
{ {
return QString( qMax( n, 1 ), QChar('0') ); // empty
} }
else
///
/// 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; 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
{
if ( mCanFreeform )
{
return QString( qMax( n, 1 ), QChar('0') );
}
else
{
return mDefaultDigits;
}
}
} }
+57 -52
View File
@@ -24,77 +24,82 @@
#include <QString> #include <QString>
/// namespace glabels
/// Barcode Style Type
///
struct BarcodeStyle
{ {
///
/// Barcode Style Type
///
struct BarcodeStyle
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
BarcodeStyle (); BarcodeStyle ();
BarcodeStyle ( const QString& id, BarcodeStyle ( const QString& id,
const QString& backendId, const QString& backendId,
const QString& name, const QString& name,
bool canText, bool canText,
bool textOptional, bool textOptional,
bool canChecksum, bool canChecksum,
bool checksumOptional, bool checksumOptional,
const QString& defaultDigits, const QString& defaultDigits,
bool canFreeform, bool canFreeform,
int preferedN ); int preferedN );
///////////////////////////////// /////////////////////////////////
// Properties // Properties
///////////////////////////////// /////////////////////////////////
const QString& id() const; 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 // Methods
///////////////////////////////// /////////////////////////////////
public: public:
QString exampleDigits( int n ) const; QString exampleDigits( int n ) const;
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
QString mId; QString mId;
QString mBackendId; QString mBackendId;
QString mName; QString mName;
bool mCanText; bool mCanText;
bool mTextOptional; bool mTextOptional;
bool mCanChecksum; bool mCanChecksum;
bool mChecksumOptional; bool mChecksumOptional;
QString mDefaultDigits; QString mDefaultDigits;
bool mCanFreeform; bool mCanFreeform;
int mPreferedN; int mPreferedN;
}; };
}
#endif // BarcodeStyle_h #endif // BarcodeStyle_h
+1
View File
@@ -27,6 +27,7 @@ namespace glabels
Category::Category( const QString &id, const QString &name ) Category::Category( const QString &id, const QString &name )
: mId(id), mName(name) : mId(id), mName(name)
{ {
// empty
} }
+141 -130
View File
@@ -28,148 +28,159 @@
#include "ColorSwatch.h" #include "ColorSwatch.h"
namespace namespace glabels
{ {
const int SWATCH_W = 64;
const int SWATCH_H = 24; //
} // Private
//
namespace
ColorButton::ColorButton( QWidget* parent )
: QPushButton( parent )
{
}
void ColorButton::init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color )
{
mDefaultColor = defaultColor;
mColorNode = ColorNode( color );
setMinimumSize( QSize( 85, 34 ) );
setIconSize( QSize(SWATCH_W, SWATCH_H) );
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.isField() )
{ {
setIcon( QIcon() ); const int SWATCH_W = 64;
setText( QString("${%1}").arg( colorNode.key() ) ); const int SWATCH_H = 24;
} }
else
ColorButton::ColorButton( QWidget* parent )
: QPushButton( parent )
{ {
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) ); // empty
}
void ColorButton::init( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color )
{
mDefaultColor = defaultColor;
mColorNode = ColorNode( color );
setMinimumSize( QSize( 85, 34 ) );
setIconSize( QSize(SWATCH_W, SWATCH_H) );
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.isField() )
{
setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) );
}
else
{
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
setText( "" );
}
mDialog->setColorNode( colorNode );
}
void ColorButton::setColor( QColor color )
{
mIsDefault = false;
mColorNode.setField( false );
mColorNode.setColor( color );
mColorNode.setKey( "" );
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) );
setText( "" ); setText( "" );
} }
mDialog->setColorNode( colorNode );
}
void ColorButton::setToDefault()
void ColorButton::setColor( QColor color )
{
mIsDefault = false;
mColorNode.setField( false );
mColorNode.setColor( color );
mColorNode.setKey( "" );
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) );
setText( "" );
}
void ColorButton::setToDefault()
{
mIsDefault = true;
mColorNode.setField( 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<QString> keyList )
{
mDialog->setKeys( keyList );
}
void ColorButton::clearKeys()
{
mDialog->clearKeys();
}
void ColorButton::onButtonToggled( bool checked )
{
if ( checked )
{ {
/// mIsDefault = true;
/// @TODO: improve positioning of dialog -- near edges of screen.
///
QPoint dialogPos( 0, height() );
mDialog->move( mapToGlobal(dialogPos) );
mDialog->show(); mColorNode.setField( false );
} mColorNode.setColor( mDefaultColor );
} mColorNode.setKey( "" );
setIcon( QIcon(ColorSwatch( SWATCH_W, SWATCH_H, mDefaultColor ) ) );
void ColorButton::onPaletteDialogAccepted()
{
setChecked( false );
}
void ColorButton::onPaletteDialogRejected()
{
setChecked( false );
}
void ColorButton::onPaletteDialogChanged( ColorNode colorNode, bool isDefault )
{
mColorNode = colorNode;
mIsDefault = isDefault;
if ( colorNode.isField() )
{
setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) );
}
else
{
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
setText( "" ); setText( "" );
} }
ColorNode ColorButton::colorNode()
{
return mColorNode;
}
void ColorButton::setKeys( const QList<QString> 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;
if ( colorNode.isField() )
{
setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) );
}
else
{
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
setText( "" );
}
emit colorChanged(); emit colorChanged();
}
} }
+52 -47
View File
@@ -28,67 +28,72 @@
#include "ColorPaletteDialog.h" #include "ColorPaletteDialog.h"
/// namespace glabels
/// Color Button
///
class ColorButton : public QPushButton
{ {
Q_OBJECT
///
/// Color Button
///
class ColorButton : public QPushButton
{
Q_OBJECT
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
ColorButton( QWidget* parent = 0 ); ColorButton( QWidget* parent = 0 );
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void colorChanged(); void colorChanged();
///////////////////////////////// /////////////////////////////////
// Public Methods // Public Methods
///////////////////////////////// /////////////////////////////////
public: public:
void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color ); void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color );
void setColorNode( ColorNode colorNode ); void setColorNode( ColorNode colorNode );
void setColor( QColor color ); void setColor( QColor color );
void setToDefault(); void setToDefault();
ColorNode colorNode(); ColorNode colorNode();
void setKeys( const QList<QString> keyList ); void setKeys( const QList<QString> keyList );
void clearKeys(); void clearKeys();
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onButtonToggled( bool checked ); void onButtonToggled( bool checked );
void onPaletteDialogAccepted(); void onPaletteDialogAccepted();
void onPaletteDialogRejected(); void onPaletteDialogRejected();
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault ); void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
///////////////////////////////// /////////////////////////////////
// Private Methods // Private Methods
///////////////////////////////// /////////////////////////////////
private: private:
///////////////////////////////// /////////////////////////////////
// Private Members // Private Members
///////////////////////////////// /////////////////////////////////
private: private:
QColor mDefaultColor; QColor mDefaultColor;
bool mIsDefault; bool mIsDefault;
ColorNode mColorNode; ColorNode mColorNode;
ColorPaletteDialog* mDialog; ColorPaletteDialog* mDialog;
}; };
}
#endif // ColorButton_h #endif // ColorButton_h
+72 -66
View File
@@ -25,89 +25,95 @@
#include <QtDebug> #include <QtDebug>
ColorHistory::ColorHistory() namespace glabels
{ {
}
ColorHistory::ColorHistory()
ColorHistory* ColorHistory::instance()
{
static ColorHistory* singletonInstance = 0;
if ( singletonInstance == 0 )
{ {
singletonInstance = new ColorHistory(); // empty
} }
return singletonInstance;
}
ColorHistory* ColorHistory::instance()
void ColorHistory::addColor( const QColor &color )
{
QList<QColor> colorList = readColorList();
// Remove any occurances of this color already in list
colorList.removeAll( color );
// Now add to list
colorList.append( color );
// Remove oldest colors, if size exceeds current max
while ( colorList.size() > MAX_COLORS )
{ {
colorList.removeFirst(); static ColorHistory* singletonInstance = 0;
if ( singletonInstance == 0 )
{
singletonInstance = new ColorHistory();
}
return singletonInstance;
} }
writeColorList( colorList );
void ColorHistory::addColor( const QColor &color )
{
QList<QColor> colorList = readColorList();
// Remove any occurances of this color already in list
colorList.removeAll( color );
// Now add to list
colorList.append( color );
// Remove oldest colors, if size exceeds current max
while ( colorList.size() > MAX_COLORS )
{
colorList.removeFirst();
}
writeColorList( colorList );
emit changed(); emit changed();
}
QList<QColor> ColorHistory::getColors()
{
return readColorList();
}
QList<QColor> ColorHistory::readColorList()
{
QStringList defaultList;
QSettings settings;
settings.beginGroup( "ColorHistory" );
QStringList colorNameList = settings.value( "colors", defaultList ).toStringList();
settings.endGroup();
QList<QColor> colorList;
foreach ( QString colorName, colorNameList )
{
colorList << QColor( colorName );
} }
// Remove oldest colors, if size exceeds current max
while ( colorList.size() > MAX_COLORS ) QList<QColor> ColorHistory::getColors()
{ {
colorList.removeFirst(); return readColorList();
} }
return colorList;
}
QList<QColor> ColorHistory::readColorList()
void ColorHistory::writeColorList( const QList<QColor>& colorList )
{
// Build name list
QStringList colorNameList;
foreach ( QColor color, colorList )
{ {
colorNameList << color.name(); QStringList defaultList;
QSettings settings;
settings.beginGroup( "ColorHistory" );
QStringList colorNameList = settings.value( "colors", defaultList ).toStringList();
settings.endGroup();
QList<QColor> colorList;
foreach ( QString colorName, colorNameList )
{
colorList << QColor( colorName );
}
// Remove oldest colors, if size exceeds current max
while ( colorList.size() > MAX_COLORS )
{
colorList.removeFirst();
}
return colorList;
}
void ColorHistory::writeColorList( const QList<QColor>& colorList )
{
// Build name list
QStringList colorNameList;
foreach ( QColor color, colorList )
{
colorNameList << color.name();
}
// Save
QSettings settings;
settings.beginGroup( "ColorHistory" );
settings.setValue( "colors", colorNameList );
settings.endGroup();
} }
// Save
QSettings settings;
settings.beginGroup( "ColorHistory" );
settings.setValue( "colors", colorNameList );
settings.endGroup();
} }
+41 -36
View File
@@ -26,55 +26,60 @@
#include <QObject> #include <QObject>
/// namespace glabels
/// Color History
///
class ColorHistory : public QObject
{ {
Q_OBJECT
public: ///
static const int MAX_COLORS = 9; /// Color History
///
class ColorHistory : public QObject
{
Q_OBJECT
///////////////////////////////// public:
// Life Cycle static const int MAX_COLORS = 9;
/////////////////////////////////
private:
ColorHistory();
public: /////////////////////////////////
static ColorHistory* instance(); // Life Cycle
/////////////////////////////////
private:
ColorHistory();
public:
static ColorHistory* instance();
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void changed(); void changed();
///////////////////////////////// /////////////////////////////////
// Public Methods // Public Methods
///////////////////////////////// /////////////////////////////////
public: public:
void addColor( const QColor &color ); void addColor( const QColor &color );
QList<QColor> getColors(); QList<QColor> getColors();
///////////////////////////////// /////////////////////////////////
// Private Methods // Private Methods
///////////////////////////////// /////////////////////////////////
private: private:
QList<QColor> readColorList(); QList<QColor> readColorList();
void writeColorList( const QList<QColor>& colorList ); void writeColorList( const QList<QColor>& colorList );
///////////////////////////////// /////////////////////////////////
// Private Members // Private Members
///////////////////////////////// /////////////////////////////////
private: private:
}; };
}
#endif // ColorHistory_h #endif // ColorHistory_h
+169 -160
View File
@@ -24,171 +24,180 @@
#include "Merge/Record.h" #include "Merge/Record.h"
/// namespace glabels
/// Default Constructor
///
ColorNode::ColorNode()
: mIsField(false), mColor(QColor::fromRgba(0x00000000)), mKey("")
{ {
}
///
/// /// Default Constructor
/// Constructor From Data ///
/// ColorNode::ColorNode()
ColorNode::ColorNode( bool isField, const QColor& color, const QString& key ) : mIsField(false), mColor(QColor::fromRgba(0x00000000)), mKey("")
: mIsField(isField), mColor(color), mKey(key)
{
}
///
/// Constructor From Data
///
ColorNode::ColorNode( bool isField, uint32_t rgba, const QString& key )
: mIsField(isField), mKey(key)
{
mColor = QColor( (rgba >> 24) & 0xFF,
(rgba >> 16) & 0xFF,
(rgba >> 8) & 0xFF,
(rgba ) & 0xFF );
}
///
/// Constructor From Color
///
ColorNode::ColorNode( const QColor& color )
: mIsField(false), mColor(color), mKey("")
{
}
///
/// Constructor From Key
///
ColorNode::ColorNode( const QString& key )
: mIsField(true), mColor(QColor::fromRgba(0x00000000)), mKey(key)
{
}
///
/// == Operator
///
bool ColorNode::operator==( const ColorNode& cn )
{
return (mIsField == cn.mIsField) &&
(mColor == cn.mColor) &&
(mKey == cn.mKey);
}
///
/// != Operator
///
bool ColorNode::operator!=( const ColorNode& cn )
{
return (mIsField != cn.mIsField) ||
(mColor != cn.mColor) ||
(mKey != cn.mKey);
}
///
/// Field Flag Property Getter
///
bool ColorNode::isField() const
{
return mIsField;
}
///
/// Field Flag Property Setter
///
void ColorNode::setField( bool isField )
{
mIsField = isField;
}
///
/// Color Property Getter
///
const QColor& ColorNode::color() const
{
return mColor;
}
///
/// Color Property Setter
///
void ColorNode::setColor( const QColor& color )
{
mColor = color;
}
///
/// Key Property Getter
///
const QString& ColorNode::key() const
{
return mKey;
}
///
/// Key Property Setter
///
void ColorNode::setKey( const QString& key )
{
mKey = key;
}
///
/// Get color encoded as an RGBA 32-bit number
///
uint32_t ColorNode::rgba() const
{
uint32_t c =
mColor.red() << 24 |
mColor.green() << 16 |
mColor.blue() << 8 |
mColor.alpha();
return c;
}
///
/// Get color, expand if necessary
///
QColor ColorNode::color( merge::Record* record ) const
{
if ( mIsField )
{ {
if ( record == 0 ) // empty
{
return mColor;
}
else
{
if ( record->contains( mKey ) )
{
return QColor( (*record)[ mKey ] );
}
else
{
return mColor;
}
}
} }
else
///
/// Constructor From Data
///
ColorNode::ColorNode( bool isField, const QColor& color, const QString& key )
: mIsField(isField), mColor(color), mKey(key)
{
// empty
}
///
/// Constructor From Data
///
ColorNode::ColorNode( bool isField, uint32_t rgba, const QString& key )
: mIsField(isField), mKey(key)
{
mColor = QColor( (rgba >> 24) & 0xFF,
(rgba >> 16) & 0xFF,
(rgba >> 8) & 0xFF,
(rgba ) & 0xFF );
}
///
/// Constructor From Color
///
ColorNode::ColorNode( const QColor& color )
: mIsField(false), mColor(color), mKey("")
{
// empty
}
///
/// Constructor From Key
///
ColorNode::ColorNode( const QString& key )
: mIsField(true), mColor(QColor::fromRgba(0x00000000)), mKey(key)
{
// empty
}
///
/// == Operator
///
bool ColorNode::operator==( const ColorNode& cn )
{
return (mIsField == cn.mIsField) &&
(mColor == cn.mColor) &&
(mKey == cn.mKey);
}
///
/// != Operator
///
bool ColorNode::operator!=( const ColorNode& cn )
{
return (mIsField != cn.mIsField) ||
(mColor != cn.mColor) ||
(mKey != cn.mKey);
}
///
/// Field Flag Property Getter
///
bool ColorNode::isField() const
{
return mIsField;
}
///
/// Field Flag Property Setter
///
void ColorNode::setField( bool isField )
{
mIsField = isField;
}
///
/// Color Property Getter
///
const QColor& ColorNode::color() const
{ {
return mColor; return mColor;
} }
///
/// Color Property Setter
///
void ColorNode::setColor( const QColor& color )
{
mColor = color;
}
///
/// Key Property Getter
///
const QString& ColorNode::key() const
{
return mKey;
}
///
/// Key Property Setter
///
void ColorNode::setKey( const QString& key )
{
mKey = key;
}
///
/// Get color encoded as an RGBA 32-bit number
///
uint32_t ColorNode::rgba() const
{
uint32_t c =
mColor.red() << 24 |
mColor.green() << 16 |
mColor.blue() << 8 |
mColor.alpha();
return c;
}
///
/// Get color, expand if necessary
///
QColor ColorNode::color( merge::Record* record ) const
{
if ( mIsField )
{
if ( record == 0 )
{
return mColor;
}
else
{
if ( record->contains( mKey ) )
{
return QColor( (*record)[ mKey ] );
}
else
{
return mColor;
}
}
}
else
{
return mColor;
}
}
} }
+57 -52
View File
@@ -30,78 +30,83 @@
#include "Merge/Record.h" #include "Merge/Record.h"
/// namespace glabels
/// Color Node Type
///
struct ColorNode
{ {
///////////////////////////////// ///
// Life Cycle /// Color Node Type
///////////////////////////////// ///
public: struct ColorNode
ColorNode(); {
ColorNode( bool isField, const QColor& color, const QString& key ); /////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorNode();
ColorNode( bool isField, uint32_t rgba, const QString& key ); ColorNode( bool isField, const QColor& color, const QString& key );
ColorNode( const QColor& color ); ColorNode( bool isField, uint32_t rgba, const QString& key );
ColorNode( const QString& key ); ColorNode( const QColor& color );
ColorNode( const QString& key );
///////////////////////////////// /////////////////////////////////
// Operators // Operators
///////////////////////////////// /////////////////////////////////
public: public:
bool operator==( const ColorNode& cn ); bool operator==( const ColorNode& cn );
bool operator!=( const ColorNode& cn ); bool operator!=( const ColorNode& cn );
///////////////////////////////// /////////////////////////////////
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
// //
// Field Flag Property // Field Flag Property
// //
bool isField() const; bool isField() const;
void setField( bool isField ); void setField( bool isField );
// //
// Color Property // Color Property
// //
const QColor& color() const; const QColor& color() const;
void setColor( const QColor& color ); void setColor( const QColor& color );
// //
// Key Property // Key Property
// //
const QString& key() const; const QString& key() const;
void setKey( const QString& key ); void setKey( const QString& key );
///////////////////////////////// /////////////////////////////////
// Misc. Methods // Misc. Methods
///////////////////////////////// /////////////////////////////////
public: public:
uint32_t rgba() const; uint32_t rgba() const;
QColor color( merge::Record* record ) const; QColor color( merge::Record* record ) const;
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
bool mIsField; bool mIsField;
QColor mColor; QColor mColor;
QString mKey; QString mKey;
}; };
}
#endif // ColorNode_h #endif // ColorNode_h
+81 -76
View File
@@ -25,96 +25,101 @@
#include <QPainter> #include <QPainter>
// namespace glabels
// Private Configuration Data
//
namespace
{ {
const int border = 4;
const int hBox = 25;
const int outlineWidthPixels = 1;
}
///
/// 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 // Private
// //
if ( isEnabled() && mHover ) namespace
{ {
QLinearGradient gradient( 0, 0, 0, height() ); const int border = 4;
gradient.setColorAt( 0, palette().color( QPalette::Highlight ).lighter() ); const int hBox = 25;
gradient.setColorAt( 1, palette().color( QPalette::Highlight ) ); const int outlineWidthPixels = 1;
painter.setBrush( QBrush( gradient ) ); }
///
/// 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 ( isEnabled() && 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 ) ); QPen pen( palette().color( QPalette::Text ) );
pen.setWidth( outlineWidthPixels ); pen.setWidth( outlineWidthPixels );
painter.setPen( pen ); painter.setPen( pen );
painter.drawRect( 0, 0, width()-1, height()-1 ); painter.drawRect( 0, 0, width()-1, height()-1 );
}
//
// Draw text
//
painter.setBrush( QBrush( Qt::NoBrush ) );
if ( isEnabled() && 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 );
} }
//
// Draw text
//
painter.setBrush( QBrush( Qt::NoBrush ) );
if ( isEnabled() && mHover ) ///
/// Enter Event
///
void ColorPaletteButtonItem::enterEvent( QEvent* event )
{ {
painter.setPen( QPen( palette().color( QPalette::HighlightedText ) ) ); mHover = true;
update();
} }
else
///
/// Leave Event
///
void ColorPaletteButtonItem::leaveEvent( QEvent* event )
{ {
painter.setPen( QPen( palette().color( QPalette::Text ) ) ); mHover = false;
update();
} }
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 /// Mouse Press Event
/// ///
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event ) void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
{ {
emit activated(); emit activated();
}
} }
+35 -30
View File
@@ -26,45 +26,50 @@
#include <QWidget> #include <QWidget>
/// namespace glabels
/// Color Palette Item
///
class ColorPaletteButtonItem : public QWidget
{ {
Q_OBJECT
///////////////////////////////// ///
// Life Cycle /// Color Palette Item
///////////////////////////////// ///
public: class ColorPaletteButtonItem : public QWidget
ColorPaletteButtonItem( const QString& text, QWidget* parent = 0 ); {
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteButtonItem( const QString& text, QWidget* parent = 0 );
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void activated(); void activated();
///////////////////////////////// /////////////////////////////////
// Event handlers // Event handlers
///////////////////////////////// /////////////////////////////////
protected: protected:
void paintEvent( QPaintEvent* event ); void paintEvent( QPaintEvent* event );
void enterEvent( QEvent* event ); void enterEvent( QEvent* event );
void leaveEvent( QEvent* event ); void leaveEvent( QEvent* event );
void mousePressEvent( QMouseEvent* event ); void mousePressEvent( QMouseEvent* event );
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
QString mText; QString mText;
bool mHover; bool mHover;
}; };
}
#endif // ColorPaletteButtonItem_h #endif // ColorPaletteButtonItem_h
+254 -245
View File
@@ -30,289 +30,298 @@
#include <QtDebug> #include <QtDebug>
ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = { namespace glabels
{ "#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()) );
mDefaultColor = defaultColor; //
mColorNode = ColorNode( color ); // Static data
//
ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = {
setStyleSheet( ".glabels--ColorPaletteDialog {background: white; border: 1px solid black}" ); { "#ef2929", tr("Light Scarlet Red", "Color name") },
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint ); { "#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") },
QVBoxLayout* vLayout = new QVBoxLayout(); { "#cc0000", tr("Scarlet Red", "Color name") },
vLayout->setContentsMargins( 0, 0, 0, 0 ); { "#f57900", tr("Orange", "Color name") },
vLayout->setSpacing( 0 ); { "#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") },
ColorPaletteButtonItem* defaultButton = new ColorPaletteButtonItem( defaultLabel ); { "#a40000", tr("Dark Scarlet Red", "Color name") },
connect( defaultButton, SIGNAL(activated()), this, SLOT(onDefaultItemActivated()) ); { "#ce5c00", tr("Dark Orange", "Color name") },
vLayout->addWidget( defaultButton ); { "#c4a000", tr("Dark Butter", "Color name") },
{ "#4e9a06", tr("Dark Chameleon", "Color name") },
QFrame* hline1 = new QFrame; { "#204a87", tr("Dark Sky Blue", "Color name") },
hline1->setFrameStyle( QFrame::HLine | QFrame::Plain ); { "#5c3566", tr("Dark Plum", "Color name") },
hline1->setLineWidth( 1 ); { "#8f5902", tr("Dark Chocolate", "Color name") },
vLayout->addWidget( hline1 ); { "#2e3436", tr("Dark Aluminum 1", "Color name") },
{ "#babdb6", tr("Dark Aluminum 2", "Color name") },
QGridLayout* mainPaletteLayout = new QGridLayout(); { "#000000", tr("Black", "Color name") },
mainPaletteLayout->setSpacing( 0 ); { "#2e3436", tr("Very Dark Gray", "Color name") },
for ( int iRow = 0; iRow < PALETTE_ROWS; iRow++ ) { "#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 );
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 );
for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ ) for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ )
{ {
int i = iRow*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)) );
ColorPaletteItem* item = new ColorPaletteItem( i, customPaletteLayout->addWidget( mHistoryItem[iCol] );
QColor( mColorTable[i].colorSpec ), }
mColorTable[i].name ); vLayout->addLayout( customPaletteLayout );
connect( item, SIGNAL(activated(int)), this, SLOT(onPaletteItemActivated(int)) );
mainPaletteLayout->addWidget( item, iRow, iCol );
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 );
mMergeFieldCombo = new QComboBox();
mMergeFieldCombo->addItem( tr("Merge key...") );
mMergeFieldCombo->setMinimumSize( 34, 34 );
mMergeFieldCombo->setFrame( false );
mMergeFieldCombo->setEnabled( false );
connect( mMergeFieldCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboIndexChanged(int)) );
vLayout->addWidget( mMergeFieldCombo );
// Item 0 is the ComboBox title, not an item intended for selection. So disable it.
const QStandardItemModel* model = qobject_cast<const QStandardItemModel*>(mMergeFieldCombo->model());
QStandardItem* item = model->item(0);
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
setLayout( vLayout );
loadCustomColorHistory();
}
void ColorPaletteDialog::setColorNode( const ColorNode& colorNode )
{
mColorNode = colorNode;
}
void ColorPaletteDialog::setKeys( const QStringList& keyList )
{
mKeys = keyList;
// Clear old keys, (all entries, except item 0)
for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- )
{
mMergeFieldCombo->removeItem( index );
}
// Add new keys
if ( keyList.size() > 0 )
{
mMergeFieldCombo->addItems( keyList );
mMergeFieldCombo->setEnabled( true );
}
else
{
mMergeFieldCombo->setEnabled( false );
} }
} }
vLayout->addLayout( mainPaletteLayout );
QFrame* hline2 = new QFrame;
hline2->setFrameStyle( QFrame::HLine | QFrame::Plain );
hline2->setLineWidth( 1 );
vLayout->addWidget( hline2 );
QHBoxLayout* customPaletteLayout = new QHBoxLayout(); void ColorPaletteDialog::clearKeys()
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 );
mMergeFieldCombo = new QComboBox();
mMergeFieldCombo->addItem( tr("Merge key...") );
mMergeFieldCombo->setMinimumSize( 34, 34 );
mMergeFieldCombo->setFrame( false );
mMergeFieldCombo->setEnabled( false );
connect( mMergeFieldCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboIndexChanged(int)) );
vLayout->addWidget( mMergeFieldCombo );
// Item 0 is the ComboBox title, not an item intended for selection. So disable it.
const QStandardItemModel* model = qobject_cast<const QStandardItemModel*>(mMergeFieldCombo->model());
QStandardItem* item = model->item(0);
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
setLayout( vLayout ); for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- )
{
loadCustomColorHistory(); mMergeFieldCombo->removeItem( index );
} }
void ColorPaletteDialog::setColorNode( const ColorNode& colorNode )
{
mColorNode = colorNode;
}
void ColorPaletteDialog::setKeys( const QStringList& keyList )
{
mKeys = keyList;
// Clear old keys, (all entries, except item 0)
for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- )
{
mMergeFieldCombo->removeItem( index );
}
// Add new keys
if ( keyList.size() > 0 )
{
mMergeFieldCombo->addItems( keyList );
mMergeFieldCombo->setEnabled( true );
}
else
{
mMergeFieldCombo->setEnabled( false ); mMergeFieldCombo->setEnabled( false );
} }
}
void ColorPaletteDialog::clearKeys() void ColorPaletteDialog::onDefaultItemActivated()
{
for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- )
{ {
mMergeFieldCombo->removeItem( index ); mColorNode.setField( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, true );
accept();
} }
mMergeFieldCombo->setEnabled( false );
}
void ColorPaletteDialog::onDefaultItemActivated() void ColorPaletteDialog::onPaletteItemActivated( int id )
{
mColorNode.setField( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, true );
accept();
}
void ColorPaletteDialog::onPaletteItemActivated( int id )
{
mColorNode.setField( false );
mColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, false );
accept();
}
void ColorPaletteDialog::onHistoryItemActivated( int id )
{
mColorNode.setField( false );
mColorNode.setColor( mColorHistory->getColors()[id] );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, false );
accept();
}
void ColorPaletteDialog::onCustomColorItemActivated()
{
QColorDialog dlg( mColorNode.color(), this );
dlg.setWindowTitle( tr("Custom Color") );
if ( dlg.exec() )
{ {
ColorNode newColorNode; mColorNode.setField( false );
mColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
mColorNode.setKey( "" );
newColorNode.setField( false ); emit colorChanged( mColorNode, false );
newColorNode.setColor( dlg.currentColor() ); accept();
newColorNode.setKey( "" ); }
if ( newColorNode != mColorNode )
void ColorPaletteDialog::onHistoryItemActivated( int id )
{
mColorNode.setField( false );
mColorNode.setColor( mColorHistory->getColors()[id] );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, false );
accept();
}
void ColorPaletteDialog::onCustomColorItemActivated()
{
QColorDialog dlg( mColorNode.color(), this );
dlg.setWindowTitle( tr("Custom Color") );
if ( dlg.exec() )
{ {
mColorNode = newColorNode; ColorNode newColorNode;
newColorNode.setField( false );
newColorNode.setColor( dlg.currentColor() );
newColorNode.setKey( "" );
if ( newColorNode != mColorNode )
{
mColorNode = newColorNode;
mColorHistory->addColor( mColorNode.color() ); mColorHistory->addColor( mColorNode.color() );
emit colorChanged( mColorNode, false );
accept();
}
}
}
void ColorPaletteDialog::onColorHistoryChanged()
{
loadCustomColorHistory();
}
void ColorPaletteDialog::loadCustomColorHistory()
{
QList<QColor> colorList = mColorHistory->getColors();
int id = 0;
foreach ( QColor color, colorList )
{
mHistoryItem[id]->setColor( id, color, QString(tr("Custom color #%1").arg(id+1) ) );
mHistoryItem[id]->setEnabled( true );
id++;
}
while ( id < PALETTE_ROWS )
{
mHistoryItem[id]->setEnabled( false );
id++;
}
}
void ColorPaletteDialog::onComboIndexChanged( int index )
{
if ( index != 0 )
{
mColorNode.setField( true );
mColorNode.setColor( QColor("#eeeeec") );
mColorNode.setKey( mKeys[index-1] );
emit colorChanged( mColorNode, false ); emit colorChanged( mColorNode, false );
accept(); accept();
} }
} }
}
void ColorPaletteDialog::onColorHistoryChanged() void ColorPaletteDialog::showEvent( QShowEvent* event )
{
loadCustomColorHistory();
}
void ColorPaletteDialog::loadCustomColorHistory()
{
QList<QColor> colorList = mColorHistory->getColors();
int id = 0;
foreach ( QColor color, colorList )
{ {
mHistoryItem[id]->setColor( id, color, QString(tr("Custom color #%1").arg(id+1) ) ); mMergeFieldCombo->setCurrentIndex( 0 );
mHistoryItem[id]->setEnabled( true );
id++; QDialog::showEvent( event );
} }
while ( id < PALETTE_ROWS )
{
mHistoryItem[id]->setEnabled( false );
id++;
}
}
void ColorPaletteDialog::onComboIndexChanged( int index )
{
if ( index != 0 )
{
mColorNode.setField( true );
mColorNode.setColor( QColor("#eeeeec") );
mColorNode.setKey( mKeys[index-1] );
emit colorChanged( mColorNode, false );
accept();
}
}
void ColorPaletteDialog::showEvent( QShowEvent* event )
{
mMergeFieldCombo->setCurrentIndex( 0 );
QDialog::showEvent( event );
} }
+65 -60
View File
@@ -31,86 +31,91 @@
#include "ColorPaletteButtonItem.h" #include "ColorPaletteButtonItem.h"
/// namespace glabels
/// Color Palette Dialog
///
class ColorPaletteDialog : public QDialog
{ {
Q_OBJECT
///
/// Color Palette Dialog
///
class ColorPaletteDialog : public QDialog
{
Q_OBJECT
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
ColorPaletteDialog( const QString& defaultLabel, ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor, const QColor& defaultColor,
const QColor& color, const QColor& color,
QWidget* parent = 0 ); QWidget* parent = 0 );
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void colorChanged( ColorNode colorNode, bool isDefault ); void colorChanged( ColorNode colorNode, bool isDefault );
///////////////////////////////// /////////////////////////////////
// Public Methods // Public Methods
///////////////////////////////// /////////////////////////////////
public: public:
void setColorNode( const ColorNode& colorNode ); void setColorNode( const ColorNode& colorNode );
void setKeys( const QStringList& keyList ); void setKeys( const QStringList& keyList );
void clearKeys(); void clearKeys();
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onDefaultItemActivated(); void onDefaultItemActivated();
void onPaletteItemActivated( int id ); void onPaletteItemActivated( int id );
void onHistoryItemActivated( int id ); void onHistoryItemActivated( int id );
void onCustomColorItemActivated(); void onCustomColorItemActivated();
void onColorHistoryChanged(); void onColorHistoryChanged();
void onComboIndexChanged( int index ); void onComboIndexChanged( int index );
protected: protected:
void showEvent( QShowEvent* event ); void showEvent( QShowEvent* event );
///////////////////////////////// /////////////////////////////////
// Private Methods // Private Methods
///////////////////////////////// /////////////////////////////////
private: private:
void loadCustomColorHistory(); void loadCustomColorHistory();
///////////////////////////////// /////////////////////////////////
// Private Members // Private Members
///////////////////////////////// /////////////////////////////////
private: private:
QColor mDefaultColor; QColor mDefaultColor;
ColorNode mColorNode; ColorNode mColorNode;
static const int PALETTE_COLS = ColorHistory::MAX_COLORS; static const int PALETTE_COLS = ColorHistory::MAX_COLORS;
static const int PALETTE_ROWS = 4; static const int PALETTE_ROWS = 4;
typedef struct { typedef struct {
QString colorSpec; QString colorSpec;
QString name; QString name;
} ColorTableEntry; } ColorTableEntry;
static ColorTableEntry mColorTable[]; static ColorTableEntry mColorTable[];
ColorHistory* mColorHistory; ColorHistory* mColorHistory;
ColorPaletteItem* mHistoryItem[PALETTE_COLS]; ColorPaletteItem* mHistoryItem[PALETTE_COLS];
QComboBox* mMergeFieldCombo; QComboBox* mMergeFieldCombo;
QStringList mKeys; QStringList mKeys;
}; };
}
#endif // ColorPaletteDialog_h #endif // ColorPaletteDialog_h
+99 -94
View File
@@ -25,120 +25,125 @@
#include <QPainter> #include <QPainter>
// namespace glabels
// Private Configuration Data
//
namespace
{ {
const int border = 4;
const int wSwatch = 25;
const int hSwatch = 25;
const int hoverBgOutlineWidthPixels = 1;
const int outlineWidthPixels = 1;
}
///
/// 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 );
}
///
/// 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 // Private
// //
if ( isEnabled() ) namespace
{ {
if ( mHover ) const int border = 4;
const int wSwatch = 25;
const int hSwatch = 25;
const int hoverBgOutlineWidthPixels = 1;
const int outlineWidthPixels = 1;
}
///
/// 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 );
}
///
/// 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() )
{ {
QPen pen( palette().color( QPalette::Text ) ); if ( mHover )
pen.setWidth( 2*outlineWidthPixels ); {
pen.setJoinStyle( Qt::MiterJoin ); QPen pen( palette().color( QPalette::Text ) );
painter.setPen( pen ); pen.setWidth( 2*outlineWidthPixels );
painter.setBrush( QBrush( mColor ) ); pen.setJoinStyle( Qt::MiterJoin );
painter.drawRect( 1, 1, width()-2, height()-2 ); 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 );
}
} }
else else
{ {
QPen pen( palette().color( QPalette::Text ) ); QPen pen( palette().color( QPalette::Disabled, QPalette::Text ) );
pen.setWidth( outlineWidthPixels ); pen.setWidth( outlineWidthPixels );
painter.setPen( pen ); painter.setPen( pen );
painter.setBrush( QBrush( mColor ) ); painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch ); painter.drawRect( border, border, wSwatch, hSwatch );
} }
} }
else
///
/// Enter Event
///
void ColorPaletteItem::enterEvent( QEvent* event )
{ {
QPen pen( palette().color( QPalette::Disabled, QPalette::Text ) ); mHover = true;
pen.setWidth( outlineWidthPixels ); update();
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch );
} }
}
///
/// /// Leave Event
/// Enter Event ///
/// void ColorPaletteItem::leaveEvent( QEvent* event )
void ColorPaletteItem::enterEvent( QEvent* event ) {
{ mHover = false;
mHover = true; update();
update(); }
}
///
/// Leave Event
///
void ColorPaletteItem::leaveEvent( QEvent* event )
{
mHover = false;
update();
}
/// ///
/// Mouse Press Event /// Mouse Press Event
/// ///
void ColorPaletteItem::mousePressEvent( QMouseEvent* event ) void ColorPaletteItem::mousePressEvent( QMouseEvent* event )
{ {
emit activated( mId ); emit activated( mId );
}
} }
+47 -42
View File
@@ -26,59 +26,64 @@
#include <QWidget> #include <QWidget>
/// namespace glabels
/// Color Palette Item
///
class ColorPaletteItem : public QWidget
{ {
Q_OBJECT
///////////////////////////////// ///
// Life Cycle /// Color Palette Item
///////////////////////////////// ///
public: class ColorPaletteItem : public QWidget
ColorPaletteItem( int id, {
const QColor& color, Q_OBJECT
const QString& tip,
QWidget* parent = 0 ); /////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteItem( int id,
const QColor& color,
const QString& tip,
QWidget* parent = 0 );
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void activated( int id ); void activated( int id );
///////////////////////////////// /////////////////////////////////
// Public Methods // Public Methods
///////////////////////////////// /////////////////////////////////
public: public:
void setColor( int id, void setColor( int id,
const QColor& color, const QColor& color,
const QString& tip ); const QString& tip );
///////////////////////////////// /////////////////////////////////
// Event handlers // Event handlers
///////////////////////////////// /////////////////////////////////
protected: protected:
void paintEvent( QPaintEvent* event ); void paintEvent( QPaintEvent* event );
void enterEvent( QEvent* event ); void enterEvent( QEvent* event );
void leaveEvent( QEvent* event ); void leaveEvent( QEvent* event );
void mousePressEvent( QMouseEvent* event ); void mousePressEvent( QMouseEvent* event );
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
int mId; int mId;
QColor mColor; QColor mColor;
QString mTip; QString mTip;
bool mHover; bool mHover;
}; };
}
#endif // ColorPaletteItem_h #endif // ColorPaletteItem_h
+33 -28
View File
@@ -24,33 +24,38 @@
#include <QPainter> #include <QPainter>
// namespace glabels
// Private Configuration Data
//
namespace
{ {
const QColor outlineColor( 0, 0, 0 );
const double outlineWidthPixels = 1; //
} // Private
//
namespace
/// {
/// Constructor const QColor outlineColor( 0, 0, 0 );
/// const double outlineWidthPixels = 1;
ColorSwatch::ColorSwatch( int w, int h, const QColor& color ) }
: QPixmap( w, h )
{
fill( Qt::transparent ); ///
/// Constructor
QPainter painter(this ); ///
ColorSwatch::ColorSwatch( int w, int h, const QColor& color )
painter.setBackgroundMode( Qt::TransparentMode ); : QPixmap( w, h )
{
QBrush brush( color ); fill( Qt::transparent );
QPen pen( outlineColor );
pen.setWidth( outlineWidthPixels ); QPainter painter(this );
painter.setBrush( brush ); painter.setBackgroundMode( Qt::TransparentMode );
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 );
}
} }
+15 -10
View File
@@ -25,19 +25,24 @@
#include <QPixmap> #include <QPixmap>
/// namespace glabels
/// Simple Preview Widget
///
class ColorSwatch : public QPixmap
{ {
///
/// Simple Preview Widget
///
class ColorSwatch : public QPixmap
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
ColorSwatch( int w, int h, const QColor& color ); ColorSwatch( int w, int h, const QColor& color );
}; };
}
#endif // ColorSwatch_h #endif // ColorSwatch_h
+1
View File
@@ -31,6 +31,7 @@ namespace glabels
const double PTS_PER_CM = (10.0*PTS_PER_MM); const double PTS_PER_CM = (10.0*PTS_PER_MM);
const double PTS_PER_PICA = 12.0; const double PTS_PER_PICA = 12.0;
const Distance EPSILON( 0.5, Units::PT );
} }
#endif // glabels_Constants_h #endif // glabels_Constants_h
+43 -32
View File
@@ -23,37 +23,48 @@
#include <QPixmap> #include <QPixmap>
Cursors::Barcode::Barcode() namespace glabels
: QCursor( QPixmap(":cursors/32x32/cursor_barcode.png"), 7, 7 )
{
}
Cursors::Box::Box()
: QCursor( QPixmap(":cursors/32x32/cursor_box.png"), 7, 7 )
{
}
Cursors::Ellipse::Ellipse()
: QCursor( QPixmap(":cursors/32x32/cursor_ellipse.png"), 7, 7 )
{
}
Cursors::Image::Image()
: QCursor( QPixmap(":cursors/32x32/cursor_image.png"), 7, 7 )
{
}
Cursors::Line::Line()
: QCursor( QPixmap(":cursors/32x32/cursor_line.png"), 7, 7 )
{
}
Cursors::Text::Text()
: QCursor( QPixmap(":cursors/32x32/cursor_text.png"), 7, 7 )
{ {
Cursors::Barcode::Barcode()
: QCursor( QPixmap(":cursors/32x32/cursor_barcode.png"), 7, 7 )
{
// empty
}
Cursors::Box::Box()
: QCursor( QPixmap(":cursors/32x32/cursor_box.png"), 7, 7 )
{
// empty
}
Cursors::Ellipse::Ellipse()
: QCursor( QPixmap(":cursors/32x32/cursor_ellipse.png"), 7, 7 )
{
// empty
}
Cursors::Image::Image()
: QCursor( QPixmap(":cursors/32x32/cursor_image.png"), 7, 7 )
{
// empty
}
Cursors::Line::Line()
: QCursor( QPixmap(":cursors/32x32/cursor_line.png"), 7, 7 )
{
// empty
}
Cursors::Text::Text()
: QCursor( QPixmap(":cursors/32x32/cursor_text.png"), 7, 7 )
{
// empty
}
} }
+39 -34
View File
@@ -25,53 +25,58 @@
#include <QCursor> #include <QCursor>
/// namespace glabels
/// Glabels Cursors
///
namespace Cursors
{ {
///
/// Glabels Cursors
///
namespace Cursors
{
class Barcode : public QCursor class Barcode : public QCursor
{ {
public: public:
Barcode(); Barcode();
}; };
class Box : public QCursor class Box : public QCursor
{ {
public: public:
Box(); Box();
}; };
class Ellipse : public QCursor class Ellipse : public QCursor
{ {
public: public:
Ellipse(); Ellipse();
}; };
class Image : public QCursor class Image : public QCursor
{ {
public: public:
Image(); Image();
}; };
class Line : public QCursor class Line : public QCursor
{ {
public: public:
Line(); Line();
}; };
class Text : public QCursor class Text : public QCursor
{ {
public: public:
Text(); Text();
}; };
}
} }
+24 -17
View File
@@ -32,18 +32,26 @@
#include "XmlVendorParser.h" #include "XmlVendorParser.h"
namespace
{
bool partNameLessThan( const glabels::Template *a, const glabels::Template *b )
{
return glabels::StrUtil::comparePartNames( a->name(), b->name() ) < 0;
}
}
namespace glabels namespace glabels
{ {
//
// Private
//
namespace
{
const QString empty = "";
bool partNameLessThan( const Template *a, const Template *b )
{
return StrUtil::comparePartNames( a->name(), b->name() ) < 0;
}
}
//
// Static data
//
QList<Paper*> Db::mPapers; QList<Paper*> Db::mPapers;
QStringList Db::mPaperIds; QStringList Db::mPaperIds;
QStringList Db::mPaperNames; QStringList Db::mPaperNames;
@@ -53,10 +61,9 @@ namespace glabels
QList<Vendor*> Db::mVendors; QList<Vendor*> Db::mVendors;
QStringList Db::mVendorNames; QStringList Db::mVendorNames;
QList<Template*> Db::mTemplates; QList<Template*> Db::mTemplates;
QString Db::mPaperNameOther;
QString Db::mPaperNameOther;
QString Db::mEmpty = "";
Db::Db() Db::Db()
{ {
mPaperNameOther = tr("Other"); mPaperNameOther = tr("Other");
@@ -204,7 +211,7 @@ namespace glabels
} }
qWarning() << "Unknown paper name: " << name; qWarning() << "Unknown paper name: " << name;
return mEmpty; return empty;
} }
@@ -225,7 +232,7 @@ namespace glabels
} }
qWarning() << "Unknown paper id: " << id; qWarning() << "Unknown paper id: " << id;
return mEmpty; return empty;
} }
@@ -318,7 +325,7 @@ namespace glabels
} }
qWarning() << "Unknown category name: " << name; qWarning() << "Unknown category name: " << name;
return mEmpty; return empty;
} }
@@ -334,7 +341,7 @@ namespace glabels
} }
qWarning() << "Unknown category id: " << id; qWarning() << "Unknown category id: " << id;
return mEmpty; return empty;
} }
@@ -399,7 +406,7 @@ namespace glabels
} }
qWarning() << "Unknown vendor name: " << name; qWarning() << "Unknown vendor name: " << name;
return mEmpty; return empty;
} }
+2 -2
View File
@@ -131,8 +131,8 @@ namespace glabels
static QList<Template*> mTemplates; static QList<Template*> mTemplates;
static QString mPaperNameOther; static QString mPaperNameOther;
static QString mEmpty;
}; };
} }
+76 -71
View File
@@ -21,101 +21,106 @@
#include "EnumUtil.h" #include "EnumUtil.h"
namespace EnumUtil namespace glabels
{ {
QString weightToString( QFont::Weight weight ) namespace EnumUtil
{ {
switch (weight)
QString weightToString( QFont::Weight weight )
{ {
case QFont::Bold: switch (weight)
return "bold"; {
break; case QFont::Bold:
default: return "bold";
return "normal"; break;
break; default:
return "normal";
break;
}
} }
}
QFont::Weight stringToWeight( const QString& string ) QFont::Weight stringToWeight( const QString& string )
{
if ( string == "bold" )
{ {
return QFont::Bold; if ( string == "bold" )
{
return QFont::Bold;
}
else
{
return QFont::Normal;
}
} }
else
{
return QFont::Normal;
}
}
QString hAlignToString( Qt::Alignment align ) QString hAlignToString( Qt::Alignment align )
{
switch (align)
{ {
case Qt::AlignRight: switch (align)
return "right"; {
break; case Qt::AlignRight:
case Qt::AlignHCenter: return "right";
return "center"; break;
break; case Qt::AlignHCenter:
default: return "center";
return "left"; break;
break; default:
return "left";
break;
}
} }
}
Qt::Alignment stringToHAlign( const QString& string ) Qt::Alignment stringToHAlign( const QString& string )
{
if ( string == "right" )
{ {
return Qt::AlignRight; if ( string == "right" )
{
return Qt::AlignRight;
}
else if ( string == "center" )
{
return Qt::AlignHCenter;
}
else
{
return Qt::AlignLeft;
}
} }
else if ( string == "center" )
{
return Qt::AlignHCenter;
}
else
{
return Qt::AlignLeft;
}
}
QString vAlignToString( Qt::Alignment align ) QString vAlignToString( Qt::Alignment align )
{
switch (align)
{ {
case Qt::AlignBottom: switch (align)
return "bottom"; {
break; case Qt::AlignBottom:
case Qt::AlignVCenter: return "bottom";
return "center"; break;
break; case Qt::AlignVCenter:
default: return "center";
return "top"; break;
break; default:
return "top";
break;
}
} }
}
Qt::Alignment stringToVAlign( const QString& string ) Qt::Alignment stringToVAlign( const QString& string )
{
if ( string == "bottom" )
{ {
return Qt::AlignBottom; if ( string == "bottom" )
} {
else if ( string == "center" ) return Qt::AlignBottom;
{ }
return Qt::AlignVCenter; else if ( string == "center" )
} {
else return Qt::AlignVCenter;
{ }
return Qt::AlignTop; else
{
return Qt::AlignTop;
}
} }
} }
} }
+12 -7
View File
@@ -27,17 +27,22 @@
#include <Qt> #include <Qt>
namespace EnumUtil namespace glabels
{ {
QString weightToString( QFont::Weight weight ); namespace EnumUtil
QFont::Weight stringToWeight( const QString& string ); {
QString hAlignToString( Qt::Alignment align ); QString weightToString( QFont::Weight weight );
Qt::Alignment stringToHAlign( const QString& string ); QFont::Weight stringToWeight( const QString& string );
QString vAlignToString( Qt::Alignment align ); QString hAlignToString( Qt::Alignment align );
Qt::Alignment stringToVAlign( const QString& string ); Qt::Alignment stringToHAlign( const QString& string );
QString vAlignToString( Qt::Alignment align );
Qt::Alignment stringToVAlign( const QString& string );
}
} }
+74 -69
View File
@@ -25,80 +25,85 @@
#include <QStandardItemModel> #include <QStandardItemModel>
/// namespace glabels
/// Constructor
///
FieldButton::FieldButton( QWidget* parent )
: QComboBox(parent)
{ {
setEnabled( false );
connect( this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int)) ); ///
} /// Constructor
///
FieldButton::FieldButton( QWidget* parent )
void FieldButton::setName( const QString& name ) : QComboBox(parent)
{
mName = name;
if ( count() == 0 )
{ {
setEnabled( false );
connect( this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int)) );
}
void FieldButton::setName( const QString& name )
{
mName = name;
if ( count() == 0 )
{
addItem( mName );
}
else
{
setItemText( 0, mName );
}
// Item 0 is the ComboBox title, not an item intended for selection. So disable it.
const QStandardItemModel* itemModel = qobject_cast<const QStandardItemModel*>(model());
QStandardItem* item = itemModel->item(0);
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
}
void FieldButton::setKeys( const QStringList& keyList )
{
// Clear old keys
clear();
addItem( mName ); addItem( mName );
}
else
{
setItemText( 0, mName );
}
// Item 0 is the ComboBox title, not an item intended for selection. So disable it. // Item 0 is the ComboBox title, not an item intended for selection. So disable it.
const QStandardItemModel* itemModel = qobject_cast<const QStandardItemModel*>(model()); const QStandardItemModel* itemModel = qobject_cast<const QStandardItemModel*>(model());
QStandardItem* item = itemModel->item(0); QStandardItem* item = itemModel->item(0);
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) ); item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
}
void FieldButton::setKeys( const QStringList& keyList )
{
// Clear old keys
clear();
addItem( mName );
// Item 0 is the ComboBox title, not an item intended for selection. So disable it.
const QStandardItemModel* itemModel = qobject_cast<const QStandardItemModel*>(model());
QStandardItem* item = itemModel->item(0);
item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
// Add new keys // Add new keys
if ( keyList.size() > 0 ) if ( keyList.size() > 0 )
{ {
addItems( keyList ); addItems( keyList );
setEnabled( true ); setEnabled( true );
} }
else else
{ {
setEnabled( false ); setEnabled( false );
} }
}
void FieldButton::clearKeys()
{
clear();
addItem( mName );
setEnabled( false );
}
///
/// onMenuKeySelected slot
///
void FieldButton::onIndexChanged( int index )
{
if ( index > 0 )
{
emit keySelected( itemText(index) );
setCurrentIndex( 0 );
} }
void FieldButton::clearKeys()
{
clear();
addItem( mName );
setEnabled( false );
}
///
/// onMenuKeySelected slot
///
void FieldButton::onIndexChanged( int index )
{
if ( index > 0 )
{
emit keySelected( itemText(index) );
setCurrentIndex( 0 );
}
}
} }
+38 -33
View File
@@ -26,50 +26,55 @@
#include <QString> #include <QString>
/// namespace glabels
/// Field Button
///
class FieldButton : public QComboBox
{ {
Q_OBJECT
///////////////////////////////// ///
// Life Cycle /// Field Button
///////////////////////////////// ///
public: class FieldButton : public QComboBox
FieldButton( QWidget* parent = 0 ); {
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldButton( QWidget* parent = 0 );
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void keySelected( QString key ); void keySelected( QString key );
///////////////////////////////// /////////////////////////////////
// Public Methods // Public Methods
///////////////////////////////// /////////////////////////////////
public: public:
void setName( const QString& name = "" ); void setName( const QString& name = "" );
void setKeys( const QStringList& keyList ); void setKeys( const QStringList& keyList );
void clearKeys(); void clearKeys();
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onIndexChanged( int index ); void onIndexChanged( int index );
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
QString mName; QString mName;
}; };
}
#endif // FieldButton_h #endif // FieldButton_h
+169 -164
View File
@@ -33,81 +33,34 @@
#include "XmlLabelCreator.h" #include "XmlLabelCreator.h"
/// namespace glabels
/// Static data
///
QString File::mCwd = ".";
///
/// New Label Dialog
///
bool File::newLabel( MainWindow *window )
{ {
SelectProductDialog dialog( window );
dialog.exec();
const glabels::Template* tmplate = dialog.tmplate(); //
if ( tmplate ) // Static data
//
QString File::mCwd = ".";
///
/// New Label Dialog
///
bool File::newLabel( MainWindow *window )
{ {
LabelModel* label = new LabelModel(); SelectProductDialog dialog( window );
label->setTmplate( tmplate ); dialog.exec();
label->clearModified();
// Intelligently decide to rotate label by default const Template* tmplate = dialog.tmplate();
const glabels::Frame* frame = tmplate->frames().first(); if ( tmplate )
label->setRotate( frame->h() > frame->w() );
// Either apply to current window or open a new one
if ( window->isEmpty() )
{ {
window->setModel( label ); LabelModel* label = new LabelModel();
} label->setTmplate( tmplate );
else label->clearModified();
{
MainWindow *newWindow = new MainWindow();
newWindow->setModel( label );
newWindow->show();
}
return true; // Intelligently decide to rotate label by default
} const Frame* frame = tmplate->frames().first();
else label->setRotate( frame->h() > frame->w() );
{
return false;
}
}
///
/// Open File Dialog
///
void File::open( MainWindow *window )
{
// Either use the saved CWD from a previous open/save or grab it from the path of the current file
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
cwd = fileInfo.absolutePath();
}
}
QString fileName =
QFileDialog::getOpenFileName( window,
tr("gLabels - Open Project"),
cwd,
tr("glabels files (*.glabels);;All files (*)")
);
if ( !fileName.isEmpty() )
{
LabelModel *label = XmlLabelParser::readFile( fileName );
if ( label )
{
label->setFileName( fileName );
// Either apply to current window or open a new one // Either apply to current window or open a new one
if ( window->isEmpty() ) if ( window->isEmpty() )
{ {
@@ -120,123 +73,175 @@ void File::open( MainWindow *window )
newWindow->show(); newWindow->show();
} }
// Save CWD return true;
mCwd = QFileInfo( fileName ).absolutePath();
} }
else else
{ {
QMessageBox msgBox; return false;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
msgBox.setDefaultButton( QMessageBox::Ok );
msgBox.exec();
} }
} }
}
/// ///
/// Save file /// Open File Dialog
/// ///
bool File::save( MainWindow *window ) void File::open( MainWindow *window )
{
if ( window->model()->fileName().isEmpty() )
{ {
return saveAs( window ); // Either use the saved CWD from a previous open/save or grab it from the path of the current file
} QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
if ( !window->model()->isModified() )
{
return true;
}
XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
window->model()->clearModified();
// Save CWD
mCwd = QFileInfo( window->model()->fileName() ).absolutePath();
return true;
}
///
/// Save file as
///
bool File::saveAs( MainWindow *window )
{
// Either use the saved CWD from a previous open/save or grab it from the path of the current file
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{ {
cwd = fileInfo.filePath(); QFileInfo fileInfo( window->model()->fileName() );
} if ( fileInfo.isFile() )
}
QString rawFileName =
QFileDialog::getSaveFileName( window,
tr("gLabels - Save Project As"),
cwd,
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 ); cwd = fileInfo.absolutePath();
} }
} }
XmlLabelCreator::writeFile( window->model(), fileName ); QString fileName =
window->model()->setFileName( fileName ); QFileDialog::getOpenFileName( window,
tr("gLabels - Open Project"),
cwd,
tr("glabels files (*.glabels);;All files (*)")
);
if ( !fileName.isEmpty() )
{
LabelModel *label = XmlLabelParser::readFile( fileName );
if ( label )
{
label->setFileName( fileName );
// Either apply to current window or open a new one
if ( window->isEmpty() )
{
window->setModel( label );
}
else
{
MainWindow *newWindow = new MainWindow();
newWindow->setModel( label );
newWindow->show();
}
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
}
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 );
}
if ( !window->model()->isModified() )
{
return true;
}
XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
window->model()->clearModified(); window->model()->clearModified();
// Save CWD // Save CWD
mCwd = QFileInfo( fileName ).absolutePath(); mCwd = QFileInfo( window->model()->fileName() ).absolutePath();
return true; return true;
} }
return false;
}
///
/// /// Save file as
/// Close file ///
/// bool File::saveAs( MainWindow *window )
void File::close( MainWindow *window )
{
window->close();
}
///
/// Exit, closing all windows
///
void File::exit()
{
foreach ( QWidget* qwidget, QApplication::topLevelWidgets() )
{ {
if ( MainWindow* window = qobject_cast<MainWindow*>(qwidget) ) // Either use the saved CWD from a previous open/save or grab it from the path of the current file
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{ {
window->close(); QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
cwd = fileInfo.filePath();
}
}
QString rawFileName =
QFileDialog::getSaveFileName( window,
tr("gLabels - Save Project As"),
cwd,
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 );
window->model()->clearModified();
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
return true;
}
return false;
}
///
/// Close file
///
void File::close( MainWindow *window )
{
window->close();
}
///
/// Exit, closing all windows
///
void File::exit()
{
foreach ( QWidget* qwidget, QApplication::topLevelWidgets() )
{
if ( MainWindow* window = qobject_cast<MainWindow*>(qwidget) )
{
window->close();
}
} }
} }
} }
+26 -20
View File
@@ -24,31 +24,37 @@
#include <QObject> #include <QObject>
// Forward References
class MainWindow;
namespace glabels
///
/// File Actions
///
/// Note: class provides a translation context for these static functions.
///
class File : public QObject
{ {
Q_OBJECT
public: // Forward References
static bool newLabel( MainWindow *window = 0 ); class MainWindow;
static void open( MainWindow *window );
static bool save( MainWindow *window );
static bool saveAs( MainWindow *window );
static void close( MainWindow *window );
static void exit();
private:
static QString mCwd; ///
/// File Actions
///
/// Note: class provides a translation context for these static functions.
///
class File : public QObject
{
Q_OBJECT
public:
static bool newLabel( MainWindow *window = 0 );
static void open( MainWindow *window );
static bool save( MainWindow *window );
static bool saveAs( MainWindow *window );
static void close( MainWindow *window );
static void exit();
private:
static QString mCwd;
}; };
}
#endif // File_h #endif // File_h
+10 -5
View File
@@ -21,17 +21,22 @@
#include "FileUtil.h" #include "FileUtil.h"
namespace FileUtil namespace glabels
{ {
QString addExtension( const QString& rawFilename, const QString& extension ) namespace FileUtil
{ {
if ( rawFilename.endsWith( extension ) )
QString addExtension( const QString& rawFilename, const QString& extension )
{ {
return rawFilename; if ( rawFilename.endsWith( extension ) )
{
return rawFilename;
}
return rawFilename + extension;
} }
return rawFilename + extension;
} }
} }
+7 -2
View File
@@ -25,10 +25,15 @@
#include <QString> #include <QString>
namespace FileUtil namespace glabels
{ {
QString addExtension( const QString& rawFilename, const QString& extension ); namespace FileUtil
{
QString addExtension( const QString& rawFilename, const QString& extension );
}
} }
+1
View File
@@ -30,6 +30,7 @@ namespace glabels
Frame::Frame( const QString& id ) Frame::Frame( const QString& id )
: mId(id), mNLabels(0), mLayoutDescription("") : mId(id), mNLabels(0), mLayoutDescription("")
{ {
// empty
} }
+6 -5
View File
@@ -23,7 +23,7 @@
#include <QtDebug> #include <QtDebug>
#include "privateConstants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
@@ -96,6 +96,7 @@ namespace glabels
: mR1(other.mR1), mR2(other.mR2), mW(other.mW), mH(other.mH), mWaste(other.mWaste), : mR1(other.mR1), mR2(other.mR2), mW(other.mW), mH(other.mH), mWaste(other.mWaste),
mPath(other.mPath), Frame(other) mPath(other.mPath), Frame(other)
{ {
// empty
} }
@@ -160,10 +161,10 @@ namespace glabels
{ {
if ( FrameCd *otherCd = dynamic_cast<FrameCd*>(other) ) if ( FrameCd *otherCd = dynamic_cast<FrameCd*>(other) )
{ {
if ( (fabs( mW - otherCd->mW ) <= Constants::EPSILON) && if ( (fabs( mW - otherCd->mW ) <= EPSILON) &&
(fabs( mH - otherCd->mH ) <= Constants::EPSILON) && (fabs( mH - otherCd->mH ) <= EPSILON) &&
(fabs( mR1 - otherCd->mR1 ) <= Constants::EPSILON) && (fabs( mR1 - otherCd->mR1 ) <= EPSILON) &&
(fabs( mR2 - otherCd->mR2 ) <= Constants::EPSILON) ) (fabs( mR2 - otherCd->mR2 ) <= EPSILON) )
{ {
return true; return true;
} }
+4 -3
View File
@@ -21,7 +21,7 @@
#include "FrameEllipse.h" #include "FrameEllipse.h"
#include "privateConstants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
@@ -41,6 +41,7 @@ namespace glabels
FrameEllipse::FrameEllipse( const FrameEllipse& other ) FrameEllipse::FrameEllipse( const FrameEllipse& other )
: mW(other.mW), mH(other.mH), mWaste(other.mWaste), mPath(other.mPath), Frame(other) : mW(other.mW), mH(other.mH), mWaste(other.mWaste), mPath(other.mPath), Frame(other)
{ {
// empty
} }
@@ -94,8 +95,8 @@ namespace glabels
{ {
if ( FrameEllipse* otherEllipse = dynamic_cast<FrameEllipse*>(other) ) if ( FrameEllipse* otherEllipse = dynamic_cast<FrameEllipse*>(other) )
{ {
if ( (fabs( mW - otherEllipse->mW ) <= Constants::EPSILON) && if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) &&
(fabs( mH - otherEllipse->mH ) <= Constants::EPSILON) ) (fabs( mH - otherEllipse->mH ) <= EPSILON) )
{ {
return true; return true;
} }
+4 -3
View File
@@ -21,7 +21,7 @@
#include "FrameRect.h" #include "FrameRect.h"
#include "privateConstants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
@@ -48,6 +48,7 @@ namespace glabels
: mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste), : mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste),
mYWaste(other.mYWaste), mPath(other.mPath), Frame(other) mYWaste(other.mYWaste), mPath(other.mPath), Frame(other)
{ {
// empty
} }
@@ -113,8 +114,8 @@ namespace glabels
{ {
if ( FrameRect *otherRect = dynamic_cast<FrameRect*>(other) ) if ( FrameRect *otherRect = dynamic_cast<FrameRect*>(other) )
{ {
if ( (fabs( mW - otherRect->mW ) <= Constants::EPSILON) && if ( (fabs( mW - otherRect->mW ) <= EPSILON) &&
(fabs( mH - otherRect->mH ) <= Constants::EPSILON) ) (fabs( mH - otherRect->mH ) <= EPSILON) )
{ {
return true; return true;
} }
+5 -3
View File
@@ -21,7 +21,7 @@
#include "FrameRound.h" #include "FrameRound.h"
#include "privateConstants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
@@ -34,13 +34,15 @@ namespace glabels
: mR(r), mWaste(waste), Frame(id) : mR(r), mWaste(waste), Frame(id)
{ {
mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() ); mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() );
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), 2*(mR+mWaste).pt(), 2*(mR+mWaste).pt() ); mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(),
2*(mR+mWaste).pt(), 2*(mR+mWaste).pt() );
} }
FrameRound::FrameRound( const FrameRound& other ) FrameRound::FrameRound( const FrameRound& other )
: mR(other.mR), mWaste(other.mWaste), mPath(other.mPath), Frame(other) : mR(other.mR), mWaste(other.mWaste), mPath(other.mPath), Frame(other)
{ {
// empty
} }
@@ -99,7 +101,7 @@ namespace glabels
{ {
if ( FrameRound *otherRound = dynamic_cast<FrameRound*>(other) ) if ( FrameRound *otherRound = dynamic_cast<FrameRound*>(other) )
{ {
if ( fabs( mR - otherRound->mR ) <= Constants::EPSILON ) if ( fabs( mR - otherRound->mR ) <= EPSILON )
{ {
return true; return true;
} }
+536 -505
View File
File diff suppressed because it is too large Load Diff
+251 -245
View File
@@ -27,304 +27,310 @@
#include "Distance.h" #include "Distance.h"
// Forward References
class LabelModelObject;
namespace glabels
///
/// Handle Base Class
///
class Handle
{ {
////////////////////////////
// Location enumeration // Forward References
//////////////////////////// class LabelModelObject;
public:
enum Location { NW, N, NE, E, SE, S, SW, W, P1, P2 };
////////////////////////////
// Lifecycle Methods
////////////////////////////
protected:
Handle( LabelModelObject* owner, Location location );
public:
virtual ~Handle();
//////////////////////////// ///
// Duplication /// Handle Base Class
//////////////////////////// ///
virtual Handle* clone( LabelModelObject* newOwner ) const = 0; class Handle
{
////////////////////////////
// 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();
////////////////////////////
// Duplication
////////////////////////////
virtual Handle* clone( LabelModelObject* newOwner ) const = 0;
//////////////////////////// ////////////////////////////
// Attribue Methods // Attribue Methods
//////////////////////////// ////////////////////////////
LabelModelObject* owner() const; LabelModelObject* owner() const;
Location location() const; Location location() const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const = 0; virtual void draw( QPainter* painter, double scale ) const = 0;
virtual QPainterPath path( double scale ) const = 0; virtual QPainterPath path( double scale ) const = 0;
protected: protected:
void drawAt( QPainter* painter, void drawAt( QPainter* painter,
double scale, double scale,
const glabels::Distance& x, const Distance& x,
const glabels::Distance& y, const Distance& y,
QColor color ) const; QColor color ) const;
QPainterPath pathAt( double scale, QPainterPath pathAt( double scale,
const glabels::Distance& x, const Distance& x,
const glabels::Distance& y ) const; const Distance& y ) const;
//////////////////////////// ////////////////////////////
// Protected Data // Protected Data
//////////////////////////// ////////////////////////////
protected: protected:
LabelModelObject* mOwner; LabelModelObject* mOwner;
Location mLocation; Location mLocation;
}; };
/// ///
/// HandleNorth Class /// HandleNorth Class
/// ///
class HandleNorth : public Handle class HandleNorth : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleNorth( LabelModelObject* owner ); HandleNorth( LabelModelObject* owner );
virtual ~HandleNorth(); virtual ~HandleNorth();
virtual HandleNorth* clone( LabelModelObject* newOwner ) const; virtual HandleNorth* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleNorthEast Class /// HandleNorthEast Class
/// ///
class HandleNorthEast : public Handle class HandleNorthEast : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleNorthEast( LabelModelObject* owner ); HandleNorthEast( LabelModelObject* owner );
virtual ~HandleNorthEast(); virtual ~HandleNorthEast();
virtual HandleNorthEast* clone( LabelModelObject* newOwner ) const; virtual HandleNorthEast* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleEast Class /// HandleEast Class
/// ///
class HandleEast : public Handle class HandleEast : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleEast( LabelModelObject* owner ); HandleEast( LabelModelObject* owner );
virtual ~HandleEast(); virtual ~HandleEast();
virtual HandleEast* clone( LabelModelObject* newOwner ) const; virtual HandleEast* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleSouthEast Class /// HandleSouthEast Class
/// ///
class HandleSouthEast : public Handle class HandleSouthEast : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleSouthEast( LabelModelObject* owner ); HandleSouthEast( LabelModelObject* owner );
virtual ~HandleSouthEast(); virtual ~HandleSouthEast();
virtual HandleSouthEast* clone( LabelModelObject* newOwner ) const; virtual HandleSouthEast* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleSouth Class /// HandleSouth Class
/// ///
class HandleSouth : public Handle class HandleSouth : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleSouth( LabelModelObject* owner ); HandleSouth( LabelModelObject* owner );
virtual ~HandleSouth(); virtual ~HandleSouth();
virtual HandleSouth* clone( LabelModelObject* newOwner ) const; virtual HandleSouth* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleSouthWest Class /// HandleSouthWest Class
/// ///
class HandleSouthWest : public Handle class HandleSouthWest : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleSouthWest( LabelModelObject* owner ); HandleSouthWest( LabelModelObject* owner );
virtual ~HandleSouthWest(); virtual ~HandleSouthWest();
virtual HandleSouthWest* clone( LabelModelObject* newOwner ) const; virtual HandleSouthWest* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleWest Class /// HandleWest Class
/// ///
class HandleWest : public Handle class HandleWest : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleWest( LabelModelObject* owner ); HandleWest( LabelModelObject* owner );
virtual ~HandleWest(); virtual ~HandleWest();
virtual HandleWest* clone( LabelModelObject* newOwner ) const; virtual HandleWest* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleNorthWest Class /// HandleNorthWest Class
/// ///
class HandleNorthWest : public Handle class HandleNorthWest : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleNorthWest( LabelModelObject* owner ); HandleNorthWest( LabelModelObject* owner );
virtual ~HandleNorthWest(); virtual ~HandleNorthWest();
virtual HandleNorthWest* clone( LabelModelObject* newOwner ) const; virtual HandleNorthWest* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleP1 Class /// HandleP1 Class
/// ///
class HandleP1 : public Handle class HandleP1 : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleP1( LabelModelObject* owner ); HandleP1( LabelModelObject* owner );
virtual ~HandleP1(); virtual ~HandleP1();
virtual HandleP1* clone( LabelModelObject* newOwner ) const; virtual HandleP1* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
/// ///
/// HandleP2 Class /// HandleP2 Class
/// ///
class HandleP2 : public Handle class HandleP2 : public Handle
{ {
//////////////////////////// ////////////////////////////
// Lifecycle Methods // Lifecycle Methods
//////////////////////////// ////////////////////////////
public: public:
HandleP2( LabelModelObject* owner ); HandleP2( LabelModelObject* owner );
virtual ~HandleP2(); virtual ~HandleP2();
//////////////////////////// ////////////////////////////
// Duplication // Duplication
//////////////////////////// ////////////////////////////
virtual HandleP2* clone( LabelModelObject* newOwner ) const; virtual HandleP2* clone( LabelModelObject* newOwner ) const;
//////////////////////////// ////////////////////////////
// Drawing Methods // Drawing Methods
//////////////////////////// ////////////////////////////
public: public:
virtual void draw( QPainter* painter, double scale ) const; virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const; virtual QPainterPath path( double scale ) const;
}; };
}
#endif // Handles_h #endif // Handles_h
+18 -13
View File
@@ -26,20 +26,25 @@
#include "AboutDialog.h" #include "AboutDialog.h"
/// namespace glabels
/// Display Help Contents
///
void Help::displayContents( QWidget *parent )
{ {
qDebug() << "TODO: Help::displayContents";
} ///
/// Display Help Contents
///
void Help::displayContents( QWidget *parent )
{
qDebug() << "TODO: Help::displayContents";
}
/// ///
/// Display Help->About Dialog /// Display Help->About Dialog
/// ///
void Help::displayAbout( QWidget *parent ) void Help::displayAbout( QWidget *parent )
{ {
AboutDialog dialog( parent ); AboutDialog dialog( parent );
dialog.exec(); dialog.exec();
}
} }
+11 -7
View File
@@ -25,16 +25,20 @@
#include <QWidget> #include <QWidget>
/// namespace glabels
/// Help Actions
///
namespace Help
{ {
void displayContents( QWidget *parent ); ///
void displayAbout( QWidget *parent ); /// Help Actions
///
namespace Help
{
void displayContents( QWidget *parent );
void displayAbout( QWidget *parent );
}
} }
#endif // Help_h #endif // Help_h
+308 -312
View File
@@ -25,324 +25,320 @@
#include <QIcon> #include <QIcon>
/// 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" );
}
};
/// ///
/// Fallback Icons. These are fallbacks for icons that would normally come from the current theme, /// Glabels Icons
/// if supported. These icons are copied from the mate-icon-theme (GPL-v3 or CC-BY-SA-v3).
/// ///
namespace Fallback 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" );
}
};
class EditCopy : public QIcon class EditCopy : public QIcon
{ {
public: public:
+1141 -1138
View File
File diff suppressed because it is too large Load Diff
+163 -157
View File
@@ -28,188 +28,194 @@
#include "Region.h" #include "Region.h"
// Forward References
class LabelModel;
class LabelModelObject;
class UndoRedoModel;
class Handle;
namespace glabels
///
/// LabelEditor Widget
///
class LabelEditor : public QWidget
{ {
Q_OBJECT
///////////////////////////////////// // Forward References
// Lifecycle class LabelModel;
///////////////////////////////////// class LabelModelObject;
public: class UndoRedoModel;
LabelEditor( QScrollArea* scrollArea, QWidget* parent = 0 ); class Handle;
///////////////////////////////////// ///
// Signals /// LabelEditor Widget
///////////////////////////////////// ///
signals: class LabelEditor : public QWidget
void contextMenuActivate(); {
void zoomChanged(); Q_OBJECT
void pointerMoved( const glabels::Distance& x, const glabels::Distance& y );
void pointerExited(); /////////////////////////////////////
void modeChanged(); // Lifecycle
/////////////////////////////////////
public:
LabelEditor( QScrollArea* scrollArea, QWidget* parent = 0 );
///////////////////////////////////// /////////////////////////////////////
// Parameters // Signals
///////////////////////////////////// /////////////////////////////////////
public: signals:
double zoom() const; void contextMenuActivate();
bool markupVisible() const; void zoomChanged();
bool qridVisible() const; void pointerMoved( const Distance& x, const Distance& y );
void pointerExited();
void modeChanged();
///////////////////////////////////// /////////////////////////////////////
// Model // Parameters
///////////////////////////////////// /////////////////////////////////////
public: public:
void setModel( LabelModel* model, UndoRedoModel* undoRedoModel ); double zoom() const;
bool markupVisible() const;
bool qridVisible() const;
///////////////////////////////////// /////////////////////////////////////
// Visibility operations // Model
///////////////////////////////////// /////////////////////////////////////
public: public:
void setGridVisible( bool visibleFlag ); void setModel( LabelModel* model, UndoRedoModel* undoRedoModel );
void setMarkupVisible( bool visibleFlag );
///////////////////////////////////// /////////////////////////////////////
// Zoom operations // Visibility operations
///////////////////////////////////// /////////////////////////////////////
public: public:
void zoomIn(); void setGridVisible( bool visibleFlag );
void zoomOut(); void setMarkupVisible( bool visibleFlag );
void zoom1To1();
void zoomToFit();
bool isZoomMax() const;
bool isZoomMin() const;
private:
void setZoomReal( double zoom, bool zoomToFitFlag );
///////////////////////////////////// /////////////////////////////////////
// Mode operations // Zoom operations
///////////////////////////////////// /////////////////////////////////////
public: public:
void arrowMode(); void zoomIn();
void createBoxMode(); void zoomOut();
void createEllipseMode(); void zoom1To1();
void createLineMode(); void zoomToFit();
void createImageMode(); bool isZoomMax() const;
void createTextMode(); bool isZoomMin() const;
void createBarcodeMode(); private:
void setZoomReal( double zoom, bool zoomToFitFlag );
///////////////////////////////////// /////////////////////////////////////
// Event handlers // Mode operations
///////////////////////////////////// /////////////////////////////////////
protected: public:
void resizeEvent( QResizeEvent* event ); void arrowMode();
void mousePressEvent( QMouseEvent* event ); void createBoxMode();
void mouseMoveEvent( QMouseEvent* event ); void createEllipseMode();
void mouseReleaseEvent( QMouseEvent* event ); void createLineMode();
void leaveEvent( QEvent* event ); void createImageMode();
void keyPressEvent( QKeyEvent* event ); void createTextMode();
void paintEvent( QPaintEvent* event ); void createBarcodeMode();
///////////////////////////////////// /////////////////////////////////////
// Private methods // Event handlers
///////////////////////////////////// /////////////////////////////////////
private: protected:
void handleResizeMotion( const glabels::Distance& xWorld, void resizeEvent( QResizeEvent* event );
const glabels::Distance& yWorld ); void mousePressEvent( QMouseEvent* event );
void mouseMoveEvent( QMouseEvent* event );
void drawBgLayer( QPainter* painter ); void mouseReleaseEvent( QMouseEvent* event );
void drawGridLayer( QPainter* painter ); void leaveEvent( QEvent* event );
void drawMarkupLayer( QPainter* painter ); void keyPressEvent( QKeyEvent* event );
void drawObjectsLayer( QPainter* painter ); void paintEvent( QPaintEvent* event );
void drawFgLayer( QPainter* painter );
void drawHighlightLayer( QPainter* painter );
void drawSelectRegionLayer( QPainter* painter );
///////////////////////////////////// /////////////////////////////////////
// Private slots // Private methods
///////////////////////////////////// /////////////////////////////////////
private slots: private:
void onSettingsChanged(); void handleResizeMotion( const Distance& xWorld,
void onModelSizeChanged(); const 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 slots:
void onSettingsChanged();
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;
Distance mX0;
Distance mY0;
bool mMarkupVisible;
bool mGridVisible;
double mGridSpacing;
Distance mStepSize;
LabelModel* mModel;
UndoRedoModel* mUndoRedoModel;
State mState;
/* ArrowSelectRegion state */
bool mSelectRegionVisible;
Region mSelectRegion;
/* ArrowMove state */
Distance mMoveLastX;
Distance mMoveLastY;
/* ArrowResize state */
LabelModelObject* mResizeObject;
Handle* mResizeHandle;
bool mResizeHonorAspect;
/* CreateDrag state */
CreateType mCreateObjectType;
LabelModelObject* mCreateObject;
Distance mCreateX0;
Distance mCreateY0;
/////////////////////////////////////
// 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;
glabels::Distance mStepSize;
LabelModel* mModel;
UndoRedoModel* mUndoRedoModel;
State mState;
/* ArrowSelectRegion state */
bool mSelectRegionVisible;
Region 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 // LabelEditor_h #endif // LabelEditor_h
+1330 -1322
View File
File diff suppressed because it is too large Load Diff
+164 -161
View File
@@ -32,205 +32,208 @@
#include "Merge/Merge.h" #include "Merge/Merge.h"
#include "Merge/Record.h" #include "Merge/Record.h"
// Forward References
class ColorNode;
class Handle;
class LabelModelObject;
class Region;
namespace glabels
//////////////////////////////////////////////
//////////////////////////////////////////////
// LabelModel
//////////////////////////////////////////////
//////////////////////////////////////////////
class LabelModel : public QObject
{ {
Q_OBJECT
// Forward References
class ColorNode;
class Handle;
class LabelModelObject;
class Region;
///
/// LabelModel
///
class LabelModel : public QObject
{
Q_OBJECT
///////////////////////////////// /////////////////////////////////
// Lifecycle // Lifecycle
///////////////////////////////// /////////////////////////////////
public: public:
LabelModel(); LabelModel();
virtual ~LabelModel() {} virtual ~LabelModel() {}
///////////////////////////////// /////////////////////////////////
// Save/restore model state // Save/restore model state
///////////////////////////////// /////////////////////////////////
LabelModel* save() const; LabelModel* save() const;
void restore( const LabelModel *savedModel ); void restore( const LabelModel *savedModel );
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void changed(); void changed();
void nameChanged(); void nameChanged();
void sizeChanged(); void sizeChanged();
void selectionChanged(); void selectionChanged();
void modifiedChanged(); void modifiedChanged();
void mergeChanged(); void mergeChanged();
void mergeSourceChanged(); void mergeSourceChanged();
void mergeSelectionChanged(); void mergeSelectionChanged();
///////////////////////////////// /////////////////////////////////
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
bool isModified() const; bool isModified() const;
void setModified(); void setModified();
void clearModified(); void clearModified();
QString shortName(); QString shortName();
const QString& fileName() const; const QString& fileName() const;
void setFileName( const QString &fileName ); void setFileName( const QString &fileName );
int compressionLevel() const; int compressionLevel() const;
void setCompressionLevel( int compressionLevel ); void setCompressionLevel( int compressionLevel );
const glabels::Template* tmplate() const; const Template* tmplate() const;
const glabels::Frame* frame() const; const Frame* frame() const;
void setTmplate( const glabels::Template* tmplate ); void setTmplate( const Template* tmplate );
bool rotate() const; bool rotate() const;
void setRotate( bool rotate ); void setRotate( bool rotate );
glabels::Distance w() const; Distance w() const;
glabels::Distance h() const; Distance h() const;
const QList<LabelModelObject*>& objectList() const; const QList<LabelModelObject*>& objectList() const;
merge::Merge* merge() const; merge::Merge* merge() const;
void setMerge( merge::Merge* merge ); void setMerge( merge::Merge* merge );
///////////////////////////////// /////////////////////////////////
// Manage objects // Manage objects
///////////////////////////////// /////////////////////////////////
public: public:
void addObject( LabelModelObject* object ); void addObject( LabelModelObject* object );
void deleteObject( LabelModelObject* object ); void deleteObject( LabelModelObject* object );
LabelModelObject* objectAt( double scale, LabelModelObject* objectAt( double scale,
const glabels::Distance& x, const Distance& x,
const glabels::Distance& y ) const; const Distance& y ) const;
Handle* handleAt( double scale, Handle* handleAt( double scale,
const glabels::Distance& x, const Distance& x,
const glabels::Distance& y ) const; const Distance& y ) const;
///////////////////////////////// /////////////////////////////////
// Manipulate selection // Manipulate selection
///////////////////////////////// /////////////////////////////////
public: public:
void selectObject( LabelModelObject* object ); void selectObject( LabelModelObject* object );
void unselectObject( LabelModelObject* object ); void unselectObject( LabelModelObject* object );
void selectAll(); void selectAll();
void unselectAll(); void unselectAll();
void selectRegion( const Region& region ); void selectRegion( const Region& region );
bool isSelectionEmpty(); bool isSelectionEmpty();
bool isSelectionAtomic(); bool isSelectionAtomic();
///////////////////////////////// /////////////////////////////////
// Get selected objects // Get selected objects
///////////////////////////////// /////////////////////////////////
public: public:
QList<LabelModelObject*> getSelection(); QList<LabelModelObject*> getSelection();
LabelModelObject* getFirstSelectedObject(); LabelModelObject* getFirstSelectedObject();
///////////////////////////////// /////////////////////////////////
// Query selection capabilities // Query selection capabilities
///////////////////////////////// /////////////////////////////////
public: public:
bool canSelectionText(); bool canSelectionText();
bool canSelectionFill(); bool canSelectionFill();
bool canSelectionLineColor(); bool canSelectionLineColor();
bool canSelectionLineWidth(); bool canSelectionLineWidth();
///////////////////////////////// /////////////////////////////////
// Operations on selections // Operations on selections
///////////////////////////////// /////////////////////////////////
public: public:
void deleteSelection(); void deleteSelection();
void raiseSelectionToTop(); void raiseSelectionToTop();
void lowerSelectionToBottom(); void lowerSelectionToBottom();
void rotateSelection( double thetaDegs ); void rotateSelection( double thetaDegs );
void rotateSelectionLeft(); void rotateSelectionLeft();
void rotateSelectionRight(); void rotateSelectionRight();
void flipSelectionHoriz(); void flipSelectionHoriz();
void flipSelectionVert(); void flipSelectionVert();
void alignSelectionLeft(); void alignSelectionLeft();
void alignSelectionRight(); void alignSelectionRight();
void alignSelectionHCenter(); void alignSelectionHCenter();
void alignSelectionTop(); void alignSelectionTop();
void alignSelectionBottom(); void alignSelectionBottom();
void alignSelectionVCenter(); void alignSelectionVCenter();
void centerSelectionHoriz(); void centerSelectionHoriz();
void centerSelectionVert(); void centerSelectionVert();
void moveSelection( const glabels::Distance& dx, const glabels::Distance& dy ); void moveSelection( const Distance& dx, const Distance& dy );
void setSelectionFontFamily( const QString& fontFamily ); void setSelectionFontFamily( const QString& fontFamily );
void setSelectionFontSize( double fontSize ); void setSelectionFontSize( double fontSize );
void setSelectionFontWeight( QFont::Weight fontWeight ); void setSelectionFontWeight( QFont::Weight fontWeight );
void setSelectionFontItalicFlag( bool fontItalicFlag ); void setSelectionFontItalicFlag( bool fontItalicFlag );
void setSelectionTextHAlign( Qt::Alignment textHAlign ); void setSelectionTextHAlign( Qt::Alignment textHAlign );
void setSelectionTextVAlign( Qt::Alignment textVAlign ); void setSelectionTextVAlign( Qt::Alignment textVAlign );
void setSelectionTextLineSpacing( double textLineSpacing ); void setSelectionTextLineSpacing( double textLineSpacing );
void setSelectionTextColorNode( ColorNode textColorNode ); void setSelectionTextColorNode( ColorNode textColorNode );
void setSelectionLineWidth( const glabels::Distance& lineWidth ); void setSelectionLineWidth( const Distance& lineWidth );
void setSelectionLineColorNode( ColorNode lineColorNode ); void setSelectionLineColorNode( ColorNode lineColorNode );
void setSelectionFillColorNode( ColorNode fillColorNode ); void setSelectionFillColorNode( ColorNode fillColorNode );
///////////////////////////////// /////////////////////////////////
// Clipboard operations // Clipboard operations
///////////////////////////////// /////////////////////////////////
void copySelection(); void copySelection();
void cutSelection(); void cutSelection();
bool canPaste(); bool canPaste();
void paste(); void paste();
///////////////////////////////// /////////////////////////////////
// Drawing operations // Drawing operations
///////////////////////////////// /////////////////////////////////
public: public:
void draw( QPainter* painter, bool inEditor = true, merge::Record* record = 0 ) const; void draw( QPainter* painter, bool inEditor = true, merge::Record* record = 0 ) const;
///////////////////////////////// /////////////////////////////////
// Slots // Slots
///////////////////////////////// /////////////////////////////////
private slots: private slots:
void onObjectChanged(); void onObjectChanged();
void onObjectMoved(); void onObjectMoved();
void onMergeSourceChanged(); void onMergeSourceChanged();
void onMergeSelectionChanged(); void onMergeSelectionChanged();
///////////////////////////////// /////////////////////////////////
// Private data // Private data
///////////////////////////////// /////////////////////////////////
private: private:
int mUntitledInstance; int mUntitledInstance;
bool mModified; bool mModified;
QString mFileName; QString mFileName;
int mCompressionLevel; int mCompressionLevel;
const glabels::Template* mTmplate; const Template* mTmplate;
const glabels::Frame* mFrame; const Frame* mFrame;
bool mRotate; bool mRotate;
QList<LabelModelObject*> mObjectList; QList<LabelModelObject*> mObjectList;
merge::Merge* mMerge; merge::Merge* mMerge;
}; };
}
#endif // LabelModel_h #endif // LabelModel_h
+127 -115
View File
@@ -25,134 +25,146 @@
#include <QPen> #include <QPen>
namespace namespace glabels
{ {
const double slopPixels = 2;
}
//
/// // Private
/// Constructor //
/// namespace
LabelModelBoxObject::LabelModelBoxObject()
{
}
///
/// Copy constructor
///
LabelModelBoxObject::LabelModelBoxObject( const LabelModelBoxObject* object ) : LabelModelShapeObject( object )
{
}
///
/// Destructor
///
LabelModelBoxObject::~LabelModelBoxObject()
{
}
///
/// Clone
///
LabelModelBoxObject* LabelModelBoxObject::clone() const
{
return new LabelModelBoxObject( this );
}
///
/// Draw shadow of object
///
void LabelModelBoxObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record );
QColor shadowColor = mShadowColorNode.color( record );
shadowColor.setAlphaF( mShadowOpacity );
if ( fillColor.alpha() )
{ {
painter->setPen( Qt::NoPen ); const double slopPixels = 2;
painter->setBrush( shadowColor ); }
if ( lineColor.alpha() )
///
/// Constructor
///
LabelModelBoxObject::LabelModelBoxObject()
{
// empty
}
///
/// Copy constructor
///
LabelModelBoxObject::LabelModelBoxObject( const LabelModelBoxObject* object )
: LabelModelShapeObject( object )
{
// empty
}
///
/// Destructor
///
LabelModelBoxObject::~LabelModelBoxObject()
{
// empty
}
///
/// Clone
///
LabelModelBoxObject* LabelModelBoxObject::clone() const
{
return new LabelModelBoxObject( this );
}
///
/// Draw shadow of object
///
void LabelModelBoxObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record );
QColor shadowColor = mShadowColorNode.color( record );
shadowColor.setAlphaF( mShadowOpacity );
if ( fillColor.alpha() )
{ {
/* Has FILL and OUTLINE: adjust size to account for line width. */ painter->setPen( Qt::NoPen );
painter->drawRect( QRectF( -mLineWidth.pt()/2, painter->setBrush( shadowColor );
-mLineWidth.pt()/2,
(mW + mLineWidth).pt(), if ( lineColor.alpha() )
(mH + mLineWidth).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
{
/* Has FILL, but no OUTLINE. */
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
} }
else else
{ {
/* Has FILL, but no OUTLINE. */ if ( lineColor.alpha() )
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) ); {
} /* Has only OUTLINE. */
} painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
else painter->setBrush( Qt::NoBrush );
{
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() ) ); painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
} }
}
} }
/// ///
/// Draw object itself /// Draw object itself
/// ///
void LabelModelBoxObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const void LabelModelBoxObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{ {
QColor lineColor = mLineColorNode.color( record ); QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record ); QColor fillColor = mFillColorNode.color( record );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->setBrush( fillColor ); 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;
}
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;
} }
+29 -24
View File
@@ -25,37 +25,42 @@
#include "LabelModelShapeObject.h" #include "LabelModelShapeObject.h"
/// namespace glabels
/// Label Model Box Object
///
class LabelModelBoxObject : public LabelModelShapeObject
{ {
Q_OBJECT
/////////////////////////////////////////////////////////////// ///
// Lifecycle Methods /// Label Model Box Object
/////////////////////////////////////////////////////////////// ///
public: class LabelModelBoxObject : public LabelModelShapeObject
LabelModelBoxObject(); {
LabelModelBoxObject( const LabelModelBoxObject* object ); Q_OBJECT
virtual ~LabelModelBoxObject();
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelBoxObject();
LabelModelBoxObject( const LabelModelBoxObject* object );
virtual ~LabelModelBoxObject();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Object duplication // Object duplication
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
virtual LabelModelBoxObject* clone() const; virtual LabelModelBoxObject* clone() const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual QPainterPath hoverPath( double scale ) const; virtual QPainterPath hoverPath( double scale ) const;
}; };
}
#endif // LabelModelBoxObject_h #endif // LabelModelBoxObject_h
+127 -115
View File
@@ -25,134 +25,146 @@
#include <QPen> #include <QPen>
namespace namespace glabels
{ {
const double slopPixels = 2;
}
//
/// // Private
/// Constructor //
/// namespace
LabelModelEllipseObject::LabelModelEllipseObject()
{
}
///
/// Copy constructor
///
LabelModelEllipseObject::LabelModelEllipseObject( const LabelModelEllipseObject* object ) : LabelModelShapeObject( object )
{
}
///
/// Destructor
///
LabelModelEllipseObject::~LabelModelEllipseObject()
{
}
///
/// Clone
///
LabelModelEllipseObject* LabelModelEllipseObject::clone() const
{
return new LabelModelEllipseObject( this );
}
///
/// Draw shadow of object
///
void LabelModelEllipseObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record );
QColor shadowColor = mShadowColorNode.color( record );
shadowColor.setAlphaF( mShadowOpacity );
if ( fillColor.alpha() )
{ {
painter->setPen( Qt::NoPen ); const double slopPixels = 2;
painter->setBrush( shadowColor ); }
if ( lineColor.alpha() )
///
/// Constructor
///
LabelModelEllipseObject::LabelModelEllipseObject()
{
// empty
}
///
/// Copy constructor
///
LabelModelEllipseObject::LabelModelEllipseObject( const LabelModelEllipseObject* object )
: LabelModelShapeObject( object )
{
// empty
}
///
/// Destructor
///
LabelModelEllipseObject::~LabelModelEllipseObject()
{
// empty
}
///
/// Clone
///
LabelModelEllipseObject* LabelModelEllipseObject::clone() const
{
return new LabelModelEllipseObject( this );
}
///
/// Draw shadow of object
///
void LabelModelEllipseObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record );
QColor shadowColor = mShadowColorNode.color( record );
shadowColor.setAlphaF( mShadowOpacity );
if ( fillColor.alpha() )
{ {
/* Has FILL and OUTLINE: adjust size to account for line width. */ painter->setPen( Qt::NoPen );
painter->drawEllipse( QRectF( -mLineWidth.pt()/2, painter->setBrush( shadowColor );
-mLineWidth.pt()/2,
(mW + mLineWidth).pt(), if ( lineColor.alpha() )
(mH + mLineWidth).pt() ) ); {
/* Has FILL and OUTLINE: adjust size to account for line width. */
painter->drawEllipse( QRectF( -mLineWidth.pt()/2,
-mLineWidth.pt()/2,
(mW + mLineWidth).pt(),
(mH + mLineWidth).pt() ) );
}
else
{
/* Has FILL, but no OUTLINE. */
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
} }
else else
{ {
/* Has FILL, but no OUTLINE. */ if ( lineColor.alpha() )
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) ); {
} /* Has only OUTLINE. */
} painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
else painter->setBrush( Qt::NoBrush );
{
if ( lineColor.alpha() )
{
/* Has only OUTLINE. */
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
painter->setBrush( Qt::NoBrush );
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) ); painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
} }
}
} }
/// ///
/// Draw object itself /// Draw object itself
/// ///
void LabelModelEllipseObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const void LabelModelEllipseObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{ {
QColor lineColor = mLineColorNode.color( record ); QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record ); QColor fillColor = mFillColorNode.color( record );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->setBrush( fillColor ); painter->setBrush( fillColor );
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
///
/// Path to test for hover condition
///
QPainterPath LabelModelEllipseObject::hoverPath( double scale ) const
{
double s = 1 / scale;
QPainterPath path;
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
{
path.addEllipse( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
}
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
{
path.addEllipse( 0, 0, mW.pt(), mH.pt() );
}
else if ( mLineColorNode.color().alpha() )
{
path.addEllipse( (-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.addEllipse( mLineWidth.pt()/2 + s*slopPixels,
mLineWidth.pt()/2 + s*slopPixels,
(mW - mLineWidth).pt() - s*2*slopPixels,
(mH - mLineWidth).pt() - s*2*slopPixels );
}
return path;
}
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
///
/// Path to test for hover condition
///
QPainterPath LabelModelEllipseObject::hoverPath( double scale ) const
{
double s = 1 / scale;
QPainterPath path;
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
{
path.addEllipse( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
}
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
{
path.addEllipse( 0, 0, mW.pt(), mH.pt() );
}
else if ( mLineColorNode.color().alpha() )
{
path.addEllipse( (-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.addEllipse( mLineWidth.pt()/2 + s*slopPixels,
mLineWidth.pt()/2 + s*slopPixels,
(mW - mLineWidth).pt() - s*2*slopPixels,
(mH - mLineWidth).pt() - s*2*slopPixels );
}
return path;
} }
+29 -24
View File
@@ -25,37 +25,42 @@
#include "LabelModelShapeObject.h" #include "LabelModelShapeObject.h"
/// namespace glabels
/// Label Model Ellipse Object
///
class LabelModelEllipseObject : public LabelModelShapeObject
{ {
Q_OBJECT
/////////////////////////////////////////////////////////////// ///
// Lifecycle Methods /// Label Model Ellipse Object
/////////////////////////////////////////////////////////////// ///
public: class LabelModelEllipseObject : public LabelModelShapeObject
LabelModelEllipseObject(); {
LabelModelEllipseObject( const LabelModelEllipseObject* object ); Q_OBJECT
virtual ~LabelModelEllipseObject();
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelEllipseObject();
LabelModelEllipseObject( const LabelModelEllipseObject* object );
virtual ~LabelModelEllipseObject();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Object duplication // Object duplication
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
virtual LabelModelEllipseObject* clone() const; virtual LabelModelEllipseObject* clone() const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual QPainterPath hoverPath( double scale ) const; virtual QPainterPath hoverPath( double scale ) const;
}; };
}
#endif // LabelModelEllipseObject_h #endif // LabelModelEllipseObject_h
+246 -246
View File
@@ -30,287 +30,287 @@
#include "Size.h" #include "Size.h"
namespace namespace glabels
{ {
}
///
/// Static data
///
QImage* LabelModelImageObject::smDefaultImage = 0;
/// ///
/// Static data /// Constructor
/// ///
QImage* LabelModelImageObject::smDefaultImage = 0; LabelModelImageObject::LabelModelImageObject() : mImage(0), mSvg(0)
///
/// Constructor
///
LabelModelImageObject::LabelModelImageObject() : mImage(0), mSvg(0)
{
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 );
if ( smDefaultImage == 0 )
{ {
smDefaultImage = new QImage( ":images/checkerboard.png" ); 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 );
/// if ( smDefaultImage == 0 )
/// Copy constructor
///
LabelModelImageObject::LabelModelImageObject( const LabelModelImageObject* object ) : LabelModelObject(object)
{
mFilenameNode = object->mFilenameNode;
}
///
/// Destructor
///
LabelModelImageObject::~LabelModelImageObject()
{
delete mOutline;
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
}
///
/// Clone
///
LabelModelImageObject* LabelModelImageObject::clone() const
{
return new LabelModelImageObject( this );
}
///
/// Image filenameNode Property Getter
///
TextNode LabelModelImageObject::filenameNode( void ) const
{
return mFilenameNode;
}
///
/// Image filenameNode Property Setter
///
void LabelModelImageObject::setFilenameNode( const TextNode& value )
{
if ( mFilenameNode != value )
{
mFilenameNode = value;
loadImage();
emit changed();
}
}
///
/// Image originalSize Property Getter (assumes 72 DPI, i.e. 1pixel == 1pt)
///
Size LabelModelImageObject::originalSize() const
{
Size size( glabels::Distance::pt(72), glabels::Distance::pt(72) );
if ( mImage )
{
QSize qsize = mImage->size();
size.setW( glabels::Distance::pt( qsize.width() ) );
size.setH( glabels::Distance::pt( qsize.height() ) );
}
else if ( mSvg )
{
QSize qsize = mSvg->defaultSize();
size.setW( glabels::Distance::pt( qsize.width() ) );
size.setH( glabels::Distance::pt( qsize.height() ) );
}
return size;
}
///
/// Draw shadow of object
///
void LabelModelImageObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
QColor shadowColor = mShadowColorNode.color( record );
shadowColor.setAlphaF( mShadowOpacity );
if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) )
{
QImage* shadowImage = createShadowImage( shadowColor );
painter->drawImage( destRect, *shadowImage );
delete shadowImage;
}
else
{
if ( mImage || inEditor )
{ {
painter->setBrush( shadowColor ); smDefaultImage = new QImage( ":images/checkerboard.png" );
painter->setPen( QPen( Qt::NoPen ) );
painter->drawRect( destRect );
} }
} }
}
///
/// Draw object itself
///
void LabelModelImageObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
if ( inEditor && (mFilenameNode.isField() || (!mImage && !mSvg) ) )
{
painter->save();
painter->setRenderHint( QPainter::SmoothPixmapTransform, false );
painter->drawImage( destRect, *smDefaultImage );
painter->restore();
}
else if ( mImage )
{
painter->drawImage( destRect, *mImage );
}
else if ( mSvg )
{
mSvg->render( painter, destRect );
}
else if ( mFilenameNode.isField() )
{
// TODO
}
}
/// ///
/// Path to test for hover condition /// Copy constructor
/// ///
QPainterPath LabelModelImageObject::hoverPath( double scale ) const LabelModelImageObject::LabelModelImageObject( const LabelModelImageObject* object ) : LabelModelObject(object)
{
QPainterPath path;
path.addRect( 0, 0, mW.pt(), mH.pt() );
return path;
}
///
/// Load image
///
void LabelModelImageObject::loadImage()
{
if ( mImage )
{ {
delete mImage; mFilenameNode = object->mFilenameNode;
}
if ( mSvg )
{
delete mSvg;
} }
if ( mFilenameNode.isField() )
{
mImage = 0;
mSvg = 0;
}
else
{
QString filename = mFilenameNode.data();
QFileInfo fileInfo( filename );
if ( fileInfo.isReadable() ) ///
/// Destructor
///
LabelModelImageObject::~LabelModelImageObject()
{
delete mOutline;
foreach( Handle* handle, mHandles )
{ {
if ( (fileInfo.suffix() == "svg") || (fileInfo.suffix() == "SVG") ) delete handle;
}
mHandles.clear();
}
///
/// Clone
///
LabelModelImageObject* LabelModelImageObject::clone() const
{
return new LabelModelImageObject( this );
}
///
/// Image filenameNode Property Getter
///
TextNode LabelModelImageObject::filenameNode( void ) const
{
return mFilenameNode;
}
///
/// Image filenameNode Property Setter
///
void LabelModelImageObject::setFilenameNode( const TextNode& value )
{
if ( mFilenameNode != value )
{
mFilenameNode = value;
loadImage();
emit changed();
}
}
///
/// Image originalSize Property Getter (assumes 72 DPI, i.e. 1pixel == 1pt)
///
Size LabelModelImageObject::originalSize() const
{
Size size( Distance::pt(72), Distance::pt(72) );
if ( mImage )
{
QSize qsize = mImage->size();
size.setW( Distance::pt( qsize.width() ) );
size.setH( Distance::pt( qsize.height() ) );
}
else if ( mSvg )
{
QSize qsize = mSvg->defaultSize();
size.setW( Distance::pt( qsize.width() ) );
size.setH( Distance::pt( qsize.height() ) );
}
return size;
}
///
/// Draw shadow of object
///
void LabelModelImageObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
QColor shadowColor = mShadowColorNode.color( record );
shadowColor.setAlphaF( mShadowOpacity );
if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) )
{
QImage* shadowImage = createShadowImage( shadowColor );
painter->drawImage( destRect, *shadowImage );
delete shadowImage;
}
else
{
if ( mImage || inEditor )
{ {
mSvg = new QSvgRenderer( filename ); painter->setBrush( shadowColor );
if ( !mSvg->isValid() ) painter->setPen( QPen( Qt::NoPen ) );
{
mSvg = 0; painter->drawRect( destRect );
}
else
{
// Adjust size based on aspect ratio of SVG image
QRectF rect = mSvg->viewBoxF();
double aspectRatio = rect.height() / rect.width();
if ( mH > mW*aspectRatio )
{
mH = mW*aspectRatio;
}
else
{
mW = mH/aspectRatio;
}
}
} }
else }
}
///
/// Draw object itself
///
void LabelModelImageObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
if ( inEditor && (mFilenameNode.isField() || (!mImage && !mSvg) ) )
{
painter->save();
painter->setRenderHint( QPainter::SmoothPixmapTransform, false );
painter->drawImage( destRect, *smDefaultImage );
painter->restore();
}
else if ( mImage )
{
painter->drawImage( destRect, *mImage );
}
else if ( mSvg )
{
mSvg->render( painter, destRect );
}
else if ( mFilenameNode.isField() )
{
// TODO
}
}
///
/// Path to test for hover condition
///
QPainterPath LabelModelImageObject::hoverPath( double scale ) const
{
QPainterPath path;
path.addRect( 0, 0, mW.pt(), mH.pt() );
return path;
}
///
/// Load image
///
void LabelModelImageObject::loadImage()
{
if ( mImage )
{
delete mImage;
}
if ( mSvg )
{
delete mSvg;
}
if ( mFilenameNode.isField() )
{
mImage = 0;
mSvg = 0;
}
else
{
QString filename = mFilenameNode.data();
QFileInfo fileInfo( filename );
if ( fileInfo.isReadable() )
{ {
mImage = new QImage( filename ); if ( (fileInfo.suffix() == "svg") || (fileInfo.suffix() == "SVG") )
if ( mImage->isNull() )
{ {
mImage = 0; mSvg = new QSvgRenderer( filename );
} if ( !mSvg->isValid() )
else
{
// Adjust size based on aspect ratio of image
double imageW = mImage->width();
double imageH = mImage->height();
double aspectRatio = imageH / imageW;
if ( mH > mW*aspectRatio )
{ {
mH = mW*aspectRatio; mSvg = 0;
} }
else else
{ {
mW = mH/aspectRatio; // Adjust size based on aspect ratio of SVG image
QRectF rect = mSvg->viewBoxF();
double aspectRatio = rect.height() / rect.width();
if ( mH > mW*aspectRatio )
{
mH = mW*aspectRatio;
}
else
{
mW = mH/aspectRatio;
}
}
}
else
{
mImage = new QImage( filename );
if ( mImage->isNull() )
{
mImage = 0;
}
else
{
// Adjust size based on aspect ratio of image
double imageW = mImage->width();
double imageH = mImage->height();
double aspectRatio = imageH / imageW;
if ( mH > mW*aspectRatio )
{
mH = mW*aspectRatio;
}
else
{
mW = mH/aspectRatio;
}
} }
} }
} }
} }
} }
}
/// ///
/// Create shadow image /// Create shadow image
/// ///
QImage* LabelModelImageObject::createShadowImage( const QColor& color ) const QImage* LabelModelImageObject::createShadowImage( const QColor& color ) const
{
int r = color.red();
int g = color.green();
int b = color.blue();
int a = color.alpha();
QImage* shadow = new QImage( *mImage );
for ( int iy = 0; iy < shadow->height(); iy++ )
{ {
QRgb* scanLine = (QRgb*)shadow->scanLine( iy ); int r = color.red();
int g = color.green();
int b = color.blue();
int a = color.alpha();
for ( int ix = 0; ix < shadow->width(); ix++ ) QImage* shadow = new QImage( *mImage );
for ( int iy = 0; iy < shadow->height(); iy++ )
{ {
scanLine[ix] = qRgba( r, g, b, (a*qAlpha(scanLine[ix]))/255 ); QRgb* scanLine = (QRgb*)shadow->scanLine( iy );
for ( int ix = 0; ix < shadow->width(); ix++ )
{
scanLine[ix] = qRgba( r, g, b, (a*qAlpha(scanLine[ix]))/255 );
}
} }
return shadow;
} }
return shadow;
} }
+58 -53
View File
@@ -27,76 +27,81 @@
#include "LabelModelObject.h" #include "LabelModelObject.h"
/// namespace glabels
/// Label Model Image Object
///
class LabelModelImageObject : public LabelModelObject
{ {
Q_OBJECT
/////////////////////////////////////////////////////////////// ///
// Lifecycle Methods /// Label Model Image Object
/////////////////////////////////////////////////////////////// ///
public: class LabelModelImageObject : public LabelModelObject
LabelModelImageObject(); {
LabelModelImageObject( const LabelModelImageObject* object ); Q_OBJECT
virtual ~LabelModelImageObject();
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelImageObject();
LabelModelImageObject( const LabelModelImageObject* object );
virtual ~LabelModelImageObject();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Object duplication // Object duplication
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
virtual LabelModelImageObject* clone() const; virtual LabelModelImageObject* clone() const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Property Implementations // Property Implementations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// Image Property: filenameNode // Image Property: filenameNode
// //
virtual TextNode filenameNode( void ) const; virtual TextNode filenameNode( void ) const;
virtual void setFilenameNode( const TextNode& value ); virtual void setFilenameNode( const TextNode& value );
// //
// Image Property: originalSize // Image Property: originalSize
// //
virtual Size originalSize() const; virtual Size originalSize() const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Capability Implementations // Capability Implementations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual QPainterPath hoverPath( double scale ) const; virtual QPainterPath hoverPath( double scale ) const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Private // Private
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
void loadImage(); void loadImage();
QImage* createShadowImage( const QColor& color ) const; QImage* createShadowImage( const QColor& color ) const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Private Members // Private Members
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
TextNode mFilenameNode; TextNode mFilenameNode;
QImage* mImage; QImage* mImage;
QSvgRenderer* mSvg; QSvgRenderer* mSvg;
static QImage* smDefaultImage; static QImage* smDefaultImage;
}; };
}
#endif // LabelModelImageObject_h #endif // LabelModelImageObject_h
+156 -147
View File
@@ -25,176 +25,185 @@
#include <QPen> #include <QPen>
namespace namespace glabels
{ {
const double slopPixels = 2;
}
//
/// // Private
/// Constructor //
/// namespace
LabelModelLineObject::LabelModelLineObject()
{
mOutline = 0;
mHandles << new HandleP1( this );
mHandles << new HandleP2( this );
mLineWidth = 1.0;
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
}
///
/// Copy constructor
///
LabelModelLineObject::LabelModelLineObject( const LabelModelLineObject* object ) : LabelModelObject(object)
{
mLineWidth = object->mLineWidth;
mLineColorNode = object->mLineColorNode;
}
///
/// Destructor
///
LabelModelLineObject::~LabelModelLineObject()
{
foreach( Handle* handle, mHandles )
{ {
delete handle; const double slopPixels = 2;
} }
mHandles.clear();
}
/// ///
/// Clone /// Constructor
/// ///
LabelModelLineObject* LabelModelLineObject::clone() const LabelModelLineObject::LabelModelLineObject()
{
return new LabelModelLineObject( this );
}
///
/// Line Width Property Getter
///
glabels::Distance LabelModelLineObject::lineWidth( void ) const
{
return mLineWidth;
}
///
/// Line Width Property Setter
///
void LabelModelLineObject::setLineWidth( const glabels::Distance& value )
{
if ( mLineWidth != value )
{ {
mLineWidth = value; mOutline = 0;
emit changed();
mHandles << new HandleP1( this );
mHandles << new HandleP2( this );
mLineWidth = 1.0;
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
} }
}
/// ///
/// Line Color Node Property Getter /// Copy constructor
/// ///
ColorNode LabelModelLineObject::lineColorNode( void ) const LabelModelLineObject::LabelModelLineObject( const LabelModelLineObject* object )
{ : LabelModelObject(object)
return mLineColorNode;
}
///
/// Line Color Node Property Setter
///
void LabelModelLineObject::setLineColorNode( const ColorNode& value )
{
if ( mLineColorNode != value )
{ {
mLineColorNode = value; mLineWidth = object->mLineWidth;
emit changed(); mLineColorNode = object->mLineColorNode;
}
///
/// Destructor
///
LabelModelLineObject::~LabelModelLineObject()
{
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
}
///
/// Clone
///
LabelModelLineObject* LabelModelLineObject::clone() const
{
return new LabelModelLineObject( this );
}
///
/// Line Width Property Getter
///
Distance LabelModelLineObject::lineWidth( void ) const
{
return mLineWidth;
}
///
/// Line Width Property Setter
///
void LabelModelLineObject::setLineWidth( const Distance& value )
{
if ( mLineWidth != value )
{
mLineWidth = value;
emit changed();
}
}
///
/// Line Color Node Property Getter
///
ColorNode LabelModelLineObject::lineColorNode( void ) const
{
return mLineColorNode;
}
///
/// Line Color Node Property Setter
///
void LabelModelLineObject::setLineColorNode( const ColorNode& value )
{
if ( mLineColorNode != value )
{
mLineColorNode = value;
emit changed();
}
} }
}
/// ///
/// Can Line Color Capability Implementation /// Can Line Color Capability Implementation
/// ///
bool LabelModelLineObject::canLineColor() bool LabelModelLineObject::canLineColor()
{
return true;
}
///
/// Can Line Width Capability Implementation
///
bool LabelModelLineObject::canLineWidth()
{
return true;
}
///
/// Draw shadow of object
///
void LabelModelLineObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor shadowColor = mShadowColorNode.color( record );
shadowColor.setAlphaF( mShadowOpacity );
if ( lineColor.alpha() )
{ {
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) ); return true;
}
///
/// Can Line Width Capability Implementation
///
bool LabelModelLineObject::canLineWidth()
{
return true;
}
///
/// Draw shadow of object
///
void LabelModelLineObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor shadowColor = mShadowColorNode.color( record );
shadowColor.setAlphaF( mShadowOpacity );
if ( lineColor.alpha() )
{
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
painter->drawLine( 0, 0, mW.pt(), mH.pt() );
}
}
///
/// Draw object itself
///
void LabelModelLineObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->drawLine( 0, 0, mW.pt(), mH.pt() ); painter->drawLine( 0, 0, mW.pt(), mH.pt() );
} }
}
///
/// Draw object itself
///
void LabelModelLineObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->drawLine( 0, 0, mW.pt(), mH.pt() );
}
/// ///
/// Path to test for hover condition /// Path to test for hover condition
/// ///
QPainterPath LabelModelLineObject::hoverPath( double scale ) const QPainterPath LabelModelLineObject::hoverPath( double scale ) const
{
QPainterPath path;
if ( mLineColorNode.color().alpha() )
{ {
// QPainterPath path;
// Build a thin rectangle representing line
//
double rPts = mLineWidth.pt()/2 + slopPixels / scale;
double lengthPts = sqrt( mW.pt()*mW.pt() + mH.pt()*mH.pt() ); if ( mLineColorNode.color().alpha() )
double dx = mH.pt() / lengthPts; // horizontal pitch of perpendicular line {
double dy = mW.pt() / lengthPts; // vertical pitch of perpendicular line //
// Build a thin rectangle representing line
//
double rPts = mLineWidth.pt()/2 + slopPixels / scale;
double lengthPts = sqrt( mW.pt()*mW.pt() + mH.pt()*mH.pt() );
double dx = mH.pt() / lengthPts; // horizontal pitch of perpendicular line
double dy = mW.pt() / lengthPts; // vertical pitch of perpendicular line
path.moveTo( rPts*dx, - rPts*dy ); path.moveTo( rPts*dx, - rPts*dy );
path.lineTo( mW.pt() + rPts*dx, mH.pt() - rPts*dy ); path.lineTo( mW.pt() + rPts*dx, mH.pt() - rPts*dy );
path.lineTo( mW.pt() - rPts*dx, mH.pt() + rPts*dy ); path.lineTo( mW.pt() - rPts*dx, mH.pt() + rPts*dy );
path.lineTo( - rPts*dx, rPts*dy ); path.lineTo( - rPts*dx, rPts*dy );
path.closeSubpath(); path.closeSubpath();
}
return path;
} }
return path;
} }
+55 -50
View File
@@ -25,71 +25,76 @@
#include "LabelModelObject.h" #include "LabelModelObject.h"
/// namespace glabels
/// Label Model Line Object
///
class LabelModelLineObject : public LabelModelObject
{ {
Q_OBJECT
/////////////////////////////////////////////////////////////// ///
// Lifecycle Methods /// Label Model Line Object
/////////////////////////////////////////////////////////////// ///
public: class LabelModelLineObject : public LabelModelObject
LabelModelLineObject(); {
LabelModelLineObject( const LabelModelLineObject* object ); Q_OBJECT
virtual ~LabelModelLineObject();
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelLineObject();
LabelModelLineObject( const LabelModelLineObject* object );
virtual ~LabelModelLineObject();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Object duplication // Object duplication
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
virtual LabelModelLineObject* clone() const; virtual LabelModelLineObject* clone() const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Property Implementations // Property Implementations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// Line Property: lineWidth // Line Property: lineWidth
// //
virtual glabels::Distance lineWidth( void ) const; virtual Distance lineWidth( void ) const;
virtual void setLineWidth( const glabels::Distance& value ); virtual void setLineWidth( const Distance& value );
// //
// Line Property: lineColorNode // Line Property: lineColorNode
// //
virtual ColorNode lineColorNode( void ) const; virtual ColorNode lineColorNode( void ) const;
virtual void setLineColorNode( const ColorNode& value ); virtual void setLineColorNode( const ColorNode& value );
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Capability Implementations // Capability Implementations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
virtual bool canLineColor(); virtual bool canLineColor();
virtual bool canLineWidth(); virtual bool canLineWidth();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual QPainterPath hoverPath( double scale ) const; virtual QPainterPath hoverPath( double scale ) const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Private Members // Private Members
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
glabels::Distance mLineWidth; Distance mLineWidth;
ColorNode mLineColorNode; ColorNode mLineColorNode;
}; };
}
#endif // LabelModelLineObject_h #endif // LabelModelLineObject_h
+1030 -1005
View File
File diff suppressed because it is too large Load Diff
+278 -273
View File
@@ -37,366 +37,371 @@
#include "Merge/Record.h" #include "Merge/Record.h"
// Forward References namespace glabels
class Region;
class Size;
///
/// Label Model Object Base Class
///
class LabelModelObject : public QObject
{ {
Q_OBJECT
/////////////////////////////////////////////////////////////// // Forward References
// Lifecycle Methods class Region;
/////////////////////////////////////////////////////////////// class Size;
protected:
LabelModelObject();
LabelModelObject( const LabelModelObject* object );
public:
virtual ~LabelModelObject();
/////////////////////////////////////////////////////////////// ///
// Object duplication /// Label Model Object Base Class
/////////////////////////////////////////////////////////////// ///
virtual LabelModelObject* clone() const = 0; class LabelModelObject : public QObject
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
protected:
LabelModelObject();
LabelModelObject( const LabelModelObject* object );
public:
virtual ~LabelModelObject();
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelObject* clone() const = 0;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Signals // Signals
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
signals: signals:
void moved(); void moved();
void changed(); void changed();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Common Properties // Common Properties
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// ID Property. // ID Property.
// //
int id() const; int id() const;
// //
// Selected Property. // Selected Property.
// //
bool isSelected() const; bool isSelected() const;
void select( bool value = true ); void select( bool value = true );
void unselect(); void unselect();
// //
// x0 Property ( x coordinate of origin ) // x0 Property ( x coordinate of origin )
// //
glabels::Distance x0() const; Distance x0() const;
void setX0( const glabels::Distance& value ); void setX0( const Distance& value );
// //
// y0 Property ( y coordinate of origin ) // y0 Property ( y coordinate of origin )
// //
glabels::Distance y0() const; Distance y0() const;
void setY0( const glabels::Distance& value ); void setY0( const Distance& value );
// //
// w Property ( width of bounding box ) // w Property ( width of bounding box )
// //
glabels::Distance w() const; Distance w() const;
void setW( const glabels::Distance& value ); void setW( const Distance& value );
// //
// h Property ( height of bounding box ) // h Property ( height of bounding box )
// //
glabels::Distance h() const; Distance h() const;
void setH( const glabels::Distance& value ); void setH( const Distance& value );
// //
// Transformation Matrix Property // Transformation Matrix Property
// //
QMatrix matrix() const; QMatrix matrix() const;
void setMatrix( const QMatrix& value ); void setMatrix( const QMatrix& value );
// //
// Shadow State Property // Shadow State Property
// //
bool shadow() const; bool shadow() const;
void setShadow( bool value ); void setShadow( bool value );
// //
// Shadow x Offset Property // Shadow x Offset Property
// //
glabels::Distance shadowX() const; Distance shadowX() const;
void setShadowX( const glabels::Distance& value ); void setShadowX( const Distance& value );
// //
// Shadow y Offset Property // Shadow y Offset Property
// //
glabels::Distance shadowY() const; Distance shadowY() const;
void setShadowY( const glabels::Distance& value ); void setShadowY( const Distance& value );
// //
// Shadow opacity Property // Shadow opacity Property
// //
double shadowOpacity() const; double shadowOpacity() const;
void setShadowOpacity( double value ); void setShadowOpacity( double value );
// //
// Shadow Color Property // Shadow Color Property
// //
ColorNode shadowColorNode() const; ColorNode shadowColorNode() const;
void setShadowColorNode( const ColorNode& value ); void setShadowColorNode( const ColorNode& value );
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Text Properties Virtual Interface // Text Properties Virtual Interface
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// Virtual Text Property: text // Virtual Text Property: text
// //
virtual QString text() const; virtual QString text() const;
virtual void setText( const QString &value ); virtual void setText( const QString &value );
// //
// Virtual Text Property: fontFamily // Virtual Text Property: fontFamily
// //
virtual QString fontFamily() const; virtual QString fontFamily() const;
virtual void setFontFamily( const QString &value ); virtual void setFontFamily( const QString &value );
// //
// Virtual Text Property: fontSize // Virtual Text Property: fontSize
// //
virtual double fontSize() const; virtual double fontSize() const;
virtual void setFontSize( double value ); virtual void setFontSize( double value );
// //
// Virtual Text Property: fontWeight // Virtual Text Property: fontWeight
// //
virtual QFont::Weight fontWeight() const; virtual QFont::Weight fontWeight() const;
virtual void setFontWeight( QFont::Weight value ); virtual void setFontWeight( QFont::Weight value );
// //
// Virtual Text Property: fontItalicFlag // Virtual Text Property: fontItalicFlag
// //
virtual bool fontItalicFlag() const; virtual bool fontItalicFlag() const;
virtual void setFontItalicFlag( bool value ); virtual void setFontItalicFlag( bool value );
// //
// Virtual Text Property: fontUnderlineFlag // Virtual Text Property: fontUnderlineFlag
// //
virtual bool fontUnderlineFlag() const; virtual bool fontUnderlineFlag() const;
virtual void setFontUnderlineFlag( bool value ); virtual void setFontUnderlineFlag( bool value );
// //
// Virtual Text Property: textColorNode // Virtual Text Property: textColorNode
// //
virtual ColorNode textColorNode() const; virtual ColorNode textColorNode() const;
virtual void setTextColorNode( const ColorNode &value ); virtual void setTextColorNode( const ColorNode &value );
// //
// Virtual Text Property: textHAlign // Virtual Text Property: textHAlign
// //
virtual Qt::Alignment textHAlign() const; virtual Qt::Alignment textHAlign() const;
virtual void setTextHAlign( Qt::Alignment value ); virtual void setTextHAlign( Qt::Alignment value );
// //
// Virtual Text Property: textVAlign // Virtual Text Property: textVAlign
// //
virtual Qt::Alignment textVAlign() const; virtual Qt::Alignment textVAlign() const;
virtual void setTextVAlign( Qt::Alignment value ); virtual void setTextVAlign( Qt::Alignment value );
// //
// Virtual Text Property: textLineSpacing // Virtual Text Property: textLineSpacing
// //
virtual double textLineSpacing() const; virtual double textLineSpacing() const;
virtual void setTextLineSpacing( double value ); virtual void setTextLineSpacing( double value );
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Image Properties Virtual Interface // Image Properties Virtual Interface
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// Virtual Image Property: filenameNode // Virtual Image Property: filenameNode
// //
virtual TextNode filenameNode() const; virtual TextNode filenameNode() const;
virtual void setFilenameNode( const TextNode &value ); virtual void setFilenameNode( const TextNode &value );
// //
// Virtual Image Property: originalSize (read-only) // Virtual Image Property: originalSize (read-only)
// //
virtual Size originalSize() const; virtual Size originalSize() const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Shape Properties Virtual Interface // Shape Properties Virtual Interface
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// Virtual Shape Property: lineWidth // Virtual Shape Property: lineWidth
// //
virtual glabels::Distance lineWidth() const; virtual Distance lineWidth() const;
virtual void setLineWidth( const glabels::Distance& value ); virtual void setLineWidth( const Distance& value );
// //
// Virtual Shape Property: lineColorNode // Virtual Shape Property: lineColorNode
// //
virtual ColorNode lineColorNode() const; virtual ColorNode lineColorNode() const;
virtual void setLineColorNode( const ColorNode &value ); virtual void setLineColorNode( const ColorNode &value );
// //
// Virtual Shape Property: fillColorNode // Virtual Shape Property: fillColorNode
// //
virtual ColorNode fillColorNode() const; virtual ColorNode fillColorNode() const;
virtual void setFillColorNode( const ColorNode &value ); virtual void setFillColorNode( const ColorNode &value );
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Barcode Properties Virtual Interface // Barcode Properties Virtual Interface
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// Virtual Barcode Property: bcDataNode // Virtual Barcode Property: bcDataNode
// //
virtual TextNode bcDataNode() const; virtual TextNode bcDataNode() const;
virtual void setBcDataNode( const TextNode &value ); virtual void setBcDataNode( const TextNode &value );
// //
// Virtual Barcode Property: bcTextFlag // Virtual Barcode Property: bcTextFlag
// //
virtual bool bcTextFlag() const; virtual bool bcTextFlag() const;
virtual void setBcTextFlag( bool value ); virtual void setBcTextFlag( bool value );
// //
// Virtual Barcode Property: bcChecksumFlag // Virtual Barcode Property: bcChecksumFlag
// //
virtual bool bcChecksumFlag() const; virtual bool bcChecksumFlag() const;
virtual void setBcChecksumFlag( bool value ); virtual void setBcChecksumFlag( bool value );
// //
// Virtual Barcode Property: bcColorNode // Virtual Barcode Property: bcColorNode
// //
virtual ColorNode bcColorNode() const; virtual ColorNode bcColorNode() const;
virtual void setBcColorNode( const ColorNode &value ); virtual void setBcColorNode( const ColorNode &value );
// //
// Virtual Barcode Property: bcStyle // Virtual Barcode Property: bcStyle
// //
virtual BarcodeStyle bcStyle() const; virtual BarcodeStyle bcStyle() const;
virtual void setBcStyle( const BarcodeStyle &value ); virtual void setBcStyle( const BarcodeStyle &value );
// //
// Virtual Barcode Property: bcFormatDigits // Virtual Barcode Property: bcFormatDigits
// //
virtual int bcFormatDigits() const; virtual int bcFormatDigits() const;
virtual void setBcFormatDigits( int value ); virtual void setBcFormatDigits( int value );
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Capabilities (Overridden by concrete classes.) // Capabilities (Overridden by concrete classes.)
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
virtual bool canText() const; virtual bool canText() const;
virtual bool canFill() const; virtual bool canFill() const;
virtual bool canLineColor() const; virtual bool canLineColor() const;
virtual bool canLineWidth() const; virtual bool canLineWidth() const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Position and Size methods // Position and Size methods
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
void setPosition( const glabels::Distance& x0, const glabels::Distance& y0 ); void setPosition( const Distance& x0, const Distance& y0 );
void setPositionRelative( const glabels::Distance& dx, const glabels::Distance& dy ); void setPositionRelative( const Distance& dx, const Distance& dy );
Size size() const; Size size() const;
void setSize( const glabels::Distance& w, const glabels::Distance& h ); void setSize( const Distance& w, const Distance& h );
void setSize( const Size& size ); void setSize( const Size& size );
void setSizeHonorAspect( const glabels::Distance& w, const glabels::Distance& h ); void setSizeHonorAspect( const Distance& w, const Distance& h );
void setWHonorAspect( const glabels::Distance& w ); void setWHonorAspect( const Distance& w );
void setHHonorAspect( const glabels::Distance& h ); void setHHonorAspect( const Distance& h );
Region getExtent(); Region getExtent();
void rotate( double thetaDegs ); void rotate( double thetaDegs );
void flipHoriz(); void flipHoriz();
void flipVert(); void flipVert();
bool isLocatedAt( double scale, const glabels::Distance& x, const glabels::Distance& y ) const; bool isLocatedAt( double scale, const Distance& x, const Distance& y ) const;
Handle* handleAt( double scale, const glabels::Distance& x, const glabels::Distance& y ) const; Handle* handleAt( double scale, const Distance& x, const Distance& y ) const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
void draw( QPainter* painter, bool inEditor, merge::Record* record ) const; void draw( QPainter* painter, bool inEditor, merge::Record* record ) const;
void drawSelectionHighlight( QPainter* painter, double scale ) const; void drawSelectionHighlight( QPainter* painter, double scale ) const;
protected: protected:
virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const = 0; virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const = 0;
virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const = 0; virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const = 0;
virtual QPainterPath hoverPath( double scale ) const = 0; virtual QPainterPath hoverPath( double scale ) const = 0;
virtual void sizeUpdated(); virtual void sizeUpdated();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Protected Members // Protected Members
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
bool mSelectedFlag; bool mSelectedFlag;
glabels::Distance mX0; Distance mX0;
glabels::Distance mY0; Distance mY0;
glabels::Distance mW; Distance mW;
glabels::Distance mH; Distance mH;
bool mShadowState; bool mShadowState;
glabels::Distance mShadowX; Distance mShadowX;
glabels::Distance mShadowY; Distance mShadowY;
double mShadowOpacity; double mShadowOpacity;
ColorNode mShadowColorNode; ColorNode mShadowColorNode;
QList<Handle*> mHandles; QList<Handle*> mHandles;
Outline* mOutline; Outline* mOutline;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Private Members // Private Members
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
private: private:
static int msNextId; static int msNextId;
int mId; int mId;
QMatrix mMatrix; QMatrix mMatrix;
}; };
}
#endif // LabelModelObject_h #endif // LabelModelObject_h
+125 -120
View File
@@ -25,142 +25,147 @@
#include <QPen> #include <QPen>
/// namespace glabels
/// Constructor
///
LabelModelShapeObject::LabelModelShapeObject()
{ {
mOutline = new Outline( this );
mHandles << new HandleNorthWest( this ); ///
mHandles << new HandleNorth( this ); /// Constructor
mHandles << new HandleNorthEast( this ); ///
mHandles << new HandleEast( this ); LabelModelShapeObject::LabelModelShapeObject()
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 ) );
}
///
/// Copy constructor
///
LabelModelShapeObject::LabelModelShapeObject( const LabelModelShapeObject* object ) : LabelModelObject(object)
{
mLineWidth = object->mLineWidth;
mLineColorNode = object->mLineColorNode;
mFillColorNode = object->mFillColorNode;
}
///
/// Destructor
///
LabelModelShapeObject::~LabelModelShapeObject()
{
delete mOutline;
foreach( Handle* handle, mHandles )
{ {
delete handle; 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 ) );
} }
mHandles.clear();
}
/// ///
/// Line Width Property Getter /// Copy constructor
/// ///
glabels::Distance LabelModelShapeObject::lineWidth( void ) const LabelModelShapeObject::LabelModelShapeObject( const LabelModelShapeObject* object ) : LabelModelObject(object)
{
return mLineWidth;
}
///
/// Line Width Property Setter
///
void LabelModelShapeObject::setLineWidth( const glabels::Distance& value )
{
if ( mLineWidth != value )
{ {
mLineWidth = value; mLineWidth = object->mLineWidth;
emit changed(); mLineColorNode = object->mLineColorNode;
mFillColorNode = object->mFillColorNode;
} }
}
/// ///
/// Line Color Node Property Getter /// Destructor
/// ///
ColorNode LabelModelShapeObject::lineColorNode( void ) const LabelModelShapeObject::~LabelModelShapeObject()
{
return mLineColorNode;
}
///
/// Line Color Node Property Setter
///
void LabelModelShapeObject::setLineColorNode( const ColorNode& value )
{
if ( mLineColorNode != value )
{ {
mLineColorNode = value; delete mOutline;
emit changed();
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
}
///
/// Line Width Property Getter
///
Distance LabelModelShapeObject::lineWidth( void ) const
{
return mLineWidth;
}
///
/// Line Width Property Setter
///
void LabelModelShapeObject::setLineWidth( const 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 /// Fill Color Node Property Getter
/// ///
ColorNode LabelModelShapeObject::fillColorNode( void ) const ColorNode LabelModelShapeObject::fillColorNode( void ) const
{
return mFillColorNode;
}
///
/// Fill Color Node Property Setter
///
void LabelModelShapeObject::setFillColorNode( const ColorNode& value )
{
if ( mFillColorNode != value )
{ {
mFillColorNode = value; return mFillColorNode;
emit changed(); }
///
/// Fill Color Node Property Setter
///
void LabelModelShapeObject::setFillColorNode( const ColorNode& value )
{
if ( mFillColorNode != value )
{
mFillColorNode = value;
emit changed();
}
} }
}
/// ///
/// Can Fill Capability Implementation /// Can Fill Capability Implementation
/// ///
bool LabelModelShapeObject::canFill() bool LabelModelShapeObject::canFill()
{ {
return true; return true;
} }
/// ///
/// Can Line Color Capability Implementation /// Can Line Color Capability Implementation
/// ///
bool LabelModelShapeObject::canLineColor() bool LabelModelShapeObject::canLineColor()
{ {
return true; return true;
} }
/// ///
/// Can Line Width Capability Implementation /// Can Line Width Capability Implementation
/// ///
bool LabelModelShapeObject::canLineWidth() bool LabelModelShapeObject::canLineWidth()
{ {
return true; return true;
}
} }
+52 -47
View File
@@ -25,66 +25,71 @@
#include "LabelModelObject.h" #include "LabelModelObject.h"
/// namespace glabels
/// Label Model Shape Object (Box or Ellipse)
///
class LabelModelShapeObject : public LabelModelObject
{ {
Q_OBJECT
/////////////////////////////////////////////////////////////// ///
// Lifecycle Methods /// Label Model Shape Object (Box or Ellipse)
/////////////////////////////////////////////////////////////// ///
protected: class LabelModelShapeObject : public LabelModelObject
LabelModelShapeObject(); {
LabelModelShapeObject( const LabelModelShapeObject* object ); Q_OBJECT
public:
virtual ~LabelModelShapeObject(); ///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
protected:
LabelModelShapeObject();
LabelModelShapeObject( const LabelModelShapeObject* object );
public:
virtual ~LabelModelShapeObject();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Property Implementations // Property Implementations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// Shape Property: lineWidth // Shape Property: lineWidth
// //
virtual glabels::Distance lineWidth( void ) const; virtual Distance lineWidth( void ) const;
virtual void setLineWidth( const glabels::Distance& value ); virtual void setLineWidth( const Distance& value );
// //
// Shape Property: lineColorNode // Shape Property: lineColorNode
// //
virtual ColorNode lineColorNode( void ) const; virtual ColorNode lineColorNode( void ) const;
virtual void setLineColorNode( const ColorNode& value ); virtual void setLineColorNode( const ColorNode& value );
// //
// Shape Property: fillColorNode // Shape Property: fillColorNode
// //
virtual ColorNode fillColorNode( void ) const; virtual ColorNode fillColorNode( void ) const;
virtual void setFillColorNode( const ColorNode& value ); virtual void setFillColorNode( const ColorNode& value );
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Capability Implementations // Capability Implementations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
virtual bool canFill(); virtual bool canFill();
virtual bool canLineColor(); virtual bool canLineColor();
virtual bool canLineWidth(); virtual bool canLineWidth();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Private Members // Private Members
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
glabels::Distance mLineWidth; Distance mLineWidth;
ColorNode mLineColorNode; ColorNode mLineColorNode;
ColorNode mFillColorNode; ColorNode mFillColorNode;
}; };
}
#endif // LabelModelShapeObject_h #endif // LabelModelShapeObject_h
File diff suppressed because it is too large Load Diff
+113 -108
View File
@@ -27,148 +27,153 @@
#include "LabelModelObject.h" #include "LabelModelObject.h"
/// namespace glabels
/// Label Model Line Object
///
class LabelModelTextObject : public LabelModelObject
{ {
Q_OBJECT
/////////////////////////////////////////////////////////////// ///
// Lifecycle Methods /// Label Model Line Object
/////////////////////////////////////////////////////////////// ///
public: class LabelModelTextObject : public LabelModelObject
LabelModelTextObject(); {
LabelModelTextObject( const LabelModelTextObject* object ); Q_OBJECT
virtual ~LabelModelTextObject();
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelTextObject();
LabelModelTextObject( const LabelModelTextObject* object );
virtual ~LabelModelTextObject();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Object duplication // Object duplication
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
virtual LabelModelTextObject* clone() const; virtual LabelModelTextObject* clone() const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Property Implementations // Property Implementations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
// //
// Text Property: text // Text Property: text
// //
virtual QString text() const; virtual QString text() const;
virtual void setText( const QString &value ); virtual void setText( const QString &value );
// //
// Text Property: fontFamily // Text Property: fontFamily
// //
virtual QString fontFamily() const; virtual QString fontFamily() const;
virtual void setFontFamily( const QString &value ); virtual void setFontFamily( const QString &value );
// //
// Text Property: fontSize // Text Property: fontSize
// //
virtual double fontSize() const; virtual double fontSize() const;
virtual void setFontSize( double value ); virtual void setFontSize( double value );
// //
// Text Property: fontWeight // Text Property: fontWeight
// //
virtual QFont::Weight fontWeight() const; virtual QFont::Weight fontWeight() const;
virtual void setFontWeight( QFont::Weight value ); virtual void setFontWeight( QFont::Weight value );
// //
// Text Property: fontItalicFlag // Text Property: fontItalicFlag
// //
virtual bool fontItalicFlag() const; virtual bool fontItalicFlag() const;
virtual void setFontItalicFlag( bool value ); virtual void setFontItalicFlag( bool value );
// //
// Text Property: fontUnderlineFlag // Text Property: fontUnderlineFlag
// //
virtual bool fontUnderlineFlag() const; virtual bool fontUnderlineFlag() const;
virtual void setFontUnderlineFlag( bool value ); virtual void setFontUnderlineFlag( bool value );
// //
// Text Property: textColorNode // Text Property: textColorNode
// //
virtual ColorNode textColorNode() const; virtual ColorNode textColorNode() const;
virtual void setTextColorNode( const ColorNode &value ); virtual void setTextColorNode( const ColorNode &value );
// //
// Text Property: textHAlign // Text Property: textHAlign
// //
virtual Qt::Alignment textHAlign() const; virtual Qt::Alignment textHAlign() const;
virtual void setTextHAlign( Qt::Alignment value ); virtual void setTextHAlign( Qt::Alignment value );
// //
// Text Property: textVAlign // Text Property: textVAlign
// //
virtual Qt::Alignment textVAlign() const; virtual Qt::Alignment textVAlign() const;
virtual void setTextVAlign( Qt::Alignment value ); virtual void setTextVAlign( Qt::Alignment value );
// //
// Text Property: textLineSpacing // Text Property: textLineSpacing
// //
virtual double textLineSpacing() const; virtual double textLineSpacing() const;
virtual void setTextLineSpacing( double value ); virtual void setTextLineSpacing( double value );
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Capability Implementations // Capability Implementations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
public: public:
virtual bool canText(); virtual bool canText();
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const; virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const;
virtual QPainterPath hoverPath( double scale ) const; virtual QPainterPath hoverPath( double scale ) const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Private methods // Private methods
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
private: private:
virtual void sizeUpdated(); virtual void sizeUpdated();
void update(); void update();
void drawTextInEditor( QPainter* painter, const QColor& color ) const; void drawTextInEditor( QPainter* painter, const QColor& color ) const;
void drawText( QPainter* painter, const QColor&color, merge::Record* record ) const; void drawText( QPainter* painter, const QColor&color, merge::Record* record ) const;
QString expandText( QString text, merge::Record* record ) const; QString expandText( QString text, merge::Record* record ) const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Private Members // Private Members
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
private: private:
QString mText; QString mText;
QString mFontFamily; QString mFontFamily;
double mFontSize; double mFontSize;
QFont::Weight mFontWeight; QFont::Weight mFontWeight;
bool mFontItalicFlag; bool mFontItalicFlag;
bool mFontUnderlineFlag; bool mFontUnderlineFlag;
ColorNode mTextColorNode; ColorNode mTextColorNode;
Qt::Alignment mTextHAlign; Qt::Alignment mTextHAlign;
Qt::Alignment mTextVAlign; Qt::Alignment mTextVAlign;
double mTextLineSpacing; double mTextLineSpacing;
QList<QTextLayout*> mEditorLayouts; QList<QTextLayout*> mEditorLayouts;
QPainterPath mHoverPath; QPainterPath mHoverPath;
}; };
}
#endif // LabelModelTextObject_h #endif // LabelModelTextObject_h
+9 -7
View File
@@ -23,7 +23,7 @@
#include <cmath> #include <cmath>
#include "privateConstants.h" #include "Constants.h"
namespace glabels namespace glabels
@@ -37,6 +37,7 @@ namespace glabels
const Distance& dy ) const Distance& dy )
: mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy) : mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy)
{ {
// empty
} }
@@ -44,6 +45,7 @@ namespace glabels
: mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0), : mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0),
mDx(other.mDx), mDy(other.mDy) mDx(other.mDx), mDy(other.mDy)
{ {
// empty
} }
@@ -85,12 +87,12 @@ namespace glabels
bool Layout::isSimilarTo( const Layout *other ) bool Layout::isSimilarTo( const Layout *other )
{ {
return ( (mNx == other->mNx) && return ( (mNx == other->mNx) &&
(mNy == other->mNy) && (mNy == other->mNy) &&
(fabs(mX0 - other->mX0) < Constants::EPSILON) && (fabs(mX0 - other->mX0) < EPSILON) &&
(fabs(mY0 - other->mY0) < Constants::EPSILON) && (fabs(mY0 - other->mY0) < EPSILON) &&
(fabs(mDx - other->mDx) < Constants::EPSILON) && (fabs(mDx - other->mDx) < EPSILON) &&
(fabs(mDy - other->mDy) < Constants::EPSILON) ); (fabs(mDy - other->mDy) < EPSILON) );
} }
+1430 -1423
View File
File diff suppressed because it is too large Load Diff
+227 -220
View File
@@ -33,257 +33,264 @@
#include <QStackedWidget> #include <QStackedWidget>
#include <QToolBar> #include <QToolBar>
// Forward References
class LabelEditor;
class LabelModel;
class MergeView;
class ObjectEditor;
class PrintView;
class PropertiesView;
class StartupView;
class UndoRedoModel;
namespace glabels
///
/// MainWindow Widget
///
class MainWindow : public QMainWindow
{ {
Q_OBJECT
// Forward References
class LabelEditor;
class LabelModel;
class MergeView;
class ObjectEditor;
class PrintView;
class PropertiesView;
class StartupView;
class UndoRedoModel;
///////////////////////////////////// ///
// Lifecycle /// MainWindow Widget
///////////////////////////////////// ///
public: class MainWindow : public QMainWindow
MainWindow(); {
virtual ~MainWindow(); Q_OBJECT
///////////////////////////////////// /////////////////////////////////////
// Public Methods // Lifecycle
///////////////////////////////////// /////////////////////////////////////
public: public:
LabelModel* model() const; MainWindow();
void setModel( LabelModel* label ); virtual ~MainWindow();
bool isEmpty() const;
///////////////////////////////////// /////////////////////////////////////
// Events // Public Methods
///////////////////////////////////// /////////////////////////////////////
protected: public:
void closeEvent( QCloseEvent *event ); LabelModel* model() const;
void setModel( LabelModel* label );
bool isEmpty() const;
///////////////////////////////////// /////////////////////////////////////
// Slots // Events
///////////////////////////////////// /////////////////////////////////////
private slots: protected:
void changePage(QListWidgetItem *current, QListWidgetItem *previous); void closeEvent( QCloseEvent *event );
void clipboardChanged();
void fileNew();
void fileOpen();
void fileSave();
void fileSaveAs();
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();
void onUndoRedoChanged();
///////////////////////////////////// /////////////////////////////////////
// Internal Private Methods // Slots
///////////////////////////////////// /////////////////////////////////////
private: private slots:
void createActions(); void changePage(QListWidgetItem *current, QListWidgetItem *previous);
void createMenus();
void createToolBars();
void createStatusBar();
QWidget* createWelcomePage(); void clipboardChanged();
QWidget* createPropertiesPage();
QWidget* createEditorPage();
QWidget* createMergePage();
QWidget* createPrintPage();
void setWelcomeMode( bool ); void fileNew();
void setDocVerbsEnabled( bool ); void fileOpen();
void setDocModifiedVerbsEnabled( bool ); void fileSave();
void setPasteVerbsEnabled( bool ); void fileSaveAs();
void setSelectionVerbsEnabled( bool ); void fileTemplateDesigner();
void setMultiSelectionVerbsEnabled( bool ); void fileClose();
void fileExit();
void setTitle(); void editUndo();
void editRedo();
void editCut();
void editCopy();
void editPaste();
void editDelete();
void editSelectAll();
void editUnSelectAll();
void editPreferences();
void readSettings(); void viewFileToolBar( bool );
void writeSettings(); void viewEditorToolBar( bool );
void viewGrid( bool );
void viewMarkup( bool );
void viewZoomIn();
void viewZoomOut();
void viewZoom1To1();
void viewZoomToFit();
bool isOkToClose(); 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();
void onUndoRedoChanged();
/////////////////////////////////////
// Internal Private Methods
/////////////////////////////////////
private:
void createActions();
void createMenus();
void createToolBars();
void createStatusBar();
QWidget* createWelcomePage();
QWidget* createPropertiesPage();
QWidget* createEditorPage();
QWidget* createMergePage();
QWidget* createPrintPage();
void setWelcomeMode( bool );
void setDocVerbsEnabled( bool );
void setDocModifiedVerbsEnabled( bool );
void setPasteVerbsEnabled( bool );
void setSelectionVerbsEnabled( bool );
void setMultiSelectionVerbsEnabled( bool );
void setTitle();
void readSettings();
void writeSettings();
bool isOkToClose();
///////////////////////////////////// /////////////////////////////////////
// Private Data // Private Data
///////////////////////////////////// /////////////////////////////////////
private: private:
QMenu* fileMenu; QMenu* fileMenu;
QMenu* editMenu; QMenu* editMenu;
QMenu* viewMenu; QMenu* viewMenu;
QMenu* viewToolBarsMenu; QMenu* viewToolBarsMenu;
QMenu* objectsMenu; QMenu* objectsMenu;
QMenu* objectsCreateMenu; QMenu* objectsCreateMenu;
QMenu* objectsOrderMenu; QMenu* objectsOrderMenu;
QMenu* objectsXformMenu; QMenu* objectsXformMenu;
QMenu* objectsAlignMenu; QMenu* objectsAlignMenu;
QMenu* objectsCenterMenu; QMenu* objectsCenterMenu;
QMenu* helpMenu; QMenu* helpMenu;
QMenu* contextMenu; QMenu* contextMenu;
QMenu* contextOrderMenu; QMenu* contextOrderMenu;
QMenu* contextXformMenu; QMenu* contextXformMenu;
QMenu* contextAlignMenu; QMenu* contextAlignMenu;
QMenu* contextCenterMenu; QMenu* contextCenterMenu;
QMenu* noSelectionContextMenu; QMenu* noSelectionContextMenu;
QToolBar* fileToolBar; QToolBar* fileToolBar;
QToolBar* editorToolBar; QToolBar* editorToolBar;
LabelModel* mModel; LabelModel* mModel;
UndoRedoModel* mUndoRedoModel; UndoRedoModel* mUndoRedoModel;
QListWidget* mContents; QListWidget* mContents;
QListWidgetItem* mWelcomeButton; QListWidgetItem* mWelcomeButton;
QListWidgetItem* mPropertiesButton; QListWidgetItem* mPropertiesButton;
QListWidgetItem* mEditorButton; QListWidgetItem* mEditorButton;
QListWidgetItem* mMergeButton; QListWidgetItem* mMergeButton;
QListWidgetItem* mPrintButton; QListWidgetItem* mPrintButton;
QStackedWidget* mPages; QStackedWidget* mPages;
StartupView* mWelcomeView; StartupView* mWelcomeView;
PropertiesView* mPropertiesView; PropertiesView* mPropertiesView;
QScrollArea* mLabelEditorScrollArea; QScrollArea* mLabelEditorScrollArea;
LabelEditor* mLabelEditor; LabelEditor* mLabelEditor;
ObjectEditor* mObjectEditor; ObjectEditor* mObjectEditor;
MergeView* mMergeView; MergeView* mMergeView;
PrintView* mPrintView; PrintView* mPrintView;
QLabel* zoomInfoLabel; QLabel* zoomInfoLabel;
QLabel* cursorInfoLabel; QLabel* cursorInfoLabel;
QAction* fileNewAction; QAction* fileNewAction;
QAction* fileOpenAction; QAction* fileOpenAction;
QAction* fileSaveAction; QAction* fileSaveAction;
QAction* fileSaveAsAction; QAction* fileSaveAsAction;
QAction* fileTemplateDesignerAction; QAction* fileTemplateDesignerAction;
QAction* fileCloseAction; QAction* fileCloseAction;
QAction* fileExitAction; QAction* fileExitAction;
QAction* editUndoAction; QAction* editUndoAction;
QAction* editRedoAction; QAction* editRedoAction;
QAction* editCutAction; QAction* editCutAction;
QAction* editCopyAction; QAction* editCopyAction;
QAction* editPasteAction; QAction* editPasteAction;
QAction* editDeleteAction; QAction* editDeleteAction;
QAction* editSelectAllAction; QAction* editSelectAllAction;
QAction* editUnSelectAllAction; QAction* editUnSelectAllAction;
QAction* editPreferencesAction; QAction* editPreferencesAction;
QAction* viewFileToolBarAction; QAction* viewFileToolBarAction;
QAction* viewEditorToolBarAction; QAction* viewEditorToolBarAction;
QAction* viewGridAction; QAction* viewGridAction;
QAction* viewMarkupAction; QAction* viewMarkupAction;
QAction* viewZoomInAction; QAction* viewZoomInAction;
QAction* viewZoomOutAction; QAction* viewZoomOutAction;
QAction* viewZoom1To1Action; QAction* viewZoom1To1Action;
QAction* viewZoomToFitAction; QAction* viewZoomToFitAction;
QAction* objectsArrowModeAction; QAction* objectsArrowModeAction;
QAction* objectsCreateTextAction; QAction* objectsCreateTextAction;
QAction* objectsCreateBoxAction; QAction* objectsCreateBoxAction;
QAction* objectsCreateLineAction; QAction* objectsCreateLineAction;
QAction* objectsCreateEllipseAction; QAction* objectsCreateEllipseAction;
QAction* objectsCreateImageAction; QAction* objectsCreateImageAction;
QAction* objectsCreateBarcodeAction; QAction* objectsCreateBarcodeAction;
QAction* objectsOrderRaiseAction; QAction* objectsOrderRaiseAction;
QAction* objectsOrderLowerAction; QAction* objectsOrderLowerAction;
QAction* objectsXformRotateLeftAction; QAction* objectsXformRotateLeftAction;
QAction* objectsXformRotateRightAction; QAction* objectsXformRotateRightAction;
QAction* objectsXformFlipHorizAction; QAction* objectsXformFlipHorizAction;
QAction* objectsXformFlipVertAction; QAction* objectsXformFlipVertAction;
QAction* objectsAlignLeftAction; QAction* objectsAlignLeftAction;
QAction* objectsAlignHCenterAction; QAction* objectsAlignHCenterAction;
QAction* objectsAlignRightAction; QAction* objectsAlignRightAction;
QAction* objectsAlignTopAction; QAction* objectsAlignTopAction;
QAction* objectsAlignVCenterAction; QAction* objectsAlignVCenterAction;
QAction* objectsAlignBottomAction; QAction* objectsAlignBottomAction;
QAction* objectsCenterHorizAction; QAction* objectsCenterHorizAction;
QAction* objectsCenterVertAction; QAction* objectsCenterVertAction;
QAction* helpContentsAction; QAction* helpContentsAction;
QAction* helpAboutAction; QAction* helpAboutAction;
QAction* contextCutAction; QAction* contextCutAction;
QAction* contextCopyAction; QAction* contextCopyAction;
QAction* contextPasteAction; QAction* contextPasteAction;
QAction* contextDeleteAction; QAction* contextDeleteAction;
}; };
}
#endif // MainWindow_h #endif // MainWindow_h
+157 -154
View File
@@ -31,191 +31,194 @@
#include "TextSemicolonKeys.h" #include "TextSemicolonKeys.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// Static data
///
QMap<QString,Factory::BackendEntry> Factory::mBackendIdMap;
QMap<QString,Factory::BackendEntry> Factory::mBackendNameMap;
QStringList Factory::mNameList;
///
/// Constructor
///
Factory::Factory()
{ {
registerBackend( None::id(),
tr("None"), //
NONE, // Static data
&None::create ); //
QMap<QString,Factory::BackendEntry> Factory::mBackendIdMap;
QMap<QString,Factory::BackendEntry> Factory::mBackendNameMap;
QStringList Factory::mNameList;
///
/// Constructor
///
Factory::Factory()
{
registerBackend( None::id(),
tr("None"),
NONE,
&None::create );
registerBackend( TextCsv::id(), registerBackend( TextCsv::id(),
tr("Text: Comma Separated Values (CSV)"), tr("Text: Comma Separated Values (CSV)"),
FILE, FILE,
&TextCsv::create ); &TextCsv::create );
registerBackend( TextCsvKeys::id(), registerBackend( TextCsvKeys::id(),
tr("Text: Comma Separated Values (CSV), keys on line 1"), tr("Text: Comma Separated Values (CSV), keys on line 1"),
FILE, FILE,
&TextCsvKeys::create ); &TextCsvKeys::create );
registerBackend( TextTsv::id(), registerBackend( TextTsv::id(),
tr("Text: Tab Separated Values (TSV)"), tr("Text: Tab Separated Values (TSV)"),
FILE, FILE,
&TextTsv::create ); &TextTsv::create );
registerBackend( TextTsvKeys::id(), registerBackend( TextTsvKeys::id(),
tr("Text: Tab Separated Values (TSV), keys on line 1"), tr("Text: Tab Separated Values (TSV), keys on line 1"),
FILE, FILE,
&TextTsvKeys::create ); &TextTsvKeys::create );
registerBackend( TextColon::id(), registerBackend( TextColon::id(),
tr("Text: Colon Separated Values"), tr("Text: Colon Separated Values"),
FILE, FILE,
&TextColon::create ); &TextColon::create );
registerBackend( TextColonKeys::id(), registerBackend( TextColonKeys::id(),
tr("Text: Colon Separated Values, keys on line 1"), tr("Text: Colon Separated Values, keys on line 1"),
FILE, FILE,
&TextColonKeys::create ); &TextColonKeys::create );
registerBackend( TextSemicolon::id(), registerBackend( TextSemicolon::id(),
tr("Text: Semicolon Separated Values"), tr("Text: Semicolon Separated Values"),
FILE, FILE,
&TextSemicolon::create ); &TextSemicolon::create );
registerBackend( TextSemicolonKeys::id(), registerBackend( TextSemicolonKeys::id(),
tr("Text: Semicolon Separated Values, keys on line 1"), tr("Text: Semicolon Separated Values, keys on line 1"),
FILE, FILE,
&TextSemicolonKeys::create ); &TextSemicolonKeys::create );
}
///
/// Initialize
///
void Factory::init()
{
static Factory* singletonInstance = 0;
if ( !singletonInstance )
{
singletonInstance = new Factory();
} }
}
/// ///
/// Create Merge object /// Initialize
/// ///
Merge* Factory::createMerge( const QString& id ) void Factory::init()
{
QMap<QString,BackendEntry>::iterator iBackend = mBackendIdMap.find( id );
if ( iBackend != mBackendIdMap.end() )
{ {
return iBackend->create(); static Factory* singletonInstance = 0;
if ( !singletonInstance )
{
singletonInstance = new Factory();
}
} }
///
/// Create Merge object
///
Merge* Factory::createMerge( const QString& id )
{
QMap<QString,BackendEntry>::iterator iBackend = mBackendIdMap.find( id );
if ( iBackend != mBackendIdMap.end() )
{
return iBackend->create();
}
return None::create(); return None::create();
}
///
/// Get name list
///
QStringList Factory::nameList()
{
return mNameList;
}
///
/// Convert ID to name
///
QString Factory::idToName( const QString& id )
{
if ( mBackendIdMap.contains( id ) )
{
return mBackendIdMap[id].name;
} }
else
{
return tr("None");
}
}
/// ///
/// Convert name to ID /// Get name list
/// ///
QString Factory::nameToId( const QString& name ) QStringList Factory::nameList()
{
if ( mBackendNameMap.contains( name ) )
{ {
return mBackendNameMap[name].id; return mNameList;
} }
else
///
/// Convert ID to name
///
QString Factory::idToName( const QString& id )
{ {
if ( mBackendIdMap.contains( id ) )
{
return mBackendIdMap[id].name;
}
else
{
return tr("None");
}
}
///
/// Convert name to ID
///
QString Factory::nameToId( const QString& name )
{
if ( mBackendNameMap.contains( name ) )
{
return mBackendNameMap[name].id;
}
else
{
return "None";
}
}
///
/// Convert ID to type
///
Factory::SourceType Factory::idToType( const QString& id )
{
if ( mBackendIdMap.contains( id ) )
{
return mBackendIdMap[id].type;
}
else
{
return NONE;
}
}
///
/// Lookup ID from index
///
QString Factory::indexToId( int index )
{
if ( (index > 0) && (index < mNameList.size()) )
{
QString name = mNameList[index];
return mBackendNameMap[ name ].id;
}
return "None"; return "None";
} }
}
/// ///
/// Convert ID to type /// Register backend
/// ///
Factory::SourceType Factory::idToType( const QString& id ) void Factory::registerBackend( const QString& id,
{ const QString& name,
if ( mBackendIdMap.contains( id ) ) SourceType type,
CreateFct create )
{ {
return mBackendIdMap[id].type; BackendEntry backend;
}
else
{
return NONE;
}
}
backend.id = id;
/// backend.name = name;
/// Lookup ID from index backend.type = type;
/// backend.create = create;
QString Factory::indexToId( int index )
{
if ( (index > 0) && (index < mNameList.size()) )
{
QString name = mNameList[index];
return mBackendNameMap[ name ].id;
}
return "None";
}
///
/// Register backend
///
void Factory::registerBackend( const QString& id,
const QString& name,
SourceType type,
CreateFct create )
{
BackendEntry backend;
backend.id = id;
backend.name = name;
backend.type = type;
backend.create = create;
mBackendIdMap[ id ] = backend; mBackendIdMap[ id ] = backend;
mBackendNameMap[ name ] = backend; mBackendNameMap[ name ] = backend;
mNameList << name;
}
mNameList << name;
} }
} }
+71 -63
View File
@@ -26,78 +26,86 @@
#include <QMap> #include <QMap>
namespace merge namespace glabels
{ {
class Merge; // Forward reference
/// namespace merge
/// Factory
///
class Factory
{ {
Q_DECLARE_TR_FUNCTIONS(Factory)
// Forward references
class Merge;
///////////////////////////////// ///
// Source Type /// Factory
///////////////////////////////// ///
public: class Factory
enum SourceType { NONE, FIXED, FILE };
/////////////////////////////////
// Life Cycle
/////////////////////////////////
protected:
Factory();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static void init();
static Merge* createMerge( const QString& id );
static QStringList nameList();
static QString idToName( const QString& id );
static QString nameToId( const QString& name );
static SourceType idToType( const QString& id );
static QString indexToId( int index );
/////////////////////////////////
// private methods
/////////////////////////////////
private:
typedef Merge* (*CreateFct)();
static void registerBackend( const QString& id,
const QString& name,
SourceType type,
CreateFct create );
/////////////////////////////////
// private data
/////////////////////////////////
class BackendEntry
{ {
public: Q_DECLARE_TR_FUNCTIONS(Factory)
QString id;
QString name;
SourceType type;
CreateFct create;
};
static QMap<QString,BackendEntry> mBackendIdMap;
static QMap<QString,BackendEntry> mBackendNameMap; /////////////////////////////////
// Source Type
/////////////////////////////////
public:
enum SourceType { NONE, FIXED, FILE };
static QStringList mNameList;
}; /////////////////////////////////
// Life Cycle
/////////////////////////////////
protected:
Factory();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static void init();
static Merge* createMerge( const QString& id );
static QStringList nameList();
static QString idToName( const QString& id );
static QString nameToId( const QString& name );
static SourceType idToType( const QString& id );
static QString indexToId( int index );
/////////////////////////////////
// private methods
/////////////////////////////////
private:
typedef Merge* (*CreateFct)();
static void registerBackend( const QString& id,
const QString& name,
SourceType type,
CreateFct create );
/////////////////////////////////
// private data
/////////////////////////////////
class BackendEntry
{
public:
QString id;
QString name;
SourceType type;
CreateFct create;
};
static QMap<QString,BackendEntry> mBackendIdMap;
static QMap<QString,BackendEntry> mBackendNameMap;
static QStringList mNameList;
};
}
} }
#endif // merge_Factory_h #endif // merge_Factory_h
+146 -141
View File
@@ -23,188 +23,193 @@
#include "Record.h" #include "Record.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// Constructor
///
Merge::Merge()
{ {
}
///
/// /// Constructor
/// Constructor ///
/// Merge::Merge()
Merge::Merge( const Merge* merge ) : mSource(merge->mSource)
{
foreach ( Record* record, merge->mRecordList )
{ {
mRecordList << record->clone();
} }
}
/// ///
/// Destructor /// Constructor
/// ///
Merge::~Merge() Merge::Merge( const Merge* merge ) : mSource(merge->mSource)
{
foreach ( Record* record, mRecordList )
{ {
delete record; foreach ( Record* record, merge->mRecordList )
{
mRecordList << record->clone();
}
} }
mRecordList.clear();
}
/// ///
/// Get id /// Destructor
/// ///
QString Merge::id() const Merge::~Merge()
{
return mId;
}
///
/// Get source
///
QString Merge::source() const
{
return mSource;
}
///
/// Set source
///
void Merge::setSource( const QString& source )
{
mSource = source;
// Clear out any old records
foreach ( Record* record, mRecordList )
{ {
delete record; foreach ( Record* record, mRecordList )
{
delete record;
}
mRecordList.clear();
} }
mRecordList.clear();
open();
for ( Record* record = readNextRecord(); record != 0; record = readNextRecord() ) ///
/// Get id
///
QString Merge::id() const
{ {
mRecordList.append( record ); return mId;
} }
close();
///
/// Get source
///
QString Merge::source() const
{
return mSource;
}
///
/// Set source
///
void Merge::setSource( const QString& source )
{
mSource = source;
// Clear out any old records
foreach ( Record* record, mRecordList )
{
delete record;
}
mRecordList.clear();
open();
for ( Record* record = readNextRecord(); record != 0; record = readNextRecord() )
{
mRecordList.append( record );
}
close();
emit sourceChanged(); emit sourceChanged();
}
///
/// Get record list
///
const QList<Record*>& Merge::recordList( void ) const
{
return mRecordList;
}
///
/// Select matching record
///
void Merge::select( Record* record )
{
record->setSelected( true );
emit selectionChanged();
}
///
/// Unselect matching record
///
void Merge::unselect( Record* record )
{
record->setSelected( false );
emit selectionChanged();
}
///
/// Select/unselect i'th record
///
void Merge::setSelected( int i, bool state )
{
if ( (i >= 0) && (i < mRecordList.size()) )
{
mRecordList[i]->setSelected( state );
emit selectionChanged();
} }
}
/// ///
/// Select all records /// Get record list
/// ///
void Merge::selectAll() const QList<Record*>& Merge::recordList( void ) const
{ {
foreach ( Record* record, mRecordList ) return mRecordList;
}
///
/// Select matching record
///
void Merge::select( Record* record )
{ {
record->setSelected( true ); record->setSelected( true );
emit selectionChanged();
} }
emit selectionChanged();
}
///
/// Unselect all records ///
/// /// Unselect matching record
void Merge::unselectAll() ///
{ void Merge::unselect( Record* record )
foreach ( Record* record, mRecordList )
{ {
record->setSelected( false ); record->setSelected( false );
emit selectionChanged();
} }
emit selectionChanged();
}
/// ///
/// Return count of selected records /// Select/unselect i'th record
/// ///
int Merge::nSelectedRecords() const void Merge::setSelected( int i, bool state )
{
int count = 0;
foreach ( Record* record, mRecordList )
{ {
if ( record->isSelected() ) if ( (i >= 0) && (i < mRecordList.size()) )
{ {
count++; mRecordList[i]->setSelected( state );
emit selectionChanged();
} }
} }
return count;
}
///
/// /// Select all records
/// Return list of selected records ///
/// void Merge::selectAll()
const QList<Record*> Merge::selectedRecords() const
{
QList<Record*> list;
foreach ( Record* record, mRecordList )
{ {
if ( record->isSelected() ) foreach ( Record* record, mRecordList )
{ {
list.append( record ); record->setSelected( true );
} }
emit selectionChanged();
}
///
/// Unselect all records
///
void Merge::unselectAll()
{
foreach ( Record* record, mRecordList )
{
record->setSelected( false );
}
emit selectionChanged();
}
///
/// Return count of selected records
///
int Merge::nSelectedRecords() const
{
int count = 0;
foreach ( Record* record, mRecordList )
{
if ( record->isSelected() )
{
count++;
}
}
return count;
}
///
/// Return list of selected records
///
const QList<Record*> Merge::selectedRecords() const
{
QList<Record*> list;
foreach ( Record* record, mRecordList )
{
if ( record->isSelected() )
{
list.append( record );
}
}
return list;
} }
return list;
} }
} }
+80 -72
View File
@@ -27,90 +27,98 @@
#include <QList> #include <QList>
namespace merge namespace glabels
{ {
class Record; // Forward reference
namespace merge
///
/// Merge Object
///
struct Merge : QObject
{ {
Q_OBJECT
// Forward references
///////////////////////////////// class Record;
// Life Cycle
/////////////////////////////////
protected:
Merge();
Merge( const Merge* merge );
public:
virtual ~Merge();
/////////////////////////////////
// Object duplication
/////////////////////////////////
virtual Merge* clone() const = 0;
/////////////////////////////////
// Properties
/////////////////////////////////
public:
QString id() const;
QString source() const;
void setSource( const QString& source );
const QList<Record*>& recordList( void ) const;
/////////////////////////////////
// Selection methods
/////////////////////////////////
public:
void select( Record* record );
void unselect( Record* record );
void setSelected( int i, bool state = true );
void selectAll();
void unselectAll();
int nSelectedRecords() const; ///
const QList<Record*> selectedRecords() const; /// Merge Object
///
struct Merge : QObject
{
Q_OBJECT
///////////////////////////////// /////////////////////////////////
// Virtual methods // Life Cycle
///////////////////////////////// /////////////////////////////////
public: protected:
virtual QStringList keys() const = 0; Merge();
virtual QString primaryKey() const = 0; Merge( const Merge* merge );
protected: public:
virtual void open() = 0; virtual ~Merge();
virtual void close() = 0;
virtual Record* readNextRecord() = 0;
/////////////////////////////////
// Object duplication
/////////////////////////////////
virtual Merge* clone() const = 0;
/////////////////////////////////
// Properties
/////////////////////////////////
public:
QString id() const;
QString source() const;
void setSource( const QString& source );
const QList<Record*>& recordList( void ) const;
/////////////////////////////////
// Selection methods
/////////////////////////////////
public:
void select( Record* record );
void unselect( Record* record );
void setSelected( int i, bool state = true );
void selectAll();
void unselectAll();
int nSelectedRecords() const;
const QList<Record*> selectedRecords() const;
/////////////////////////////////
// Virtual methods
/////////////////////////////////
public:
virtual QStringList keys() const = 0;
virtual QString primaryKey() const = 0;
protected:
virtual void open() = 0;
virtual void close() = 0;
virtual Record* readNextRecord() = 0;
///////////////////////////////// /////////////////////////////////
// Signals // Signals
///////////////////////////////// /////////////////////////////////
signals: signals:
void sourceChanged(); void sourceChanged();
void selectionChanged(); void selectionChanged();
///////////////////////////////// /////////////////////////////////
// Private data // Private data
///////////////////////////////// /////////////////////////////////
protected: protected:
QString mId; QString mId;
private: private:
QString mSource; QString mSource;
QList<Record*> mRecordList; QList<Record*> mRecordList;
}; };
}
} }
#endif // merge_Merge_h #endif // merge_Merge_h
+78 -73
View File
@@ -21,102 +21,107 @@
#include "None.h" #include "None.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// Constructor
///
None::None() : Merge()
{ {
mId = "None";
} ///
/// Constructor
///
None::None() : Merge()
{
mId = "None";
}
/// ///
/// Constructor /// Constructor
/// ///
None::None( const None* merge ) : Merge( merge ) None::None( const None* merge ) : Merge( merge )
{ {
} }
/// ///
/// Destructor /// Destructor
/// ///
None::~None() None::~None()
{ {
} }
/// ///
/// Clone /// Clone
/// ///
None* None::clone() const None* None::clone() const
{ {
return new None( this ); return new None( this );
} }
/// ///
/// Get ID /// Get ID
/// ///
QString None::id() QString None::id()
{ {
return "None"; return "None";
} }
/// ///
/// Create /// Create
/// ///
Merge* None::create() Merge* None::create()
{ {
return new None(); return new None();
} }
/// ///
/// Get key list /// Get key list
/// ///
QStringList None::keys() const QStringList None::keys() const
{ {
QStringList emptyList; QStringList emptyList;
return emptyList; return emptyList;
} }
/// ///
/// Get primary key /// Get primary key
/// ///
QString None::primaryKey() const QString None::primaryKey() const
{ {
return ""; return "";
} }
/// ///
/// Open source /// Open source
/// ///
void None::open() void None::open()
{ {
} }
/// ///
/// Close source /// Close source
/// ///
void None::close() void None::close()
{ {
} }
/// ///
/// Read next record /// Read next record
/// ///
Record* None::readNextRecord() Record* None::readNextRecord()
{ {
return 0; return 0;
}
} }
} }
+40 -34
View File
@@ -24,51 +24,57 @@
#include "Merge.h" #include "Merge.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// None Merge Backend
///
struct None : public Merge
{ {
///
/// None Merge Backend
///
struct None : public Merge
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
None(); None();
None( const None* merge ); None( const None* merge );
virtual ~None(); virtual ~None();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
None* clone() const; None* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
///////////////////////////////// /////////////////////////////////
// Implementation of virtual methods // Implementation of virtual methods
///////////////////////////////// /////////////////////////////////
public: public:
QStringList keys() const; QStringList keys() const;
QString primaryKey() const; QString primaryKey() const;
protected: protected:
void open(); void open();
void close(); void close();
Record* readNextRecord(); Record* readNextRecord();
}; };
}
} }
#endif // merge_None_h #endif // merge_None_h
+38 -33
View File
@@ -21,50 +21,55 @@
#include "Record.h" #include "Record.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// Constructor
///
Record::Record() : mSelected( true )
{ {
}
///
/// Constructor
///
Record::Record() : mSelected( true )
{
}
/// ///
/// Constructor /// Constructor
/// ///
Record::Record( const Record* record ) Record::Record( const Record* record )
: QMap<QString,QString>(*record), mSelected(record->mSelected) : QMap<QString,QString>(*record), mSelected(record->mSelected)
{ {
} }
/// ///
/// Clone /// Clone
/// ///
Record* Record::clone() const Record* Record::clone() const
{ {
return new Record( this ); return new Record( this );
} }
/// ///
/// Is record selected? /// Is record selected?
/// ///
bool Record::isSelected() const bool Record::isSelected() const
{ {
return mSelected; return mSelected;
} }
/// ///
/// Set selected on not selected /// Set selected on not selected
/// ///
void Record::setSelected( bool value ) void Record::setSelected( bool value )
{ {
mSelected = value; mSelected = value;
}
} }
} }
+34 -28
View File
@@ -25,45 +25,51 @@
#include <QMap> #include <QMap>
namespace merge namespace glabels
{ {
/// namespace merge
/// Merge Record
///
struct Record : public QMap<QString,QString>
{ {
///
/// Merge Record
///
struct Record : public QMap<QString,QString>
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
Record(); Record();
Record( const Record* record ); Record( const Record* record );
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
Record* clone() const; Record* clone() const;
///////////////////////////////// /////////////////////////////////
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
bool isSelected() const; bool isSelected() const;
void setSelected( bool value ); void setSelected( bool value );
///////////////////////////////// /////////////////////////////////
// Private data // Private data
///////////////////////////////// /////////////////////////////////
private: private:
bool mSelected; bool mSelected;
}; };
}
} }
#endif // merge_Record_h #endif // merge_Record_h
+338 -333
View File
@@ -24,392 +24,397 @@
#include <QtDebug> #include <QtDebug>
namespace merge namespace glabels
{ {
/// namespace merge
/// Constructor
///
Text::Text( QChar delimiter, bool line1HasKeys )
: mNFieldsMax(0), mDelimeter(delimiter), mLine1HasKeys(line1HasKeys)
{ {
}
///
/// /// Constructor
/// Constructor ///
/// Text::Text( QChar delimiter, bool line1HasKeys )
Text::Text( const Text* merge ) : mNFieldsMax(0), mDelimeter(delimiter), mLine1HasKeys(line1HasKeys)
: Merge( merge ),
mNFieldsMax(merge->mNFieldsMax),
mDelimeter(merge->mDelimeter), mLine1HasKeys(merge->mLine1HasKeys)
{
}
///
/// Destructor
///
Text::~Text()
{
}
///
/// Get key list
///
QStringList Text::keys() const
{
QStringList keys;
for ( int iField = 0; iField < mNFieldsMax; iField++ )
{ {
keys << keyFromIndex(iField);
} }
return keys;
}
/// ///
/// Get primary key /// Constructor
/// ///
QString Text::primaryKey() const Text::Text( const Text* merge )
{ : Merge( merge ),
return keyFromIndex(0); mNFieldsMax(merge->mNFieldsMax),
} mDelimeter(merge->mDelimeter), mLine1HasKeys(merge->mLine1HasKeys)
///
/// Open source
///
void Text::open()
{
mFile.setFileName( source() );
mFile.open( QIODevice::ReadOnly|QIODevice::Text );
mKeys.clear();
mNFieldsMax = 0;
if ( mLine1HasKeys && mFile.isOpen() )
{ {
mKeys = parseLine(); }
if ( (mKeys.size() == 1) && (mKeys[0] == "") )
///
/// Destructor
///
Text::~Text()
{
}
///
/// Get key list
///
QStringList Text::keys() const
{
QStringList keys;
for ( int iField = 0; iField < mNFieldsMax; iField++ )
{ {
mKeys.clear(); keys << keyFromIndex(iField);
}
return keys;
}
///
/// Get primary key
///
QString Text::primaryKey() const
{
return keyFromIndex(0);
}
///
/// Open source
///
void Text::open()
{
mFile.setFileName( source() );
mFile.open( QIODevice::ReadOnly|QIODevice::Text );
mKeys.clear();
mNFieldsMax = 0;
if ( mLine1HasKeys && mFile.isOpen() )
{
mKeys = parseLine();
if ( (mKeys.size() == 1) && (mKeys[0] == "") )
{
mKeys.clear();
}
else
{
mNFieldsMax = mKeys.size();
}
}
}
///
/// Close source
///
void Text::close()
{
if ( mFile.isOpen() )
{
mFile.close();
}
}
///
/// Read next record
///
Record* Text::readNextRecord()
{
QStringList values = parseLine();
if ( !values.isEmpty() )
{
Record* record = new Record();
int iField = 0;
foreach ( QString value, values )
{
(*record)[ keyFromIndex(iField) ] = value;
iField++;
}
mNFieldsMax = std::max( mNFieldsMax, iField );
return record;
}
return 0;
}
///
/// Key from field index
///
QString Text::keyFromIndex( int iField ) const
{
if ( mLine1HasKeys && ( iField < mKeys.size() ) )
{
return mKeys[iField];
} }
else else
{ {
mNFieldsMax = mKeys.size(); return QString::number( iField+1 );
} }
} }
}
/// ///
/// Close source /// Parse line.
/// ///
void Text::close() /// Attempt to be a robust parser of various CSV (and similar) formats.
{ ///
if ( mFile.isOpen() ) /// Based on CSV format described in RFC 4180 section 2.
///
/// Additions to RFC 4180 rules:
/// - delimeters and other special characters may be "escaped" by a leading
/// backslash (\)
/// - C escape sequences for newline (\n) and tab (\t) are also translated.
/// - if quoted text is not followed by a delimeter, any additional text is
/// concatenated with quoted portion.
///
/// Returns a list of fields. A blank line is considered a line with one
/// empty field. Returns an empty list when done.
///
QStringList Text::parseLine()
{ {
mFile.close(); QStringList fields;
}
}
///
/// Read next record
///
Record* Text::readNextRecord()
{
QStringList values = parseLine();
if ( !values.isEmpty() )
{
Record* record = new Record();
int iField = 0;
foreach ( QString value, values )
{
(*record)[ keyFromIndex(iField) ] = value;
iField++;
}
mNFieldsMax = std::max( mNFieldsMax, iField );
return record;
}
return 0;
}
///
/// Key from field index
///
QString Text::keyFromIndex( int iField ) const
{
if ( mLine1HasKeys && ( iField < mKeys.size() ) )
{
return mKeys[iField];
}
else
{
return QString::number( iField+1 );
}
}
///
/// Parse line.
///
/// Attempt to be a robust parser of various CSV (and similar) formats.
///
/// Based on CSV format described in RFC 4180 section 2.
///
/// Additions to RFC 4180 rules:
/// - delimeters and other special characters may be "escaped" by a leading
/// backslash (\)
/// - C escape sequences for newline (\n) and tab (\t) are also translated.
/// - if quoted text is not followed by a delimeter, any additional text is
/// concatenated with quoted portion.
///
/// Returns a list of fields. A blank line is considered a line with one
/// empty field. Returns an empty list when done.
///
QStringList Text::parseLine()
{
QStringList fields;
enum State enum State
{
DELIM, QUOTED, QUOTED_QUOTE1, QUOTED_ESCAPED, SIMPLE, SIMPLE_ESCAPED, DONE
} state = DELIM;
QByteArray field;
while ( state != DONE )
{
char c;
if ( mFile.getChar( &c ) )
{ {
switch (state) DELIM, QUOTED, QUOTED_QUOTE1, QUOTED_ESCAPED, SIMPLE, SIMPLE_ESCAPED, DONE
} state = DELIM;
QByteArray field;
while ( state != DONE )
{
char c;
if ( mFile.getChar( &c ) )
{ {
switch (state)
case DELIM:
switch (c)
{ {
case '\n':
/* last field is empty. */ case DELIM:
fields << ""; switch (c)
state = DONE;
break;
case '\r':
/* ignore */
state = DELIM;
break;
case '"':
/* start a quoted field. */
state = QUOTED;
break;
case '\\':
/* simple field, but 1st character is an escape. */
state = SIMPLE_ESCAPED;
break;
default:
if ( c == mDelimeter )
{ {
/* field is empty. */ case '\n':
/* last field is empty. */
fields << ""; fields << "";
state = DONE;
break;
case '\r':
/* ignore */
state = DELIM; state = DELIM;
} break;
else case '"':
{ /* start a quoted field. */
/* begining of a simple field. */ state = QUOTED;
field.append( c ); break;
state = SIMPLE; case '\\':
/* simple field, but 1st character is an escape. */
state = SIMPLE_ESCAPED;
break;
default:
if ( c == mDelimeter )
{
/* field is empty. */
fields << "";
state = DELIM;
}
else
{
/* begining of a simple field. */
field.append( c );
state = SIMPLE;
}
break;
} }
break; break;
}
break;
case QUOTED: case QUOTED:
switch (c) switch (c)
{
case '"':
/* Possible end of field, but could be 1st of a pair. */
state = QUOTED_QUOTE1;
break;
case '\\':
/* Escape next character, or special escape, e.g. \n. */
state = QUOTED_ESCAPED;
break;
default:
/* Use character literally. */
field.append( c );
break;
}
break;
case QUOTED_QUOTE1:
switch (c)
{
case '\n':
/* line ended after quoted item */
fields << QString( field );
state = DONE;
break;
case '"':
/* second quote, insert and stay quoted. */
field.append( c );
state = QUOTED;
break;
case '\r':
/* ignore and go to fallback */
state = SIMPLE;
break;
default:
if ( c == mDelimeter )
{
/* end of field. */
fields << QString( field );
field.clear();
state = DELIM;
}
else
{
/* fallback if not a delim or another quote. */
field.append( c );
state = SIMPLE;
}
break;
}
break;
case QUOTED_ESCAPED:
switch (c)
{
case 'n':
/* Decode "\n" as newline. */
field.append( '\n' );
state = QUOTED;
break;
case 't':
/* Decode "\t" as tab. */
field.append( '\t' );
state = QUOTED;
break;
default:
/* Use character literally. */
field.append( c );
state = QUOTED;
break;
}
break;
case SIMPLE:
switch (c)
{
case '\n':
/* line ended */
fields << QString( field );
state = DONE;
break;
case '\r':
/* ignore */
state = SIMPLE;
break;
case '\\':
/* Escape next character, or special escape, e.g. \n. */
state = SIMPLE_ESCAPED;
break;
default:
if ( c == mDelimeter )
{
/* end of field. */
fields << QString( field );
field.clear();
state = DELIM;
}
else
{ {
case '"':
/* Possible end of field, but could be 1st of a pair. */
state = QUOTED_QUOTE1;
break;
case '\\':
/* Escape next character, or special escape, e.g. \n. */
state = QUOTED_ESCAPED;
break;
default:
/* Use character literally. */ /* Use character literally. */
field.append( c ); field.append( c );
state = SIMPLE; break;
} }
break; break;
}
break;
case SIMPLE_ESCAPED: case QUOTED_QUOTE1:
switch (c) switch (c)
{ {
case 'n': case '\n':
/* Decode "\n" as newline. */ /* line ended after quoted item */
field.append( '\n' ); fields << QString( field );
state = SIMPLE; state = DONE;
break;
case '"':
/* second quote, insert and stay quoted. */
field.append( c );
state = QUOTED;
break;
case '\r':
/* ignore and go to fallback */
state = SIMPLE;
break;
default:
if ( c == mDelimeter )
{
/* end of field. */
fields << QString( field );
field.clear();
state = DELIM;
}
else
{
/* fallback if not a delim or another quote. */
field.append( c );
state = SIMPLE;
}
break;
}
break; break;
case 't':
/* Decode "\t" as tab. */ case QUOTED_ESCAPED:
field.append( '\t' ); switch (c)
state = SIMPLE; {
case 'n':
/* Decode "\n" as newline. */
field.append( '\n' );
state = QUOTED;
break;
case 't':
/* Decode "\t" as tab. */
field.append( '\t' );
state = QUOTED;
break;
default:
/* Use character literally. */
field.append( c );
state = QUOTED;
break;
}
break; break;
case SIMPLE:
switch (c)
{
case '\n':
/* line ended */
fields << QString( field );
state = DONE;
break;
case '\r':
/* ignore */
state = SIMPLE;
break;
case '\\':
/* Escape next character, or special escape, e.g. \n. */
state = SIMPLE_ESCAPED;
break;
default:
if ( c == mDelimeter )
{
/* end of field. */
fields << QString( field );
field.clear();
state = DELIM;
}
else
{
/* Use character literally. */
field.append( c );
state = SIMPLE;
}
break;
}
break;
case SIMPLE_ESCAPED:
switch (c)
{
case 'n':
/* Decode "\n" as newline. */
field.append( '\n' );
state = SIMPLE;
break;
case 't':
/* Decode "\t" as tab. */
field.append( '\t' );
state = SIMPLE;
break;
default:
/* Use character literally. */
field.append( (char)c );
state = SIMPLE;
break;
}
break;
default: default:
/* Use character literally. */ qWarning( "merge::Text::parseLine()::Should not be reached! #1" );
field.append( (char)c );
state = SIMPLE;
break; break;
} }
break;
default:
qWarning( "merge::Text::parseLine()::Should not be reached! #1" );
break;
} }
else
}
else
{
/* Handle EOF (could also be an error while reading). */
switch (state)
{ {
/* Handle EOF (could also be an error while reading). */
switch (state)
{
case DELIM: case DELIM:
/* EOF, no more lines. */ /* EOF, no more lines. */
break; break;
case QUOTED: case QUOTED:
/* File ended midway through quoted item. Truncate field. */ /* File ended midway through quoted item. Truncate field. */
fields << QString( field ); fields << QString( field );
break; break;
case QUOTED_QUOTE1: case QUOTED_QUOTE1:
/* File ended after quoted item. */ /* File ended after quoted item. */
fields << QString( field ); fields << QString( field );
break; break;
case QUOTED_ESCAPED: case QUOTED_ESCAPED:
/* File ended midway through quoted item. Truncate field. */ /* File ended midway through quoted item. Truncate field. */
fields << QString( field ); fields << QString( field );
break; break;
case SIMPLE: case SIMPLE:
/* File ended after simple item. */ /* File ended after simple item. */
fields << QString( field ); fields << QString( field );
break; break;
case SIMPLE_ESCAPED: case SIMPLE_ESCAPED:
/* File ended midway through escaped item. */ /* File ended midway through escaped item. */
fields << QString( field ); fields << QString( field );
break; break;
default: default:
qWarning( "merge::Text::parseLine()::Should not be reached! #2" ); qWarning( "merge::Text::parseLine()::Should not be reached! #2" );
break; break;
} }
state = DONE; state = DONE;
}
} }
}
return fields; return fields;
}
} }
} }
+44 -38
View File
@@ -26,55 +26,61 @@
#include <QFile> #include <QFile>
namespace merge namespace glabels
{ {
/// namespace merge
/// Text Merge Backend
///
struct Text : public Merge
{ {
///
/// Text Merge Backend
///
struct Text : public Merge
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
protected: protected:
Text( QChar delimiter, bool line1HasKeys ); Text( QChar delimiter, bool line1HasKeys );
Text( const Text* merge ); Text( const Text* merge );
virtual ~Text(); virtual ~Text();
///////////////////////////////// /////////////////////////////////
// Implementation of virtual methods // Implementation of virtual methods
///////////////////////////////// /////////////////////////////////
public: public:
QStringList keys() const; QStringList keys() const;
QString primaryKey() const; QString primaryKey() const;
protected: protected:
void open(); void open();
void close(); void close();
Record* readNextRecord(); Record* readNextRecord();
///////////////////////////////// /////////////////////////////////
// Private methods // Private methods
///////////////////////////////// /////////////////////////////////
QString keyFromIndex( int iField ) const; QString keyFromIndex( int iField ) const;
QStringList parseLine(); QStringList parseLine();
///////////////////////////////// /////////////////////////////////
// Private data // Private data
///////////////////////////////// /////////////////////////////////
private: private:
QChar mDelimeter; QChar mDelimeter;
bool mLine1HasKeys; bool mLine1HasKeys;
QFile mFile; QFile mFile;
QStringList mKeys; QStringList mKeys;
int mNFieldsMax; int mNFieldsMax;
}; };
}
} }
#endif // merge_Text_h #endif // merge_Text_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextColon.h" #include "TextColon.h"
namespace merge namespace glabels
{ {
static const QString ID = "Text/Colon";
namespace merge
///
/// Constructor
///
TextColon::TextColon() : Text(':',false)
{ {
mId = ID; static const QString ID = "Text/Colon";
}
/// ///
/// Constructor /// Constructor
/// ///
TextColon::TextColon( const TextColon* merge ) : Text( merge ) TextColon::TextColon() : Text(':',false)
{ {
} mId = ID;
}
/// ///
/// Destructor /// Constructor
/// ///
TextColon::~TextColon() TextColon::TextColon( const TextColon* merge ) : Text( merge )
{ {
} }
/// ///
/// Clone /// Destructor
/// ///
TextColon* TextColon::clone() const TextColon::~TextColon()
{ {
return new TextColon( this ); }
}
/// ///
/// Get ID /// Clone
/// ///
QString TextColon::id() TextColon* TextColon::clone() const
{ {
return ID; return new TextColon( this );
} }
/// ///
/// Create /// Get ID
/// ///
Merge* TextColon::create() QString TextColon::id()
{ {
return new TextColon(); return ID;
}
///
/// Create
///
Merge* TextColon::create()
{
return new TextColon();
}
} }
} }
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h" #include "Text.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// TextColon Merge Backend
///
struct TextColon : public Text
{ {
///
/// TextColon Merge Backend
///
struct TextColon : public Text
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
TextColon(); TextColon();
TextColon( const TextColon* merge ); TextColon( const TextColon* merge );
virtual ~TextColon(); virtual ~TextColon();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
public: public:
TextColon* clone() const; TextColon* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
}; };
}
} }
#endif // merge_TextColon_h #endif // merge_TextColon_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextColonKeys.h" #include "TextColonKeys.h"
namespace merge namespace glabels
{ {
static const QString ID = "Text/Colon/Line1Keys";
namespace merge
{
static const QString ID = "Text/Colon/Line1Keys";
/// ///
/// Constructor /// Constructor
/// ///
TextColonKeys::TextColonKeys() : Text(':',true) TextColonKeys::TextColonKeys() : Text(':',true)
{ {
mId = ID; mId = ID;
} }
/// ///
/// Constructor /// Constructor
/// ///
TextColonKeys::TextColonKeys( const TextColonKeys* merge ) : Text( merge ) TextColonKeys::TextColonKeys( const TextColonKeys* merge ) : Text( merge )
{ {
} }
/// ///
/// Destructor /// Destructor
/// ///
TextColonKeys::~TextColonKeys() TextColonKeys::~TextColonKeys()
{ {
} }
/// ///
/// Clone /// Clone
/// ///
TextColonKeys* TextColonKeys::clone() const TextColonKeys* TextColonKeys::clone() const
{ {
return new TextColonKeys( this ); return new TextColonKeys( this );
} }
/// ///
/// Get ID /// Get ID
/// ///
QString TextColonKeys::id() QString TextColonKeys::id()
{ {
return ID; return ID;
} }
/// ///
/// Create /// Create
/// ///
Merge* TextColonKeys::create() Merge* TextColonKeys::create()
{ {
return new TextColonKeys(); return new TextColonKeys();
}
} }
} }
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h" #include "Text.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// TextColonKeys Merge Backend
///
struct TextColonKeys : public Text
{ {
///
/// TextColonKeys Merge Backend
///
struct TextColonKeys : public Text
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
TextColonKeys(); TextColonKeys();
TextColonKeys( const TextColonKeys* merge ); TextColonKeys( const TextColonKeys* merge );
virtual ~TextColonKeys(); virtual ~TextColonKeys();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
public: public:
TextColonKeys* clone() const; TextColonKeys* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
}; };
}
} }
#endif // merge_TextColonKeys_h #endif // merge_TextColonKeys_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextCsv.h" #include "TextCsv.h"
namespace merge namespace glabels
{ {
static const QString ID = "Text/Comma";
namespace merge
{
static const QString ID = "Text/Comma";
/// ///
/// Constructor /// Constructor
/// ///
TextCsv::TextCsv() : Text(',',false) TextCsv::TextCsv() : Text(',',false)
{ {
mId = ID; mId = ID;
} }
/// ///
/// Constructor /// Constructor
/// ///
TextCsv::TextCsv( const TextCsv* merge ) : Text( merge ) TextCsv::TextCsv( const TextCsv* merge ) : Text( merge )
{ {
} }
/// ///
/// Destructor /// Destructor
/// ///
TextCsv::~TextCsv() TextCsv::~TextCsv()
{ {
} }
/// ///
/// Clone /// Clone
/// ///
TextCsv* TextCsv::clone() const TextCsv* TextCsv::clone() const
{ {
return new TextCsv( this ); return new TextCsv( this );
} }
/// ///
/// Get ID /// Get ID
/// ///
QString TextCsv::id() QString TextCsv::id()
{ {
return ID; return ID;
} }
/// ///
/// Create /// Create
/// ///
Merge* TextCsv::create() Merge* TextCsv::create()
{ {
return new TextCsv(); return new TextCsv();
}
} }
} }
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h" #include "Text.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// TextCsv Merge Backend
///
struct TextCsv : public Text
{ {
///
/// TextCsv Merge Backend
///
struct TextCsv : public Text
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
TextCsv(); TextCsv();
TextCsv( const TextCsv* merge ); TextCsv( const TextCsv* merge );
virtual ~TextCsv(); virtual ~TextCsv();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
public: public:
TextCsv* clone() const; TextCsv* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
}; };
}
} }
#endif // merge_TextCsv_h #endif // merge_TextCsv_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextCsvKeys.h" #include "TextCsvKeys.h"
namespace merge namespace glabels
{ {
static const QString ID = "Text/Comma/Line1Keys";
namespace merge
{
static const QString ID = "Text/Comma/Line1Keys";
/// ///
/// Constructor /// Constructor
/// ///
TextCsvKeys::TextCsvKeys() : Text(',',true) TextCsvKeys::TextCsvKeys() : Text(',',true)
{ {
mId = ID; mId = ID;
} }
/// ///
/// Constructor /// Constructor
/// ///
TextCsvKeys::TextCsvKeys( const TextCsvKeys* merge ) : Text( merge ) TextCsvKeys::TextCsvKeys( const TextCsvKeys* merge ) : Text( merge )
{ {
} }
/// ///
/// Destructor /// Destructor
/// ///
TextCsvKeys::~TextCsvKeys() TextCsvKeys::~TextCsvKeys()
{ {
} }
/// ///
/// Clone /// Clone
/// ///
TextCsvKeys* TextCsvKeys::clone() const TextCsvKeys* TextCsvKeys::clone() const
{ {
return new TextCsvKeys( this ); return new TextCsvKeys( this );
} }
/// ///
/// Get ID /// Get ID
/// ///
QString TextCsvKeys::id() QString TextCsvKeys::id()
{ {
return ID; return ID;
} }
/// ///
/// Create /// Create
/// ///
Merge* TextCsvKeys::create() Merge* TextCsvKeys::create()
{ {
return new TextCsvKeys(); return new TextCsvKeys();
}
} }
} }
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h" #include "Text.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// TextCsvKeys Merge Backend
///
struct TextCsvKeys : public Text
{ {
///
/// TextCsvKeys Merge Backend
///
struct TextCsvKeys : public Text
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
TextCsvKeys(); TextCsvKeys();
TextCsvKeys( const TextCsvKeys* merge ); TextCsvKeys( const TextCsvKeys* merge );
virtual ~TextCsvKeys(); virtual ~TextCsvKeys();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
public: public:
TextCsvKeys* clone() const; TextCsvKeys* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
}; };
}
} }
#endif // merge_TextCsvKeys_h #endif // merge_TextCsvKeys_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextSemicolon.h" #include "TextSemicolon.h"
namespace merge namespace glabels
{ {
static const QString ID = "Text/Semicolon";
namespace merge
///
/// Constructor
///
TextSemicolon::TextSemicolon() : Text(';',false)
{ {
mId = ID; static const QString ID = "Text/Semicolon";
}
/// ///
/// Constructor /// Constructor
/// ///
TextSemicolon::TextSemicolon( const TextSemicolon* merge ) : Text( merge ) TextSemicolon::TextSemicolon() : Text(';',false)
{ {
} mId = ID;
}
/// ///
/// Destructor /// Constructor
/// ///
TextSemicolon::~TextSemicolon() TextSemicolon::TextSemicolon( const TextSemicolon* merge ) : Text( merge )
{ {
} }
/// ///
/// Clone /// Destructor
/// ///
TextSemicolon* TextSemicolon::clone() const TextSemicolon::~TextSemicolon()
{ {
return new TextSemicolon( this ); }
}
/// ///
/// Get ID /// Clone
/// ///
QString TextSemicolon::id() TextSemicolon* TextSemicolon::clone() const
{ {
return ID; return new TextSemicolon( this );
} }
/// ///
/// Create /// Get ID
/// ///
Merge* TextSemicolon::create() QString TextSemicolon::id()
{ {
return new TextSemicolon(); return ID;
}
///
/// Create
///
Merge* TextSemicolon::create()
{
return new TextSemicolon();
}
} }
} }
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h" #include "Text.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// TextSemicolon Merge Backend
///
struct TextSemicolon : public Text
{ {
///
/// TextSemicolon Merge Backend
///
struct TextSemicolon : public Text
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
TextSemicolon(); TextSemicolon();
TextSemicolon( const TextSemicolon* merge ); TextSemicolon( const TextSemicolon* merge );
virtual ~TextSemicolon(); virtual ~TextSemicolon();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
public: public:
TextSemicolon* clone() const; TextSemicolon* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
}; };
}
} }
#endif // merge_TextSemicolon_h #endif // merge_TextSemicolon_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextSemicolonKeys.h" #include "TextSemicolonKeys.h"
namespace merge namespace glabels
{ {
static const QString ID = "Text/Semicolon/Keys";
namespace merge
///
/// Constructor
///
TextSemicolonKeys::TextSemicolonKeys() : Text(';',true)
{ {
mId = ID; static const QString ID = "Text/Semicolon/Keys";
}
/// ///
/// Constructor /// Constructor
/// ///
TextSemicolonKeys::TextSemicolonKeys( const TextSemicolonKeys* merge ) : Text( merge ) TextSemicolonKeys::TextSemicolonKeys() : Text(';',true)
{ {
} mId = ID;
}
/// ///
/// Destructor /// Constructor
/// ///
TextSemicolonKeys::~TextSemicolonKeys() TextSemicolonKeys::TextSemicolonKeys( const TextSemicolonKeys* merge ) : Text( merge )
{ {
} }
/// ///
/// Clone /// Destructor
/// ///
TextSemicolonKeys* TextSemicolonKeys::clone() const TextSemicolonKeys::~TextSemicolonKeys()
{ {
return new TextSemicolonKeys( this ); }
}
/// ///
/// Get ID /// Clone
/// ///
QString TextSemicolonKeys::id() TextSemicolonKeys* TextSemicolonKeys::clone() const
{ {
return ID; return new TextSemicolonKeys( this );
} }
/// ///
/// Create /// Get ID
/// ///
Merge* TextSemicolonKeys::create() QString TextSemicolonKeys::id()
{ {
return new TextSemicolonKeys(); return ID;
}
///
/// Create
///
Merge* TextSemicolonKeys::create()
{
return new TextSemicolonKeys();
}
} }
} }
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h" #include "Text.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// TextSemicolonKeys Merge Backend
///
struct TextSemicolonKeys : public Text
{ {
///
/// TextSemicolonKeys Merge Backend
///
struct TextSemicolonKeys : public Text
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
TextSemicolonKeys(); TextSemicolonKeys();
TextSemicolonKeys( const TextSemicolonKeys* merge ); TextSemicolonKeys( const TextSemicolonKeys* merge );
virtual ~TextSemicolonKeys(); virtual ~TextSemicolonKeys();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
public: public:
TextSemicolonKeys* clone() const; TextSemicolonKeys* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
}; };
}
} }
#endif // merge_TextSemicolonKeys_h #endif // merge_TextSemicolonKeys_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextTsv.h" #include "TextTsv.h"
namespace merge namespace glabels
{ {
static const QString ID = "Text/Tab";
namespace merge
{
static const QString ID = "Text/Tab";
/// ///
/// Constructor /// Constructor
/// ///
TextTsv::TextTsv() : Text('\t',false) TextTsv::TextTsv() : Text('\t',false)
{ {
mId = ID; mId = ID;
} }
/// ///
/// Constructor /// Constructor
/// ///
TextTsv::TextTsv( const TextTsv* merge ) : Text( merge ) TextTsv::TextTsv( const TextTsv* merge ) : Text( merge )
{ {
} }
/// ///
/// Destructor /// Destructor
/// ///
TextTsv::~TextTsv() TextTsv::~TextTsv()
{ {
} }
/// ///
/// Clone /// Clone
/// ///
TextTsv* TextTsv::clone() const TextTsv* TextTsv::clone() const
{ {
return new TextTsv( this ); return new TextTsv( this );
} }
/// ///
/// Get ID /// Get ID
/// ///
QString TextTsv::id() QString TextTsv::id()
{ {
return ID; return ID;
} }
/// ///
/// Create /// Create
/// ///
Merge* TextTsv::create() Merge* TextTsv::create()
{ {
return new TextTsv(); return new TextTsv();
}
} }
} }
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h" #include "Text.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// TextTsv Merge Backend
///
struct TextTsv : public Text
{ {
///
/// TextTsv Merge Backend
///
struct TextTsv : public Text
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
TextTsv(); TextTsv();
TextTsv( const TextTsv* merge ); TextTsv( const TextTsv* merge );
virtual ~TextTsv(); virtual ~TextTsv();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
public: public:
TextTsv* clone() const; TextTsv* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
}; };
}
} }
#endif // merge_TextTsv_h #endif // merge_TextTsv_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextTsvKeys.h" #include "TextTsvKeys.h"
namespace merge namespace glabels
{ {
static const QString ID = "Text/Tab/Line1Keys";
namespace merge
///
/// Constructor
///
TextTsvKeys::TextTsvKeys() : Text('\t',true)
{ {
mId = ID; static const QString ID = "Text/Tab/Line1Keys";
}
/// ///
/// Constructor /// Constructor
/// ///
TextTsvKeys::TextTsvKeys( const TextTsvKeys* merge ) : Text( merge ) TextTsvKeys::TextTsvKeys() : Text('\t',true)
{ {
} mId = ID;
}
/// ///
/// Destructor /// Constructor
/// ///
TextTsvKeys::~TextTsvKeys() TextTsvKeys::TextTsvKeys( const TextTsvKeys* merge ) : Text( merge )
{ {
} }
/// ///
/// Clone /// Destructor
/// ///
TextTsvKeys* TextTsvKeys::clone() const TextTsvKeys::~TextTsvKeys()
{ {
return new TextTsvKeys( this ); }
}
/// ///
/// Get ID /// Clone
/// ///
QString TextTsvKeys::id() TextTsvKeys* TextTsvKeys::clone() const
{ {
return ID; return new TextTsvKeys( this );
} }
/// ///
/// Create /// Get ID
/// ///
Merge* TextTsvKeys::create() QString TextTsvKeys::id()
{ {
return new TextTsvKeys(); return ID;
}
///
/// Create
///
Merge* TextTsvKeys::create()
{
return new TextTsvKeys();
}
} }
} }
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h" #include "Text.h"
namespace merge namespace glabels
{ {
/// namespace merge
/// TextTsvKeys Merge Backend
///
struct TextTsvKeys : public Text
{ {
///
/// TextTsvKeys Merge Backend
///
struct TextTsvKeys : public Text
{
///////////////////////////////// /////////////////////////////////
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
private: private:
TextTsvKeys(); TextTsvKeys();
TextTsvKeys( const TextTsvKeys* merge ); TextTsvKeys( const TextTsvKeys* merge );
virtual ~TextTsvKeys(); virtual ~TextTsvKeys();
///////////////////////////////// /////////////////////////////////
// Object duplication // Object duplication
///////////////////////////////// /////////////////////////////////
public: public:
TextTsvKeys* clone() const; TextTsvKeys* clone() const;
///////////////////////////////// /////////////////////////////////
// Static methods // Static methods
///////////////////////////////// /////////////////////////////////
public: public:
static QString id(); static QString id();
static Merge* create(); static Merge* create();
}; };
}
} }
#endif // merge_TextTsvKeys_h #endif // merge_TextTsvKeys_h
+266 -253
View File
@@ -30,289 +30,302 @@
#include "Merge/Factory.h" #include "Merge/Factory.h"
/// namespace glabels
/// Constructor
///
MergeView::MergeView( QWidget *parent )
: QWidget(parent), mModel(0), mBlock(false)
{ {
setupUi( this );
mMergeFormatNames = merge::Factory::nameList(); ///
formatCombo->addItems( mMergeFormatNames ); /// Constructor
} ///
MergeView::MergeView( QWidget *parent )
: QWidget(parent), mModel(0), mBlock(false)
///
/// Destructor
///
MergeView::~MergeView()
{
}
///
/// Set Model
///
void MergeView::setModel( LabelModel* model, UndoRedoModel* undoRedoModel )
{
mModel = model;
mUndoRedoModel = undoRedoModel;
// Initialize CWD
if ( model->fileName().isEmpty() )
{ {
mCwd = "."; setupUi( this );
}
else mMergeFormatNames = merge::Factory::nameList();
{ formatCombo->addItems( mMergeFormatNames );
mCwd = QFileInfo( model->fileName() ).absolutePath();
} }
onMergeChanged();
connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) );
}
///
/// /// Destructor
/// Merge changed handler ///
/// MergeView::~MergeView()
void MergeView::onMergeChanged()
{
int index = mMergeFormatNames.indexOf( merge::Factory::idToName( mModel->merge()->id() ) );
mOldFormatComboIndex = index;
formatCombo->setCurrentIndex( index );
switch ( merge::Factory::idToType( mModel->merge()->id() ) )
{ {
case merge::Factory::NONE: // empty
case merge::Factory::FIXED: }
locationLabel->setEnabled( false );
locationButton->setEnabled( false );
locationButton->setText( "" );
break;
case merge::Factory::FILE:
locationLabel->setEnabled( true ); ///
locationButton->setEnabled( true ); /// Set Model
if ( mModel->merge()->source().isEmpty() ) ///
void MergeView::setModel( LabelModel* model, UndoRedoModel* undoRedoModel )
{
mModel = model;
mUndoRedoModel = undoRedoModel;
// Initialize CWD
if ( model->fileName().isEmpty() )
{ {
locationButton->setText( "Select file..." ); mCwd = ".";
} }
else else
{ {
locationButton->setText( mModel->merge()->source() ); mCwd = QFileInfo( model->fileName() ).absolutePath();
} }
break;
default: onMergeChanged();
qWarning( "MergeView::onMergeChanged()::Should not be reached!" ); connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) );
break;
} }
recordsTable->clear();
recordsTable->setColumnCount( 0 );
loadHeaders( mModel->merge() );
loadTable( mModel->merge() );
connect( mModel->merge(), SIGNAL(sourceChanged()), this, SLOT(onMergeSourceChanged()) ); ///
connect( mModel->merge(), SIGNAL(selectionChanged()), this, SLOT(onMergeSelectionChanged()) ); /// Merge changed handler
///
connect( recordsTable, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)) ); void MergeView::onMergeChanged()
}
///
/// Merge source changed handler
///
void MergeView::onMergeSourceChanged()
{
locationButton->setText( mModel->merge()->source() );
recordsTable->clear();
recordsTable->setColumnCount( 0 );
loadHeaders( mModel->merge() );
loadTable( mModel->merge() );
}
///
/// Merge selection changed handler
///
void MergeView::onMergeSelectionChanged()
{
mBlock = true; // Don't recurse
const QList<merge::Record*>& records = mModel->merge()->recordList();
int iRow = 0;
foreach ( merge::Record* record, records )
{
QTableWidgetItem* item = recordsTable->item( iRow, 0 );
item->setCheckState( record->isSelected() ? Qt::Checked : Qt::Unchecked );
iRow++;
}
mBlock = false;
}
///
/// Format combo changed handler
void MergeView::onFormatComboActivated()
{
int index = formatCombo->currentIndex();
if ( index != mOldFormatComboIndex )
{ {
QString name = merge::Factory::idToName( mModel->merge()->id() );
int index = mMergeFormatNames.indexOf( name );
mOldFormatComboIndex = index; mOldFormatComboIndex = index;
formatCombo->setCurrentIndex( index );
mModel->setMerge( merge::Factory::createMerge( merge::Factory::indexToId(index) ) ); switch ( merge::Factory::idToType( mModel->merge()->id() ) )
}
}
///
/// Location button clicked handler
///
void MergeView::onLocationButtonClicked()
{
QString fileName =
QFileDialog::getOpenFileName( this,
tr("Select merge file"),
mCwd,
tr("All files (*)") );
if ( !fileName.isEmpty() )
{
mModel->merge()->setSource( fileName );
mCwd = QFileInfo( fileName ).absolutePath(); // Update CWD
}
}
///
/// Select all button clicked handler
///
void MergeView::onSelectAllButtonClicked()
{
mModel->merge()->selectAll();
}
///
/// Unselect all button clicked handler
///
void MergeView::onUnselectAllButtonClicked()
{
mModel->merge()->unselectAll();
}
///
/// Cell changed handler
///
void MergeView::onCellChanged( int iRow, int iCol )
{
if ( !mBlock )
{
QTableWidgetItem* item = recordsTable->item( iRow, 0 );
bool state = (item->checkState() == Qt::Unchecked) ? false : true;
mModel->merge()->setSelected( iRow, state );
}
}
///
/// Load headers
///
void MergeView::loadHeaders( merge::Merge* merge )
{
mPrimaryKey = merge->primaryKey();
mKeys = merge->keys();
if ( mKeys.size() > 0 )
{
recordsTable->setColumnCount( mKeys.size() + 1 ); // Include extra column
// First column = primay Key
QTableWidgetItem* item = new QTableWidgetItem( mPrimaryKey );
item->setFlags( Qt::ItemIsEnabled );
recordsTable->setHorizontalHeaderItem( 0, item );
// Starting on second column, one column per key, skip primary Key
int iCol = 1;
foreach ( QString key, mKeys )
{ {
if ( key != mPrimaryKey ) case merge::Factory::NONE:
{ case merge::Factory::FIXED:
QTableWidgetItem* item = new QTableWidgetItem( key ); locationLabel->setEnabled( false );
item->setFlags( Qt::ItemIsEnabled ); locationButton->setEnabled( false );
recordsTable->setHorizontalHeaderItem( iCol, item ); locationButton->setText( "" );
break;
iCol++; case merge::Factory::FILE:
locationLabel->setEnabled( true );
locationButton->setEnabled( true );
if ( mModel->merge()->source().isEmpty() )
{
locationButton->setText( "Select file..." );
} }
else
}
// Extra dummy column to fill any extra horizontal space
QTableWidgetItem* fillItem = new QTableWidgetItem();
fillItem->setFlags( Qt::NoItemFlags );
recordsTable->setHorizontalHeaderItem( iCol, fillItem );
recordsTable->horizontalHeader()->setStretchLastSection( true );
}
}
///
/// Load table
///
void MergeView::loadTable( merge::Merge* merge )
{
mBlock = true;
const QList<merge::Record*>& records = merge->recordList();
recordsTable->setRowCount( records.size() );
int iRow = 0;
foreach ( merge::Record* record, records )
{
// First column for primay field
QTableWidgetItem* item = new QTableWidgetItem();
if ( record->contains( mPrimaryKey ) )
{
item->setText( (*record)[mPrimaryKey] );
}
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
item->setCheckState( record->isSelected() ? Qt::Checked : Qt::Unchecked );
recordsTable->setItem( iRow, 0, item );
recordsTable->resizeColumnToContents( 0 );
// Starting on second column, one column per field (even if empty), skip primary field
int iCol = 1;
foreach ( QString key, mKeys )
{
if ( key != mPrimaryKey )
{ {
if ( record->contains( key ) ) locationButton->setText( mModel->merge()->source() );
}
break;
default:
qWarning( "MergeView::onMergeChanged()::Should not be reached!" );
break;
}
recordsTable->clear();
recordsTable->setColumnCount( 0 );
loadHeaders( mModel->merge() );
loadTable( mModel->merge() );
connect( mModel->merge(), SIGNAL(sourceChanged()),
this, SLOT(onMergeSourceChanged()) );
connect( mModel->merge(), SIGNAL(selectionChanged()),
this, SLOT(onMergeSelectionChanged()) );
connect( recordsTable, SIGNAL(cellChanged(int,int)),
this, SLOT(onCellChanged(int,int)) );
}
///
/// Merge source changed handler
///
void MergeView::onMergeSourceChanged()
{
locationButton->setText( mModel->merge()->source() );
recordsTable->clear();
recordsTable->setColumnCount( 0 );
loadHeaders( mModel->merge() );
loadTable( mModel->merge() );
}
///
/// Merge selection changed handler
///
void MergeView::onMergeSelectionChanged()
{
mBlock = true; // Don't recurse
const QList<merge::Record*>& records = mModel->merge()->recordList();
int iRow = 0;
foreach ( merge::Record* record, records )
{
QTableWidgetItem* item = recordsTable->item( iRow, 0 );
item->setCheckState( record->isSelected() ? Qt::Checked : Qt::Unchecked );
iRow++;
}
mBlock = false;
}
///
/// Format combo changed handler
///
void MergeView::onFormatComboActivated()
{
int index = formatCombo->currentIndex();
if ( index != mOldFormatComboIndex )
{
mOldFormatComboIndex = index;
QString id = merge::Factory::indexToId(index);
mModel->setMerge( merge::Factory::createMerge( id ) );
}
}
///
/// Location button clicked handler
///
void MergeView::onLocationButtonClicked()
{
QString fileName =
QFileDialog::getOpenFileName( this,
tr("Select merge file"),
mCwd,
tr("All files (*)") );
if ( !fileName.isEmpty() )
{
mModel->merge()->setSource( fileName );
mCwd = QFileInfo( fileName ).absolutePath(); // Update CWD
}
}
///
/// Select all button clicked handler
///
void MergeView::onSelectAllButtonClicked()
{
mModel->merge()->selectAll();
}
///
/// Unselect all button clicked handler
///
void MergeView::onUnselectAllButtonClicked()
{
mModel->merge()->unselectAll();
}
///
/// Cell changed handler
///
void MergeView::onCellChanged( int iRow, int iCol )
{
if ( !mBlock )
{
QTableWidgetItem* item = recordsTable->item( iRow, 0 );
bool state = (item->checkState() == Qt::Unchecked) ? false : true;
mModel->merge()->setSelected( iRow, state );
}
}
///
/// Load headers
///
void MergeView::loadHeaders( merge::Merge* merge )
{
mPrimaryKey = merge->primaryKey();
mKeys = merge->keys();
if ( mKeys.size() > 0 )
{
recordsTable->setColumnCount( mKeys.size() + 1 ); // Include extra column
// First column = primay Key
QTableWidgetItem* item = new QTableWidgetItem( mPrimaryKey );
item->setFlags( Qt::ItemIsEnabled );
recordsTable->setHorizontalHeaderItem( 0, item );
// Starting on second column, one column per key, skip primary Key
int iCol = 1;
foreach ( QString key, mKeys )
{
if ( key != mPrimaryKey )
{ {
QTableWidgetItem* item = new QTableWidgetItem( (*record)[key] ); QTableWidgetItem* item = new QTableWidgetItem( key );
item->setFlags( Qt::ItemIsEnabled ); item->setFlags( Qt::ItemIsEnabled );
recordsTable->setItem( iRow, iCol, item ); recordsTable->setHorizontalHeaderItem( iCol, item );
recordsTable->resizeColumnToContents( iCol );
iCol++;
} }
iCol++;
} }
// Extra dummy column to fill any extra horizontal space
QTableWidgetItem* fillItem = new QTableWidgetItem();
fillItem->setFlags( Qt::NoItemFlags );
recordsTable->setHorizontalHeaderItem( iCol, fillItem );
recordsTable->horizontalHeader()->setStretchLastSection( true );
} }
// Extra dummy column to fill any extra horizontal space
QTableWidgetItem* fillItem = new QTableWidgetItem();
fillItem->setFlags( Qt::NoItemFlags );
recordsTable->setItem( iRow, iCol, fillItem );
iRow++;
} }
mBlock = false;
///
/// Load table
///
void MergeView::loadTable( merge::Merge* merge )
{
mBlock = true;
const QList<merge::Record*>& records = merge->recordList();
recordsTable->setRowCount( records.size() );
int iRow = 0;
foreach ( merge::Record* record, records )
{
// First column for primay field
QTableWidgetItem* item = new QTableWidgetItem();
if ( record->contains( mPrimaryKey ) )
{
item->setText( (*record)[mPrimaryKey] );
}
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
item->setCheckState( record->isSelected() ? Qt::Checked : Qt::Unchecked );
recordsTable->setItem( iRow, 0, item );
recordsTable->resizeColumnToContents( 0 );
// Starting on 2nd column, 1 column per field, skip primary field
int iCol = 1;
foreach ( QString key, mKeys )
{
if ( key != mPrimaryKey )
{
if ( record->contains( key ) )
{
QTableWidgetItem* item = new QTableWidgetItem( (*record)[key] );
item->setFlags( Qt::ItemIsEnabled );
recordsTable->setItem( iRow, iCol, item );
recordsTable->resizeColumnToContents( iCol );
}
iCol++;
}
}
// Extra dummy column to fill any extra horizontal space
QTableWidgetItem* fillItem = new QTableWidgetItem();
fillItem->setFlags( Qt::NoItemFlags );
recordsTable->setItem( iRow, iCol, fillItem );
iRow++;
}
mBlock = false;
}
} }
+66 -60
View File
@@ -26,74 +26,80 @@
#include "Merge/Merge.h" #include "Merge/Merge.h"
// Forward references
class LabelModel;
class UndoRedoModel;
/// namespace glabels
/// merge::Merge Property Editor Widget
///
class MergeView : public QWidget, public Ui_MergeView
{ {
Q_OBJECT
// Forward references
///////////////////////////////// class LabelModel;
// Life Cycle class UndoRedoModel;
/////////////////////////////////
public:
MergeView( QWidget *parent = 0 );
~MergeView();
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( LabelModel* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMergeChanged();
void onMergeSourceChanged();
void onMergeSelectionChanged();
void onFormatComboActivated();
void onLocationButtonClicked();
void onSelectAllButtonClicked();
void onUnselectAllButtonClicked();
void onCellChanged( int iRow, int iCol );
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadHeaders( merge::Merge* merge );
void loadTable( merge::Merge* merge );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QStringList mMergeFormatNames;
LabelModel* mModel;
UndoRedoModel* mUndoRedoModel;
QStringList mKeys; ///
QString mPrimaryKey; /// merge::Merge Property Editor Widget
///
class MergeView : public QWidget, public Ui_MergeView
{
Q_OBJECT
QString mCwd;
bool mBlock; /////////////////////////////////
int mOldFormatComboIndex; // Life Cycle
/////////////////////////////////
public:
MergeView( QWidget *parent = 0 );
~MergeView();
};
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( LabelModel* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMergeChanged();
void onMergeSourceChanged();
void onMergeSelectionChanged();
void onFormatComboActivated();
void onLocationButtonClicked();
void onSelectAllButtonClicked();
void onUnselectAllButtonClicked();
void onCellChanged( int iRow, int iCol );
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadHeaders( merge::Merge* merge );
void loadTable( merge::Merge* merge );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QStringList mMergeFormatNames;
LabelModel* mModel;
UndoRedoModel* mUndoRedoModel;
QStringList mKeys;
QString mPrimaryKey;
QString mCwd;
bool mBlock;
int mOldFormatComboIndex;
};
}
#endif // MergeView_h #endif // MergeView_h

Some files were not shown because too many files have changed in this diff Show More