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.
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
@@ -87,6 +118,7 @@ All header files should have an ifndef guard to prevent multiple inclusion.
#endif // ns_Module_h
```
### Include Directives
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
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"
///
/// Constructor
///
AboutDialog::AboutDialog( QWidget *parent )
: QDialog(parent)
namespace glabels
{
setupUi( this );
QString version = tr("Version") + " " + Version::STRING;
QString description = tr("A program to create labels and business cards.");
QString copyright = "Copyright &copy; 2017 Jim Evins <evins@snaught.com>";
QString licenseParagraph1 =
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." );
///
/// Constructor
///
AboutDialog::AboutDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
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 version = tr("Version") + " " + Version::STRING;
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>";
QString description = tr("A program to create labels and business cards.");
QString copyright = "Copyright &copy; 2017 Jim Evins <evins@snaught.com>";
QString licenseParagraph1 =
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"
///
/// About Dialog Widget
///
class AboutDialog : public QDialog, public Ui_AboutDialog
namespace glabels
{
Q_OBJECT
///
/// About Dialog Widget
///
class AboutDialog : public QDialog, public Ui_AboutDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
AboutDialog( QWidget *parent = 0 );
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
AboutDialog( QWidget *parent = 0 );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onLicenseButtonClicked();
void onWebsiteButtonClicked();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onLicenseButtonClicked();
void onWebsiteButtonClicked();
};
};
}
#endif // AboutDialog_h
+125 -121
View File
@@ -21,159 +21,163 @@
#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::BackendMap BarcodeBackends::mBackendNameMap;
BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap;
BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap;
BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap;
BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap;
QList<QString> BarcodeBackends::mBackendNameList;
QList<QString> BarcodeBackends::mNameList;
QList<QString> BarcodeBackends::mBackendNameList;
QList<QString> BarcodeBackends::mNameList;
BarcodeBackends::BarcodeBackends()
{
registerStyle( "postnet", "", tr("POSTNET (any)"),
false, false, true, false, "12345-6789-12", false, 11 );
BarcodeBackends::BarcodeBackends()
{
registerStyle( "postnet", "", tr("POSTNET (any)"),
false, false, true, false, "12345-6789-12", false, 11 );
registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"),
false, false, true, false, "12345", false, 5 );
registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"),
false, false, true, false, "12345", false, 5 );
registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"),
false, false, true, false, "12345-6789", false, 9 );
registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"),
false, false, true, false, "12345-6789", false, 9 );
registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"),
false, false, true, false, "12345-6789-12", false, 11 );
registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"),
false, false, true, false, "12345-6789-12", false, 11 );
registerStyle( "cepnet", "", tr("CEPNET"),
false, false, true, false, "12345-678", false, 8 );
registerStyle( "cepnet", "", tr("CEPNET"),
false, false, true, false, "12345-678", false, 8 );
registerStyle( "onecode", "", tr("USPS Intelligent Mail"),
false, false, true, false, "12345678901234567890", false, 20 );
registerStyle( "onecode", "", tr("USPS Intelligent Mail"),
false, false, true, false, "12345678901234567890", false, 20 );
registerStyle( "code39", "", tr("Code 39"),
true, true, true, true, "1234567890", true, 10 );
registerStyle( "code39", "", tr("Code 39"),
true, true, true, true, "1234567890", true, 10 );
registerStyle( "code39ext", "", tr("Code 39 Extended"),
true, true, true, true, "1234567890", true, 10 );
registerStyle( "code39ext", "", tr("Code 39 Extended"),
true, true, true, true, "1234567890", true, 10 );
registerStyle( "upc-A", "", tr("UPC-A"),
true, false, true, false, "12345678901", false, 11 );
registerStyle( "upc-A", "", tr("UPC-A"),
true, false, true, false, "12345678901", false, 11 );
registerStyle( "ean-13", "", tr("EAN-13"),
true, false, true, false, "123456789012", false, 12 );
registerStyle( "ean-13", "", tr("EAN-13"),
true, false, true, false, "123456789012", false, 12 );
registerStyle( "datamatrix", "", tr("DataMatrix"),
false, false, true, false, "1234567890AB", false, 12 );
registerStyle( "datamatrix", "", tr("DataMatrix"),
false, false, true, false, "1234567890AB", false, 12 );
registerStyle( "qrcode", "", tr("QRCode"),
false, false, true, false, "1234567890AB", false, 12 );
}
registerStyle( "qrcode", "", tr("QRCode"),
false, false, true, false, "1234567890AB", false, 12 );
}
void BarcodeBackends::init( void )
{
static BarcodeBackends* singletonInstance = NULL;
void BarcodeBackends::init( void )
{
static BarcodeBackends* singletonInstance = NULL;
if ( singletonInstance == NULL )
{
singletonInstance = new BarcodeBackends();
if ( singletonInstance == NULL )
{
singletonInstance = new BarcodeBackends();
}
}
}
QString BarcodeBackends::BackendIdToName( const QString& backendId )
{
BackendMap::iterator i = mBackendIdMap.find( backendId );
if ( i != mBackendIdMap.end() )
QString BarcodeBackends::BackendIdToName( const QString& backendId )
{
return i.value();
}
BackendMap::iterator i = mBackendIdMap.find( backendId );
if ( i != mBackendIdMap.end() )
{
return i.value();
}
return "";
}
QString BarcodeBackends::BackendNameToId( const QString& backendName )
{
BackendMap::iterator i = mBackendNameMap.find( backendName );
if ( i != mBackendNameMap.end() )
{
return i.value();
return "";
}
return "";
}
const QList<QString>& BarcodeBackends::getBackendNameList()
{
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() )
QString BarcodeBackends::BackendNameToId( const QString& backendName )
{
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 )
{
StyleMap::iterator i = mStyleNameMap.find( name );
if ( i != mStyleNameMap.end() )
const QList<QString>& BarcodeBackends::getBackendNameList()
{
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;
}
void BarcodeBackends::registerBackend( QString& id, QString& name)
{
mBackendNameList.append( name );
mBackendIdMap.insert( id, name );
mBackendNameMap.insert( name, id );
}
void BarcodeBackends::registerStyle( const char* id,
const char* backendId,
const QString& name,
bool canText,
bool textOptional,
bool canChecksum,
bool checksumOptional,
const char* defaultDigits,
bool canFreeForm,
int preferedN )
{
BarcodeStyle* style = new BarcodeStyle( QString(id), QString(backendId), name,
canText, textOptional,
canChecksum, checksumOptional,
QString(defaultDigits), canFreeForm, preferedN );
QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique
mNameList.append( name );
mStyleIdMap.insert( id, style );
mStyleNameMap.insert( fqName, style );
return 0;
}
const BarcodeStyle* BarcodeBackends::lookupStyleFromName( const QString& name )
{
StyleMap::iterator i = mStyleNameMap.find( name );
if ( i != mStyleNameMap.end() )
{
return i.value();
}
return 0;
}
void BarcodeBackends::registerBackend( QString& id, QString& name)
{
mBackendNameList.append( name );
mBackendIdMap.insert( id, name );
mBackendNameMap.insert( name, id );
}
void BarcodeBackends::registerStyle( const char* id,
const char* backendId,
const QString& name,
bool canText,
bool textOptional,
bool canChecksum,
bool checksumOptional,
const char* defaultDigits,
bool canFreeForm,
int preferedN )
{
BarcodeStyle* style = new BarcodeStyle( QString(id), QString(backendId), name,
canText, textOptional,
canChecksum, checksumOptional,
QString(defaultDigits),
canFreeForm, preferedN );
QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique
mNameList.append( name );
mStyleIdMap.insert( id, style );
mStyleNameMap.insert( fqName, style );
}
}
+53 -48
View File
@@ -30,68 +30,73 @@
#include "BarcodeStyle.h"
///
/// Barcode Backends Database
///
class BarcodeBackends : public QObject
namespace glabels
{
///
/// Barcode Backends Database
///
class BarcodeBackends : public QObject
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
BarcodeBackends();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
BarcodeBackends();
public:
static void init( void );
public:
static void init( void );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
static QString BackendIdToName( const QString& backendId );
static QString BackendNameToId( const QString& backendName );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
static QString BackendIdToName( const QString& backendId );
static QString BackendNameToId( const QString& backendName );
static const QList<QString>& getBackendNameList();
static const QList<QString>& getNameList();
static const QList<QString>& getBackendNameList();
static const QList<QString>& getNameList();
static const BarcodeStyle* lookupStyleFromId( const QString& id );
static const BarcodeStyle* lookupStyleFromName( const QString& name );
static const BarcodeStyle* lookupStyleFromId( const QString& id );
static const BarcodeStyle* lookupStyleFromName( const QString& name );
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
static void registerBackend( QString &id, QString &name);
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
static void registerBackend( QString &id, QString &name);
static void registerStyle( const char* id,
const char* backendId,
const QString& name,
bool canText,
bool textOptional,
bool canChecksum,
bool checksumOptional,
const char* defaultDigits,
bool canFreeForm,
int preferedN );
static void registerStyle( const char* id,
const char* backendId,
const QString& name,
bool canText,
bool textOptional,
bool canChecksum,
bool checksumOptional,
const char* defaultDigits,
bool canFreeForm,
int preferedN );
/////////////////////////////////
// Private Members
/////////////////////////////////
typedef QMap<QString,QString> BackendMap;
static BackendMap mBackendIdMap;
static BackendMap mBackendNameMap;
/////////////////////////////////
// Private Members
/////////////////////////////////
typedef QMap<QString,QString> BackendMap;
static BackendMap mBackendIdMap;
static BackendMap mBackendNameMap;
typedef QMap<QString,BarcodeStyle*> StyleMap;
static StyleMap mStyleIdMap;
static StyleMap mStyleNameMap;
typedef QMap<QString,BarcodeStyle*> StyleMap;
static StyleMap mStyleIdMap;
static StyleMap mStyleNameMap;
static QList<QString> mBackendNameList;
static QList<QString> mNameList;
static QList<QString> mBackendNameList;
static QList<QString> mNameList;
};
};
}
#endif // BarcodeBackends_h
+34 -29
View File
@@ -25,38 +25,43 @@
#include "BarcodeMenuItem.h"
///
/// Constructor
///
BarcodeMenu::BarcodeMenu()
namespace glabels
{
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 );
connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) );
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) );
addAction( bcMenuItem );
addAction( bcMenuItem );
}
}
}
///
/// bcStyle getter
///
const BarcodeStyle* BarcodeMenu::bcStyle() const
{
return mBcStyle;
}
///
/// onMenuItemActivated slot
///
void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle )
{
mBcStyle = bcStyle;
emit styleChanged();
///
/// bcStyle getter
///
const BarcodeStyle* BarcodeMenu::bcStyle() const
{
return mBcStyle;
}
///
/// onMenuItemActivated slot
///
void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle )
{
mBcStyle = bcStyle;
emit styleChanged();
}
}
+36 -31
View File
@@ -27,48 +27,53 @@
#include "BarcodeStyle.h"
///
/// Barcode Menu
///
class BarcodeMenu : public QMenu
namespace glabels
{
Q_OBJECT
///
/// Barcode Menu
///
class BarcodeMenu : public QMenu
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenu();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenu();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void styleChanged();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void styleChanged();
/////////////////////////////////
// Properties
/////////////////////////////////
public:
const BarcodeStyle* bcStyle() const;
/////////////////////////////////
// Properties
/////////////////////////////////
public:
const BarcodeStyle* bcStyle() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuItemActivated( BarcodeStyle *bcStyle );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuItemActivated( BarcodeStyle *bcStyle );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
BarcodeStyle* mBcStyle;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
BarcodeStyle* mBcStyle;
};
};
}
#endif // BarcodeMenu_h
+36 -31
View File
@@ -25,38 +25,43 @@
#include "BarcodeMenuItem.h"
///
/// Constructor
///
BarcodeMenuButton::BarcodeMenuButton( QWidget* parent )
: QPushButton(parent)
namespace glabels
{
mMenu = new BarcodeMenu();
setMenu( mMenu );
///
/// Constructor
///
BarcodeMenuButton::BarcodeMenuButton( QWidget* parent )
: QPushButton(parent)
{
mMenu = new BarcodeMenu();
setMenu( mMenu );
mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style
setText( mBcStyle->name() );
mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style
setText( mBcStyle->name() );
connect( mMenu, SIGNAL(styleChanged()), this, SLOT(onMenuStyleChanged()) );
}
///
/// bcStyle getter
///
const BarcodeStyle* BarcodeMenuButton::bcStyle() const
{
return mBcStyle;
}
///
/// onMenuStyleChanged slot
///
void BarcodeMenuButton::onMenuStyleChanged()
{
mBcStyle = mMenu->bcStyle();
setText( mBcStyle->name() );
emit styleChanged();
}
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"
///
/// Barcode Menu Button
///
class BarcodeMenuButton : public QPushButton
namespace glabels
{
Q_OBJECT
///
/// Barcode Menu Button
///
class BarcodeMenuButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenuButton( QWidget* parent = 0 );
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenuButton( QWidget* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void styleChanged();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void styleChanged();
/////////////////////////////////
// Properties
/////////////////////////////////
public:
const BarcodeStyle* bcStyle() const;
/////////////////////////////////
// Properties
/////////////////////////////////
public:
const BarcodeStyle* bcStyle() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuStyleChanged();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuStyleChanged();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
BarcodeMenu* mMenu;
const BarcodeStyle* mBcStyle;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
BarcodeMenu* mMenu;
const BarcodeStyle* mBcStyle;
};
};
}
#endif // BarcodeMenuButton_h
+30 -25
View File
@@ -21,31 +21,36 @@
#include "BarcodeMenuItem.h"
///
/// Constructor From Data
///
BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent )
: QAction(parent), mBcStyle(bcStyle)
namespace glabels
{
setText( bcStyle->name() );
connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) );
}
///
/// bcStyle Property Getter
///
const BarcodeStyle* BarcodeMenuItem::bcStyle() const
{
return mBcStyle;
}
///
/// onTriggered slot
///
void BarcodeMenuItem::onTriggered()
{
emit activated( mBcStyle );
///
/// Constructor From Data
///
BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent )
: QAction(parent), mBcStyle(bcStyle)
{
setText( bcStyle->name() );
connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) );
}
///
/// bcStyle Property Getter
///
const BarcodeStyle* BarcodeMenuItem::bcStyle() const
{
return mBcStyle;
}
///
/// onTriggered slot
///
void BarcodeMenuItem::onTriggered()
{
emit activated( mBcStyle );
}
}
+36 -31
View File
@@ -27,48 +27,53 @@
#include "BarcodeStyle.h"
///
/// Barcode Menu Item
///
class BarcodeMenuItem : public QAction
namespace glabels
{
Q_OBJECT
///
/// Barcode Menu Item
///
class BarcodeMenuItem : public QAction
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = 0 );
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( const BarcodeStyle* bcStyle );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( const BarcodeStyle* bcStyle );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
const BarcodeStyle* bcStyle() const;
/////////////////////////////////
// Properties
/////////////////////////////////
public:
const BarcodeStyle* bcStyle() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onTriggered();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onTriggered();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
const BarcodeStyle* mBcStyle;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
const BarcodeStyle* mBcStyle;
};
};
}
#endif // BarcodeMenuItem_h
+137 -130
View File
@@ -21,37 +21,41 @@
#include "BarcodeStyle.h"
///
/// Default Constructor
///
BarcodeStyle::BarcodeStyle ()
: mId( "" ),
mBackendId( "" ),
mName( "" ),
mCanText( false ),
mTextOptional( false ),
mCanChecksum( false ),
mChecksumOptional( false ),
mDefaultDigits( "" ),
mCanFreeform( false ),
mPreferedN( 0 )
namespace glabels
{
}
///
/// Default Constructor
///
BarcodeStyle::BarcodeStyle ()
: mId( "" ),
mBackendId( "" ),
mName( "" ),
mCanText( false ),
mTextOptional( false ),
mCanChecksum( false ),
mChecksumOptional( false ),
mDefaultDigits( "" ),
mCanFreeform( false ),
mPreferedN( 0 )
{
// empty
}
///
/// Constructor From Data
///
BarcodeStyle::BarcodeStyle ( const QString& id,
const QString& backendId,
const QString& name,
bool canText,
bool textOptional,
bool canChecksum,
bool checksumOptional,
const QString& defaultDigits,
bool canFreeform,
int preferedN )
///
/// Constructor From Data
///
BarcodeStyle::BarcodeStyle ( const QString& id,
const QString& backendId,
const QString& name,
bool canText,
bool textOptional,
bool canChecksum,
bool checksumOptional,
const QString& defaultDigits,
bool canFreeform,
int preferedN )
: mId( id ),
mBackendId( backendId ),
mName( name ),
@@ -62,111 +66,114 @@ BarcodeStyle::BarcodeStyle ( const QString& id,
mDefaultDigits( defaultDigits ),
mCanFreeform( canFreeform ),
mPreferedN( preferedN )
{
}
///
/// ID Property Getter
///
const QString& BarcodeStyle::id() const
{
return mId;
}
///
/// Backend ID Property Getter
///
const QString& BarcodeStyle::backendId() const
{
return mBackendId;
}
///
/// Name Property Getter
///
const QString& BarcodeStyle::name() const
{
return mName;
}
///
/// Can Text Property Getter
///
bool BarcodeStyle::canText() const
{
return mCanText;
}
///
/// Text Optional Property Getter
///
bool BarcodeStyle::textOptional() const
{
return mTextOptional;
}
///
/// Can Checksum Property Getter
///
bool BarcodeStyle::canChecksum() const
{
return mCanChecksum;
}
///
/// Checksum Optional Property Getter
///
bool BarcodeStyle::checksumOptional() const
{
return mChecksumOptional;
}
///
/// Default Digits Property Getter
///
const QString& BarcodeStyle::defaultDigits() const
{
return mDefaultDigits;
}
///
/// Can Freeform Property Getter
///
bool BarcodeStyle::canFreeform() const
{
return mCanFreeform;
}
///
/// Prefered N Property Getter
///
int BarcodeStyle::preferedN() const
{
return mPreferedN;
}
///
/// Generate Example Digits
///
QString BarcodeStyle::exampleDigits( int n ) const
{
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;
}
///
/// 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>
///
/// Barcode Style Type
///
struct BarcodeStyle
namespace glabels
{
///
/// Barcode Style Type
///
struct BarcodeStyle
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeStyle ();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeStyle ();
BarcodeStyle ( const QString& id,
const QString& backendId,
const QString& name,
bool canText,
bool textOptional,
bool canChecksum,
bool checksumOptional,
const QString& defaultDigits,
bool canFreeform,
int preferedN );
BarcodeStyle ( const QString& id,
const QString& backendId,
const QString& name,
bool canText,
bool textOptional,
bool canChecksum,
bool checksumOptional,
const QString& defaultDigits,
bool canFreeform,
int preferedN );
/////////////////////////////////
// Properties
/////////////////////////////////
const QString& id() const;
/////////////////////////////////
// Properties
/////////////////////////////////
const QString& id() const;
const QString& backendId() const;
const QString& backendId() const;
const QString& name() const;
const QString& name() const;
bool canText() const;
bool canText() const;
bool textOptional() const;
bool textOptional() const;
bool canChecksum() const;
bool canChecksum() const;
bool checksumOptional() const;
bool checksumOptional() const;
const QString& defaultDigits() const;
const QString& defaultDigits() const;
bool canFreeform() const;
bool canFreeform() const;
int preferedN() const;
int preferedN() const;
/////////////////////////////////
// Methods
/////////////////////////////////
public:
QString exampleDigits( int n ) const;
/////////////////////////////////
// Methods
/////////////////////////////////
public:
QString exampleDigits( int n ) const;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QString mId;
QString mBackendId;
QString mName;
bool mCanText;
bool mTextOptional;
bool mCanChecksum;
bool mChecksumOptional;
QString mDefaultDigits;
bool mCanFreeform;
int mPreferedN;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QString mId;
QString mBackendId;
QString mName;
bool mCanText;
bool mTextOptional;
bool mCanChecksum;
bool mChecksumOptional;
QString mDefaultDigits;
bool mCanFreeform;
int mPreferedN;
};
};
}
#endif // BarcodeStyle_h
+1
View File
@@ -27,6 +27,7 @@ namespace glabels
Category::Category( const QString &id, const QString &name )
: mId(id), mName(name)
{
// empty
}
+141 -130
View File
@@ -28,148 +28,159 @@
#include "ColorSwatch.h"
namespace
namespace glabels
{
const int SWATCH_W = 64;
const int SWATCH_H = 24;
}
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() )
//
// Private
//
namespace
{
setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) );
const int SWATCH_W = 64;
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( "" );
}
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( "" );
}
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 )
void ColorButton::setToDefault()
{
///
/// @TODO: improve positioning of dialog -- near edges of screen.
///
QPoint dialogPos( 0, height() );
mDialog->move( mapToGlobal(dialogPos) );
mIsDefault = true;
mDialog->show();
}
}
mColorNode.setField( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
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() ) ) );
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 )
{
///
/// @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"
///
/// Color Button
///
class ColorButton : public QPushButton
namespace glabels
{
Q_OBJECT
///
/// Color Button
///
class ColorButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorButton( QWidget* parent = 0 );
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorButton( QWidget* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color );
void setColorNode( ColorNode colorNode );
void setColor( QColor color );
void setToDefault();
ColorNode colorNode();
void setKeys( const QList<QString> keyList );
void clearKeys();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color );
void setColorNode( ColorNode colorNode );
void setColor( QColor color );
void setToDefault();
ColorNode colorNode();
void setKeys( const QList<QString> keyList );
void clearKeys();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onButtonToggled( bool checked );
void onPaletteDialogAccepted();
void onPaletteDialogRejected();
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onButtonToggled( bool checked );
void onPaletteDialogAccepted();
void onPaletteDialogRejected();
void onPaletteDialogChanged( ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
bool mIsDefault;
ColorNode mColorNode;
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
bool mIsDefault;
ColorNode mColorNode;
ColorPaletteDialog* mDialog;
};
ColorPaletteDialog* mDialog;
};
}
#endif // ColorButton_h
+72 -66
View File
@@ -25,89 +25,95 @@
#include <QtDebug>
ColorHistory::ColorHistory()
namespace glabels
{
}
ColorHistory* ColorHistory::instance()
{
static ColorHistory* singletonInstance = 0;
if ( singletonInstance == 0 )
ColorHistory::ColorHistory()
{
singletonInstance = new ColorHistory();
// empty
}
return singletonInstance;
}
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 )
ColorHistory* ColorHistory::instance()
{
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();
}
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 );
emit changed();
}
// Remove oldest colors, if size exceeds current max
while ( colorList.size() > MAX_COLORS )
QList<QColor> ColorHistory::getColors()
{
colorList.removeFirst();
return readColorList();
}
return colorList;
}
void ColorHistory::writeColorList( const QList<QColor>& colorList )
{
// Build name list
QStringList colorNameList;
foreach ( QColor color, colorList )
QList<QColor> ColorHistory::readColorList()
{
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>
///
/// Color History
///
class ColorHistory : public QObject
namespace glabels
{
Q_OBJECT
public:
static const int MAX_COLORS = 9;
///
/// Color History
///
class ColorHistory : public QObject
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
ColorHistory();
public:
static const int MAX_COLORS = 9;
public:
static ColorHistory* instance();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
ColorHistory();
public:
static ColorHistory* instance();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void changed();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void changed();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void addColor( const QColor &color );
QList<QColor> getColors();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void addColor( const QColor &color );
QList<QColor> getColors();
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
QList<QColor> readColorList();
void writeColorList( const QList<QColor>& colorList );
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
QList<QColor> readColorList();
void writeColorList( const QList<QColor>& colorList );
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
};
};
}
#endif // ColorHistory_h
+169 -160
View File
@@ -24,171 +24,180 @@
#include "Merge/Record.h"
///
/// Default Constructor
///
ColorNode::ColorNode()
: mIsField(false), mColor(QColor::fromRgba(0x00000000)), mKey("")
namespace glabels
{
}
///
/// Constructor From Data
///
ColorNode::ColorNode( bool isField, const QColor& color, const QString& key )
: 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 )
///
/// Default Constructor
///
ColorNode::ColorNode()
: mIsField(false), mColor(QColor::fromRgba(0x00000000)), mKey("")
{
if ( record == 0 )
{
return mColor;
}
else
{
if ( record->contains( mKey ) )
{
return QColor( (*record)[ mKey ] );
}
else
{
return mColor;
}
}
// empty
}
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;
}
///
/// 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"
///
/// Color Node Type
///
struct ColorNode
namespace glabels
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorNode();
///
/// Color Node Type
///
struct 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
/////////////////////////////////
public:
bool operator==( const ColorNode& cn );
/////////////////////////////////
// Operators
/////////////////////////////////
public:
bool operator==( const ColorNode& cn );
bool operator!=( const ColorNode& cn );
bool operator!=( const ColorNode& cn );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
//
// Field Flag Property
//
bool isField() const;
void setField( bool isField );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
//
// Field Flag Property
//
bool isField() const;
void setField( bool isField );
//
// Color Property
//
const QColor& color() const;
void setColor( const QColor& color );
//
// Color Property
//
const QColor& color() const;
void setColor( const QColor& color );
//
// Key Property
//
const QString& key() const;
void setKey( const QString& key );
//
// Key Property
//
const QString& key() const;
void setKey( const QString& key );
/////////////////////////////////
// Misc. Methods
/////////////////////////////////
public:
uint32_t rgba() const;
QColor color( merge::Record* record ) const;
/////////////////////////////////
// Misc. Methods
/////////////////////////////////
public:
uint32_t rgba() const;
QColor color( merge::Record* record ) const;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
bool mIsField;
QColor mColor;
QString mKey;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
bool mIsField;
QColor mColor;
QString mKey;
};
};
}
#endif // ColorNode_h
+81 -76
View File
@@ -25,96 +25,101 @@
#include <QPainter>
//
// Private Configuration Data
//
namespace
namespace glabels
{
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() );
gradient.setColorAt( 0, palette().color( QPalette::Highlight ).lighter() );
gradient.setColorAt( 1, palette().color( QPalette::Highlight ) );
painter.setBrush( QBrush( gradient ) );
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
//
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 ) );
pen.setWidth( outlineWidthPixels );
painter.setPen( pen );
QPen pen( palette().color( QPalette::Text ) );
pen.setWidth( outlineWidthPixels );
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
///
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
{
emit activated();
///
/// Mouse Press Event
///
void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event )
{
emit activated();
}
}
+35 -30
View File
@@ -26,45 +26,50 @@
#include <QWidget>
///
/// Color Palette Item
///
class ColorPaletteButtonItem : public QWidget
namespace glabels
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteButtonItem( const QString& text, QWidget* parent = 0 );
///
/// Color Palette Item
///
class ColorPaletteButtonItem : public QWidget
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteButtonItem( const QString& text, QWidget* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated();
/////////////////////////////////
// Event handlers
/////////////////////////////////
protected:
void paintEvent( QPaintEvent* event );
void enterEvent( QEvent* event );
void leaveEvent( QEvent* event );
void mousePressEvent( QMouseEvent* event );
/////////////////////////////////
// Event handlers
/////////////////////////////////
protected:
void paintEvent( QPaintEvent* event );
void enterEvent( QEvent* event );
void leaveEvent( QEvent* event );
void mousePressEvent( QMouseEvent* event );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QString mText;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QString mText;
bool mHover;
};
bool mHover;
};
}
#endif // ColorPaletteButtonItem_h
+254 -245
View File
@@ -30,289 +30,298 @@
#include <QtDebug>
ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = {
{ "#ef2929", tr("Light Scarlet Red", "Color name") },
{ "#fcaf3e", tr("Light Orange", "Color name") },
{ "#fce94f", tr("Light Butter", "Color name") },
{ "#8ae234", tr("Light Chameleon", "Color name") },
{ "#729fcf", tr("Light Sky Blue", "Color name") },
{ "#ad7fa8", tr("Light Plum", "Color name") },
{ "#e9b96e", tr("Light Chocolate", "Color name") },
{ "#888a85", tr("Light Aluminum 1", "Color name") },
{ "#eeeeec", tr("Light Aluminum 2", "Color name") },
{ "#cc0000", tr("Scarlet Red", "Color name") },
{ "#f57900", tr("Orange", "Color name") },
{ "#edd400", tr("Butter", "Color name") },
{ "#73d216", tr("Chameleon", "Color name") },
{ "#3465a4", tr("Sky Blue", "Color name") },
{ "#75507b", tr("Plum", "Color name") },
{ "#c17d11", tr("Chocolate", "Color name") },
{ "#555753", tr("Aluminum 1", "Color name") },
{ "#d3d7cf", tr("Aluminum 2", "Color name") },
{ "#a40000", tr("Dark Scarlet Red", "Color name") },
{ "#ce5c00", tr("Dark Orange", "Color name") },
{ "#c4a000", tr("Dark Butter", "Color name") },
{ "#4e9a06", tr("Dark Chameleon", "Color name") },
{ "#204a87", tr("Dark Sky Blue", "Color name") },
{ "#5c3566", tr("Dark Plum", "Color name") },
{ "#8f5902", tr("Dark Chocolate", "Color name") },
{ "#2e3436", tr("Dark Aluminum 1", "Color name") },
{ "#babdb6", tr("Dark Aluminum 2", "Color name") },
{ "#000000", tr("Black", "Color name") },
{ "#2e3436", tr("Very Dark Gray", "Color name") },
{ "#555753", tr("Darker Gray", "Color name") },
{ "#888a85", tr("Dark Gray", "Color name") },
{ "#babdb6", tr("Medium Gray", "Color name") },
{ "#d3d7cf", tr("Light Gray", "Color name") },
{ "#eeeeec", tr("Lighter Gray", "Color name") },
{ "#f3f3f3", tr("Very Light Gray", "Color name") },
{ "#ffffff", tr("White", "Color name") }
};
ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
QWidget* parent )
: QDialog( parent )
namespace glabels
{
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}" );
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
{ "#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") },
QVBoxLayout* vLayout = new QVBoxLayout();
vLayout->setContentsMargins( 0, 0, 0, 0 );
vLayout->setSpacing( 0 );
{ "#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") },
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 );
{ "#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") },
QGridLayout* mainPaletteLayout = new QGridLayout();
mainPaletteLayout->setSpacing( 0 );
for ( int iRow = 0; iRow < PALETTE_ROWS; iRow++ )
{ "#000000", tr("Black", "Color name") },
{ "#2e3436", tr("Very Dark Gray", "Color name") },
{ "#555753", tr("Darker Gray", "Color name") },
{ "#888a85", tr("Dark Gray", "Color name") },
{ "#babdb6", tr("Medium Gray", "Color name") },
{ "#d3d7cf", tr("Light Gray", "Color name") },
{ "#eeeeec", tr("Lighter Gray", "Color name") },
{ "#f3f3f3", tr("Very Light Gray", "Color name") },
{ "#ffffff", tr("White", "Color name") }
};
ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
QWidget* parent )
: QDialog( parent )
{
mColorHistory = ColorHistory::instance();
connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) );
mDefaultColor = defaultColor;
mColorNode = ColorNode( color );
setStyleSheet( ".glabels--ColorPaletteDialog {background: white; border: 1px solid black}" );
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
QVBoxLayout* vLayout = new QVBoxLayout();
vLayout->setContentsMargins( 0, 0, 0, 0 );
vLayout->setSpacing( 0 );
ColorPaletteButtonItem* defaultButton = new ColorPaletteButtonItem( defaultLabel );
connect( defaultButton, SIGNAL(activated()), this, SLOT(onDefaultItemActivated()) );
vLayout->addWidget( defaultButton );
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++ )
{
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,
QColor( mColorTable[i].colorSpec ),
mColorTable[i].name );
connect( item, SIGNAL(activated(int)), this, SLOT(onPaletteItemActivated(int)) );
customPaletteLayout->addWidget( mHistoryItem[iCol] );
}
vLayout->addLayout( customPaletteLayout );
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();
customPaletteLayout->setSpacing( 0 );
for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ )
void ColorPaletteDialog::clearKeys()
{
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 );
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
{
for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- )
{
mMergeFieldCombo->removeItem( index );
}
mMergeFieldCombo->setEnabled( false );
}
}
void ColorPaletteDialog::clearKeys()
{
for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- )
void ColorPaletteDialog::onDefaultItemActivated()
{
mMergeFieldCombo->removeItem( index );
mColorNode.setField( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, true );
accept();
}
mMergeFieldCombo->setEnabled( false );
}
void ColorPaletteDialog::onDefaultItemActivated()
{
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() )
void ColorPaletteDialog::onPaletteItemActivated( int id )
{
ColorNode newColorNode;
mColorNode.setField( false );
mColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
mColorNode.setKey( "" );
newColorNode.setField( false );
newColorNode.setColor( dlg.currentColor() );
newColorNode.setKey( "" );
emit colorChanged( mColorNode, false );
accept();
}
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 );
accept();
}
}
}
void ColorPaletteDialog::onColorHistoryChanged()
{
loadCustomColorHistory();
}
void ColorPaletteDialog::loadCustomColorHistory()
{
QList<QColor> colorList = mColorHistory->getColors();
int id = 0;
foreach ( QColor color, colorList )
void ColorPaletteDialog::showEvent( QShowEvent* event )
{
mHistoryItem[id]->setColor( id, color, QString(tr("Custom color #%1").arg(id+1) ) );
mHistoryItem[id]->setEnabled( true );
id++;
mMergeFieldCombo->setCurrentIndex( 0 );
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"
///
/// Color Palette Dialog
///
class ColorPaletteDialog : public QDialog
namespace glabels
{
Q_OBJECT
///
/// Color Palette Dialog
///
class ColorPaletteDialog : public QDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
QWidget* parent = 0 );
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
QWidget* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged( ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged( ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setColorNode( const ColorNode& colorNode );
void setKeys( const QStringList& keyList );
void clearKeys();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setColorNode( const ColorNode& colorNode );
void setKeys( const QStringList& keyList );
void clearKeys();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onDefaultItemActivated();
void onPaletteItemActivated( int id );
void onHistoryItemActivated( int id );
void onCustomColorItemActivated();
void onColorHistoryChanged();
void onComboIndexChanged( int index );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onDefaultItemActivated();
void onPaletteItemActivated( int id );
void onHistoryItemActivated( int id );
void onCustomColorItemActivated();
void onColorHistoryChanged();
void onComboIndexChanged( int index );
protected:
void showEvent( QShowEvent* event );
protected:
void showEvent( QShowEvent* event );
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
void loadCustomColorHistory();
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
void loadCustomColorHistory();
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
ColorNode mColorNode;
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
ColorNode mColorNode;
static const int PALETTE_COLS = ColorHistory::MAX_COLORS;
static const int PALETTE_ROWS = 4;
static const int PALETTE_COLS = ColorHistory::MAX_COLORS;
static const int PALETTE_ROWS = 4;
typedef struct {
QString colorSpec;
QString name;
} ColorTableEntry;
typedef struct {
QString colorSpec;
QString name;
} ColorTableEntry;
static ColorTableEntry mColorTable[];
static ColorTableEntry mColorTable[];
ColorHistory* mColorHistory;
ColorPaletteItem* mHistoryItem[PALETTE_COLS];
ColorHistory* mColorHistory;
ColorPaletteItem* mHistoryItem[PALETTE_COLS];
QComboBox* mMergeFieldCombo;
QStringList mKeys;
QComboBox* mMergeFieldCombo;
QStringList mKeys;
};
};
}
#endif // ColorPaletteDialog_h
+99 -94
View File
@@ -25,120 +25,125 @@
#include <QPainter>
//
// Private Configuration Data
//
namespace
namespace glabels
{
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 ) );
pen.setWidth( 2*outlineWidthPixels );
pen.setJoinStyle( Qt::MiterJoin );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( 1, 1, width()-2, height()-2 );
if ( mHover )
{
QPen pen( palette().color( QPalette::Text ) );
pen.setWidth( 2*outlineWidthPixels );
pen.setJoinStyle( Qt::MiterJoin );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( 1, 1, width()-2, height()-2 );
}
else
{
QPen pen( palette().color( QPalette::Text ) );
pen.setWidth( outlineWidthPixels );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch );
}
}
else
{
QPen pen( palette().color( QPalette::Text ) );
QPen pen( palette().color( QPalette::Disabled, QPalette::Text ) );
pen.setWidth( outlineWidthPixels );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch );
}
}
else
///
/// Enter Event
///
void ColorPaletteItem::enterEvent( QEvent* event )
{
QPen pen( palette().color( QPalette::Disabled, QPalette::Text ) );
pen.setWidth( outlineWidthPixels );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch );
mHover = true;
update();
}
}
///
/// Enter Event
///
void ColorPaletteItem::enterEvent( QEvent* event )
{
mHover = true;
update();
}
///
/// Leave Event
///
void ColorPaletteItem::leaveEvent( QEvent* event )
{
mHover = false;
update();
}
///
/// Leave Event
///
void ColorPaletteItem::leaveEvent( QEvent* event )
{
mHover = false;
update();
}
///
/// Mouse Press Event
///
void ColorPaletteItem::mousePressEvent( QMouseEvent* event )
{
emit activated( mId );
///
/// Mouse Press Event
///
void ColorPaletteItem::mousePressEvent( QMouseEvent* event )
{
emit activated( mId );
}
}
+47 -42
View File
@@ -26,59 +26,64 @@
#include <QWidget>
///
/// Color Palette Item
///
class ColorPaletteItem : public QWidget
namespace glabels
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteItem( int id,
const QColor& color,
const QString& tip,
QWidget* parent = 0 );
///
/// Color Palette Item
///
class ColorPaletteItem : public QWidget
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteItem( int id,
const QColor& color,
const QString& tip,
QWidget* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( int id );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( int id );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setColor( int id,
const QColor& color,
const QString& tip );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setColor( int id,
const QColor& color,
const QString& tip );
/////////////////////////////////
// Event handlers
/////////////////////////////////
protected:
void paintEvent( QPaintEvent* event );
void enterEvent( QEvent* event );
void leaveEvent( QEvent* event );
void mousePressEvent( QMouseEvent* event );
/////////////////////////////////
// Event handlers
/////////////////////////////////
protected:
void paintEvent( QPaintEvent* event );
void enterEvent( QEvent* event );
void leaveEvent( QEvent* event );
void mousePressEvent( QMouseEvent* event );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
int mId;
QColor mColor;
QString mTip;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
int mId;
QColor mColor;
QString mTip;
bool mHover;
};
bool mHover;
};
}
#endif // ColorPaletteItem_h
+33 -28
View File
@@ -24,33 +24,38 @@
#include <QPainter>
//
// Private Configuration Data
//
namespace
namespace glabels
{
const QColor outlineColor( 0, 0, 0 );
const double outlineWidthPixels = 1;
}
///
/// Constructor
///
ColorSwatch::ColorSwatch( int w, int h, const QColor& color )
: QPixmap( w, h )
{
fill( Qt::transparent );
QPainter painter(this );
painter.setBackgroundMode( Qt::TransparentMode );
QBrush brush( color );
QPen pen( outlineColor );
pen.setWidth( outlineWidthPixels );
painter.setBrush( brush );
painter.setPen( pen );
painter.drawRect( 1, 1, w-2, h-2 );
//
// Private
//
namespace
{
const QColor outlineColor( 0, 0, 0 );
const double outlineWidthPixels = 1;
}
///
/// Constructor
///
ColorSwatch::ColorSwatch( int w, int h, const QColor& color )
: QPixmap( w, h )
{
fill( Qt::transparent );
QPainter painter(this );
painter.setBackgroundMode( Qt::TransparentMode );
QBrush brush( color );
QPen pen( outlineColor );
pen.setWidth( outlineWidthPixels );
painter.setBrush( brush );
painter.setPen( pen );
painter.drawRect( 1, 1, w-2, h-2 );
}
}
+15 -10
View File
@@ -25,19 +25,24 @@
#include <QPixmap>
///
/// Simple Preview Widget
///
class ColorSwatch : public QPixmap
namespace glabels
{
///
/// Simple Preview Widget
///
class ColorSwatch : public QPixmap
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorSwatch( int w, int h, const QColor& color );
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorSwatch( int w, int h, const QColor& color );
};
};
}
#endif // 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_PICA = 12.0;
const Distance EPSILON( 0.5, Units::PT );
}
#endif // glabels_Constants_h
+43 -32
View File
@@ -23,37 +23,48 @@
#include <QPixmap>
Cursors::Barcode::Barcode()
: 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 )
namespace glabels
{
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>
///
/// Glabels Cursors
///
namespace Cursors
namespace glabels
{
///
/// Glabels Cursors
///
namespace Cursors
{
class Barcode : public QCursor
{
public:
Barcode();
};
class Barcode : public QCursor
{
public:
Barcode();
};
class Box : public QCursor
{
public:
Box();
};
class Box : public QCursor
{
public:
Box();
};
class Ellipse : public QCursor
{
public:
Ellipse();
};
class Ellipse : public QCursor
{
public:
Ellipse();
};
class Image : public QCursor
{
public:
Image();
};
class Image : public QCursor
{
public:
Image();
};
class Line : public QCursor
{
public:
Line();
};
class Line : public QCursor
{
public:
Line();
};
class Text : public QCursor
{
public:
Text();
};
class Text : public QCursor
{
public:
Text();
};
}
}
+24 -17
View File
@@ -32,18 +32,26 @@
#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
{
//
// 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;
QStringList Db::mPaperIds;
QStringList Db::mPaperNames;
@@ -53,10 +61,9 @@ namespace glabels
QList<Vendor*> Db::mVendors;
QStringList Db::mVendorNames;
QList<Template*> Db::mTemplates;
QString Db::mPaperNameOther;
QString Db::mPaperNameOther;
QString Db::mEmpty = "";
Db::Db()
{
mPaperNameOther = tr("Other");
@@ -204,7 +211,7 @@ namespace glabels
}
qWarning() << "Unknown paper name: " << name;
return mEmpty;
return empty;
}
@@ -225,7 +232,7 @@ namespace glabels
}
qWarning() << "Unknown paper id: " << id;
return mEmpty;
return empty;
}
@@ -318,7 +325,7 @@ namespace glabels
}
qWarning() << "Unknown category name: " << name;
return mEmpty;
return empty;
}
@@ -334,7 +341,7 @@ namespace glabels
}
qWarning() << "Unknown category id: " << id;
return mEmpty;
return empty;
}
@@ -399,7 +406,7 @@ namespace glabels
}
qWarning() << "Unknown vendor name: " << name;
return mEmpty;
return empty;
}
+2 -2
View File
@@ -131,8 +131,8 @@ namespace glabels
static QList<Template*> mTemplates;
static QString mPaperNameOther;
static QString mEmpty;
static QString mPaperNameOther;
};
}
+76 -71
View File
@@ -21,101 +21,106 @@
#include "EnumUtil.h"
namespace EnumUtil
namespace glabels
{
QString weightToString( QFont::Weight weight )
namespace EnumUtil
{
switch (weight)
QString weightToString( QFont::Weight weight )
{
case QFont::Bold:
return "bold";
break;
default:
return "normal";
break;
switch (weight)
{
case QFont::Bold:
return "bold";
break;
default:
return "normal";
break;
}
}
}
QFont::Weight stringToWeight( const QString& string )
{
if ( string == "bold" )
QFont::Weight stringToWeight( const QString& string )
{
return QFont::Bold;
if ( string == "bold" )
{
return QFont::Bold;
}
else
{
return QFont::Normal;
}
}
else
{
return QFont::Normal;
}
}
QString hAlignToString( Qt::Alignment align )
{
switch (align)
QString hAlignToString( Qt::Alignment align )
{
case Qt::AlignRight:
return "right";
break;
case Qt::AlignHCenter:
return "center";
break;
default:
return "left";
break;
switch (align)
{
case Qt::AlignRight:
return "right";
break;
case Qt::AlignHCenter:
return "center";
break;
default:
return "left";
break;
}
}
}
Qt::Alignment stringToHAlign( const QString& string )
{
if ( string == "right" )
Qt::Alignment stringToHAlign( const QString& string )
{
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 )
{
switch (align)
QString vAlignToString( Qt::Alignment align )
{
case Qt::AlignBottom:
return "bottom";
break;
case Qt::AlignVCenter:
return "center";
break;
default:
return "top";
break;
switch (align)
{
case Qt::AlignBottom:
return "bottom";
break;
case Qt::AlignVCenter:
return "center";
break;
default:
return "top";
break;
}
}
}
Qt::Alignment stringToVAlign( const QString& string )
{
if ( string == "bottom" )
Qt::Alignment stringToVAlign( const QString& string )
{
return Qt::AlignBottom;
}
else if ( string == "center" )
{
return Qt::AlignVCenter;
}
else
{
return Qt::AlignTop;
if ( string == "bottom" )
{
return Qt::AlignBottom;
}
else if ( string == "center" )
{
return Qt::AlignVCenter;
}
else
{
return Qt::AlignTop;
}
}
}
}
+12 -7
View File
@@ -27,17 +27,22 @@
#include <Qt>
namespace EnumUtil
namespace glabels
{
QString weightToString( QFont::Weight weight );
QFont::Weight stringToWeight( const QString& string );
namespace EnumUtil
{
QString hAlignToString( Qt::Alignment align );
Qt::Alignment stringToHAlign( const QString& string );
QString weightToString( QFont::Weight weight );
QFont::Weight stringToWeight( const QString& string );
QString vAlignToString( Qt::Alignment align );
Qt::Alignment stringToVAlign( const QString& string );
QString hAlignToString( Qt::Alignment align );
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>
///
/// Constructor
///
FieldButton::FieldButton( QWidget* parent )
: QComboBox(parent)
namespace glabels
{
setEnabled( false );
connect( this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int)) );
}
void FieldButton::setName( const QString& name )
{
mName = name;
if ( count() == 0 )
///
/// Constructor
///
FieldButton::FieldButton( QWidget* parent )
: QComboBox(parent)
{
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 );
}
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 );
// 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) );
// 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
if ( keyList.size() > 0 )
{
addItems( keyList );
setEnabled( true );
}
else
{
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 );
// Add new keys
if ( keyList.size() > 0 )
{
addItems( keyList );
setEnabled( true );
}
else
{
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 );
}
}
}
+38 -33
View File
@@ -26,50 +26,55 @@
#include <QString>
///
/// Field Button
///
class FieldButton : public QComboBox
namespace glabels
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldButton( QWidget* parent = 0 );
///
/// Field Button
///
class FieldButton : public QComboBox
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldButton( QWidget* parent = 0 );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void keySelected( QString key );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void keySelected( QString key );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setName( const QString& name = "" );
void setKeys( const QStringList& keyList );
void clearKeys();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setName( const QString& name = "" );
void setKeys( const QStringList& keyList );
void clearKeys();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onIndexChanged( int index );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onIndexChanged( int index );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QString mName;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QString mName;
};
};
}
#endif // FieldButton_h
+169 -164
View File
@@ -33,81 +33,34 @@
#include "XmlLabelCreator.h"
///
/// Static data
///
QString File::mCwd = ".";
///
/// New Label Dialog
///
bool File::newLabel( MainWindow *window )
namespace glabels
{
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();
label->setTmplate( tmplate );
label->clearModified();
SelectProductDialog dialog( window );
dialog.exec();
// Intelligently decide to rotate label by default
const glabels::Frame* frame = tmplate->frames().first();
label->setRotate( frame->h() > frame->w() );
// Either apply to current window or open a new one
if ( window->isEmpty() )
const Template* tmplate = dialog.tmplate();
if ( tmplate )
{
window->setModel( label );
}
else
{
MainWindow *newWindow = new MainWindow();
newWindow->setModel( label );
newWindow->show();
}
LabelModel* label = new LabelModel();
label->setTmplate( tmplate );
label->clearModified();
return true;
}
else
{
return false;
}
}
// Intelligently decide to rotate label by default
const Frame* frame = tmplate->frames().first();
label->setRotate( frame->h() > frame->w() );
///
/// 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
if ( window->isEmpty() )
{
@@ -120,123 +73,175 @@ void File::open( MainWindow *window )
newWindow->show();
}
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
return true;
}
else
{
QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
msgBox.setDefaultButton( QMessageBox::Ok );
msgBox.exec();
return false;
}
}
}
///
/// Save file
///
bool File::save( MainWindow *window )
{
if ( window->model()->fileName().isEmpty() )
///
/// Open File Dialog
///
void File::open( MainWindow *window )
{
return saveAs( window );
}
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() )
// 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() )
{
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 )
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
return saveAs( window );
cwd = fileInfo.absolutePath();
}
}
XmlLabelCreator::writeFile( window->model(), fileName );
window->model()->setFileName( fileName );
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
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();
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
mCwd = QFileInfo( window->model()->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() )
///
/// Save file as
///
bool File::saveAs( MainWindow *window )
{
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>
// Forward References
class MainWindow;
///
/// File Actions
///
/// Note: class provides a translation context for these static functions.
///
class File : public QObject
namespace glabels
{
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();
// Forward References
class MainWindow;
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
+10 -5
View File
@@ -21,17 +21,22 @@
#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>
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 )
: mId(id), mNLabels(0), mLayoutDescription("")
{
// empty
}
+6 -5
View File
@@ -23,7 +23,7 @@
#include <QtDebug>
#include "privateConstants.h"
#include "Constants.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),
mPath(other.mPath), Frame(other)
{
// empty
}
@@ -160,10 +161,10 @@ namespace glabels
{
if ( FrameCd *otherCd = dynamic_cast<FrameCd*>(other) )
{
if ( (fabs( mW - otherCd->mW ) <= Constants::EPSILON) &&
(fabs( mH - otherCd->mH ) <= Constants::EPSILON) &&
(fabs( mR1 - otherCd->mR1 ) <= Constants::EPSILON) &&
(fabs( mR2 - otherCd->mR2 ) <= Constants::EPSILON) )
if ( (fabs( mW - otherCd->mW ) <= EPSILON) &&
(fabs( mH - otherCd->mH ) <= EPSILON) &&
(fabs( mR1 - otherCd->mR1 ) <= EPSILON) &&
(fabs( mR2 - otherCd->mR2 ) <= EPSILON) )
{
return true;
}
+4 -3
View File
@@ -21,7 +21,7 @@
#include "FrameEllipse.h"
#include "privateConstants.h"
#include "Constants.h"
#include "StrUtil.h"
@@ -41,6 +41,7 @@ namespace glabels
FrameEllipse::FrameEllipse( const FrameEllipse& 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 ( (fabs( mW - otherEllipse->mW ) <= Constants::EPSILON) &&
(fabs( mH - otherEllipse->mH ) <= Constants::EPSILON) )
if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) &&
(fabs( mH - otherEllipse->mH ) <= EPSILON) )
{
return true;
}
+4 -3
View File
@@ -21,7 +21,7 @@
#include "FrameRect.h"
#include "privateConstants.h"
#include "Constants.h"
#include "StrUtil.h"
@@ -48,6 +48,7 @@ namespace glabels
: mW(other.mW), mH(other.mH), mR(other.mR), mXWaste(other.mXWaste),
mYWaste(other.mYWaste), mPath(other.mPath), Frame(other)
{
// empty
}
@@ -113,8 +114,8 @@ namespace glabels
{
if ( FrameRect *otherRect = dynamic_cast<FrameRect*>(other) )
{
if ( (fabs( mW - otherRect->mW ) <= Constants::EPSILON) &&
(fabs( mH - otherRect->mH ) <= Constants::EPSILON) )
if ( (fabs( mW - otherRect->mW ) <= EPSILON) &&
(fabs( mH - otherRect->mH ) <= EPSILON) )
{
return true;
}
+5 -3
View File
@@ -21,7 +21,7 @@
#include "FrameRound.h"
#include "privateConstants.h"
#include "Constants.h"
#include "StrUtil.h"
@@ -34,13 +34,15 @@ namespace glabels
: mR(r), mWaste(waste), Frame(id)
{
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 )
: 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 ( fabs( mR - otherRound->mR ) <= Constants::EPSILON )
if ( fabs( mR - otherRound->mR ) <= EPSILON )
{
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"
// Forward References
class LabelModelObject;
///
/// Handle Base Class
///
class Handle
namespace glabels
{
////////////////////////////
// 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();
// Forward References
class LabelModelObject;
////////////////////////////
// Duplication
////////////////////////////
virtual Handle* clone( LabelModelObject* newOwner ) const = 0;
///
/// Handle Base Class
///
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
////////////////////////////
LabelModelObject* owner() const;
Location location() const;
////////////////////////////
// Attribue Methods
////////////////////////////
LabelModelObject* owner() const;
Location location() const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const = 0;
virtual QPainterPath path( double scale ) const = 0;
protected:
void drawAt( QPainter* painter,
double scale,
const glabels::Distance& x,
const glabels::Distance& y,
QColor color ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const = 0;
virtual QPainterPath path( double scale ) const = 0;
protected:
void drawAt( QPainter* painter,
double scale,
const Distance& x,
const Distance& y,
QColor color ) const;
QPainterPath pathAt( double scale,
const glabels::Distance& x,
const glabels::Distance& y ) const;
QPainterPath pathAt( double scale,
const Distance& x,
const Distance& y ) const;
////////////////////////////
// Protected Data
////////////////////////////
protected:
LabelModelObject* mOwner;
Location mLocation;
////////////////////////////
// Protected Data
////////////////////////////
protected:
LabelModelObject* mOwner;
Location mLocation;
};
};
///
/// HandleNorth Class
///
class HandleNorth : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorth( LabelModelObject* owner );
virtual ~HandleNorth();
virtual HandleNorth* clone( LabelModelObject* newOwner ) const;
///
/// HandleNorth Class
///
class HandleNorth : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorth( LabelModelObject* owner );
virtual ~HandleNorth();
virtual HandleNorth* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleNorthEast Class
///
class HandleNorthEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorthEast( LabelModelObject* owner );
virtual ~HandleNorthEast();
virtual HandleNorthEast* clone( LabelModelObject* newOwner ) const;
///
/// HandleNorthEast Class
///
class HandleNorthEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorthEast( LabelModelObject* owner );
virtual ~HandleNorthEast();
virtual HandleNorthEast* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleEast Class
///
class HandleEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleEast( LabelModelObject* owner );
virtual ~HandleEast();
virtual HandleEast* clone( LabelModelObject* newOwner ) const;
///
/// HandleEast Class
///
class HandleEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleEast( LabelModelObject* owner );
virtual ~HandleEast();
virtual HandleEast* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleSouthEast Class
///
class HandleSouthEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouthEast( LabelModelObject* owner );
virtual ~HandleSouthEast();
virtual HandleSouthEast* clone( LabelModelObject* newOwner ) const;
///
/// HandleSouthEast Class
///
class HandleSouthEast : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouthEast( LabelModelObject* owner );
virtual ~HandleSouthEast();
virtual HandleSouthEast* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleSouth Class
///
class HandleSouth : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouth( LabelModelObject* owner );
virtual ~HandleSouth();
virtual HandleSouth* clone( LabelModelObject* newOwner ) const;
///
/// HandleSouth Class
///
class HandleSouth : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouth( LabelModelObject* owner );
virtual ~HandleSouth();
virtual HandleSouth* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleSouthWest Class
///
class HandleSouthWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouthWest( LabelModelObject* owner );
virtual ~HandleSouthWest();
virtual HandleSouthWest* clone( LabelModelObject* newOwner ) const;
///
/// HandleSouthWest Class
///
class HandleSouthWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleSouthWest( LabelModelObject* owner );
virtual ~HandleSouthWest();
virtual HandleSouthWest* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleWest Class
///
class HandleWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleWest( LabelModelObject* owner );
virtual ~HandleWest();
virtual HandleWest* clone( LabelModelObject* newOwner ) const;
///
/// HandleWest Class
///
class HandleWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleWest( LabelModelObject* owner );
virtual ~HandleWest();
virtual HandleWest* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleNorthWest Class
///
class HandleNorthWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorthWest( LabelModelObject* owner );
virtual ~HandleNorthWest();
virtual HandleNorthWest* clone( LabelModelObject* newOwner ) const;
///
/// HandleNorthWest Class
///
class HandleNorthWest : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleNorthWest( LabelModelObject* owner );
virtual ~HandleNorthWest();
virtual HandleNorthWest* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleP1 Class
///
class HandleP1 : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleP1( LabelModelObject* owner );
virtual ~HandleP1();
virtual HandleP1* clone( LabelModelObject* newOwner ) const;
///
/// HandleP1 Class
///
class HandleP1 : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleP1( LabelModelObject* owner );
virtual ~HandleP1();
virtual HandleP1* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
///
/// HandleP2 Class
///
class HandleP2 : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleP2( LabelModelObject* owner );
virtual ~HandleP2();
///
/// HandleP2 Class
///
class HandleP2 : public Handle
{
////////////////////////////
// Lifecycle Methods
////////////////////////////
public:
HandleP2( LabelModelObject* owner );
virtual ~HandleP2();
////////////////////////////
// Duplication
////////////////////////////
virtual HandleP2* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Duplication
////////////////////////////
virtual HandleP2* clone( LabelModelObject* newOwner ) const;
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
////////////////////////////
// Drawing Methods
////////////////////////////
public:
virtual void draw( QPainter* painter, double scale ) const;
virtual QPainterPath path( double scale ) const;
};
}
#endif // Handles_h
+18 -13
View File
@@ -26,20 +26,25 @@
#include "AboutDialog.h"
///
/// Display Help Contents
///
void Help::displayContents( QWidget *parent )
namespace glabels
{
qDebug() << "TODO: Help::displayContents";
}
///
/// Display Help Contents
///
void Help::displayContents( QWidget *parent )
{
qDebug() << "TODO: Help::displayContents";
}
///
/// Display Help->About Dialog
///
void Help::displayAbout( QWidget *parent )
{
AboutDialog dialog( parent );
dialog.exec();
///
/// Display Help->About Dialog
///
void Help::displayAbout( QWidget *parent )
{
AboutDialog dialog( parent );
dialog.exec();
}
}
+11 -7
View File
@@ -25,16 +25,20 @@
#include <QWidget>
///
/// Help Actions
///
namespace Help
namespace glabels
{
void displayContents( QWidget *parent );
void displayAbout( QWidget *parent );
///
/// Help Actions
///
namespace Help
{
void displayContents( QWidget *parent );
void displayAbout( QWidget *parent );
}
}
#endif // Help_h
+308 -312
View File
@@ -25,324 +25,320 @@
#include <QIcon>
///
/// Glabels Icons
///
namespace Icons
namespace glabels
{
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,
/// if supported. These icons are copied from the mate-icon-theme (GPL-v3 or CC-BY-SA-v3).
/// Glabels Icons
///
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
{
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"
// Forward References
class LabelModel;
class LabelModelObject;
class UndoRedoModel;
class Handle;
///
/// LabelEditor Widget
///
class LabelEditor : public QWidget
namespace glabels
{
Q_OBJECT
/////////////////////////////////////
// Lifecycle
/////////////////////////////////////
public:
LabelEditor( QScrollArea* scrollArea, QWidget* parent = 0 );
// Forward References
class LabelModel;
class LabelModelObject;
class UndoRedoModel;
class Handle;
/////////////////////////////////////
// Signals
/////////////////////////////////////
signals:
void contextMenuActivate();
void zoomChanged();
void pointerMoved( const glabels::Distance& x, const glabels::Distance& y );
void pointerExited();
void modeChanged();
///
/// LabelEditor Widget
///
class LabelEditor : public QWidget
{
Q_OBJECT
/////////////////////////////////////
// Lifecycle
/////////////////////////////////////
public:
LabelEditor( QScrollArea* scrollArea, QWidget* parent = 0 );
/////////////////////////////////////
// Parameters
/////////////////////////////////////
public:
double zoom() const;
bool markupVisible() const;
bool qridVisible() const;
/////////////////////////////////////
// Signals
/////////////////////////////////////
signals:
void contextMenuActivate();
void zoomChanged();
void pointerMoved( const Distance& x, const Distance& y );
void pointerExited();
void modeChanged();
/////////////////////////////////////
// Model
/////////////////////////////////////
public:
void setModel( LabelModel* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////////
// Parameters
/////////////////////////////////////
public:
double zoom() const;
bool markupVisible() const;
bool qridVisible() const;
/////////////////////////////////////
// Visibility operations
/////////////////////////////////////
public:
void setGridVisible( bool visibleFlag );
void setMarkupVisible( bool visibleFlag );
/////////////////////////////////////
// Model
/////////////////////////////////////
public:
void setModel( LabelModel* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////////
// Zoom operations
/////////////////////////////////////
public:
void zoomIn();
void zoomOut();
void zoom1To1();
void zoomToFit();
bool isZoomMax() const;
bool isZoomMin() const;
private:
void setZoomReal( double zoom, bool zoomToFitFlag );
/////////////////////////////////////
// Visibility operations
/////////////////////////////////////
public:
void setGridVisible( bool visibleFlag );
void setMarkupVisible( bool visibleFlag );
/////////////////////////////////////
// Mode operations
/////////////////////////////////////
public:
void arrowMode();
void createBoxMode();
void createEllipseMode();
void createLineMode();
void createImageMode();
void createTextMode();
void createBarcodeMode();
/////////////////////////////////////
// Zoom operations
/////////////////////////////////////
public:
void zoomIn();
void zoomOut();
void zoom1To1();
void zoomToFit();
bool isZoomMax() const;
bool isZoomMin() const;
private:
void setZoomReal( double zoom, bool zoomToFitFlag );
/////////////////////////////////////
// Event handlers
/////////////////////////////////////
protected:
void resizeEvent( QResizeEvent* event );
void mousePressEvent( QMouseEvent* event );
void mouseMoveEvent( QMouseEvent* event );
void mouseReleaseEvent( QMouseEvent* event );
void leaveEvent( QEvent* event );
void keyPressEvent( QKeyEvent* event );
void paintEvent( QPaintEvent* event );
/////////////////////////////////////
// Mode operations
/////////////////////////////////////
public:
void arrowMode();
void createBoxMode();
void createEllipseMode();
void createLineMode();
void createImageMode();
void createTextMode();
void createBarcodeMode();
/////////////////////////////////////
// Private methods
/////////////////////////////////////
private:
void handleResizeMotion( const glabels::Distance& xWorld,
const glabels::Distance& yWorld );
void drawBgLayer( QPainter* painter );
void drawGridLayer( QPainter* painter );
void drawMarkupLayer( QPainter* painter );
void drawObjectsLayer( QPainter* painter );
void drawFgLayer( QPainter* painter );
void drawHighlightLayer( QPainter* painter );
void drawSelectRegionLayer( QPainter* painter );
/////////////////////////////////////
// Event handlers
/////////////////////////////////////
protected:
void resizeEvent( QResizeEvent* event );
void mousePressEvent( QMouseEvent* event );
void mouseMoveEvent( QMouseEvent* event );
void mouseReleaseEvent( QMouseEvent* event );
void leaveEvent( QEvent* event );
void keyPressEvent( QKeyEvent* event );
void paintEvent( QPaintEvent* event );
/////////////////////////////////////
// Private slots
/////////////////////////////////////
private slots:
void onSettingsChanged();
void onModelSizeChanged();
/////////////////////////////////////
// Private methods
/////////////////////////////////////
private:
void handleResizeMotion( const Distance& xWorld,
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
+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/Record.h"
// Forward References
class ColorNode;
class Handle;
class LabelModelObject;
class Region;
//////////////////////////////////////////////
//////////////////////////////////////////////
// LabelModel
//////////////////////////////////////////////
//////////////////////////////////////////////
class LabelModel : public QObject
namespace glabels
{
Q_OBJECT
// Forward References
class ColorNode;
class Handle;
class LabelModelObject;
class Region;
///
/// LabelModel
///
class LabelModel : public QObject
{
Q_OBJECT
/////////////////////////////////
// Lifecycle
/////////////////////////////////
public:
LabelModel();
virtual ~LabelModel() {}
/////////////////////////////////
// Lifecycle
/////////////////////////////////
public:
LabelModel();
virtual ~LabelModel() {}
/////////////////////////////////
// Save/restore model state
/////////////////////////////////
LabelModel* save() const;
void restore( const LabelModel *savedModel );
/////////////////////////////////
// Save/restore model state
/////////////////////////////////
LabelModel* save() const;
void restore( const LabelModel *savedModel );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void changed();
void nameChanged();
void sizeChanged();
void selectionChanged();
void modifiedChanged();
void mergeChanged();
void mergeSourceChanged();
void mergeSelectionChanged();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void changed();
void nameChanged();
void sizeChanged();
void selectionChanged();
void modifiedChanged();
void mergeChanged();
void mergeSourceChanged();
void mergeSelectionChanged();
/////////////////////////////////
// Properties
/////////////////////////////////
public:
bool isModified() const;
void setModified();
void clearModified();
/////////////////////////////////
// Properties
/////////////////////////////////
public:
bool isModified() const;
void setModified();
void clearModified();
QString shortName();
const QString& fileName() const;
void setFileName( const QString &fileName );
QString shortName();
const QString& fileName() const;
void setFileName( const QString &fileName );
int compressionLevel() const;
void setCompressionLevel( int compressionLevel );
int compressionLevel() const;
void setCompressionLevel( int compressionLevel );
const glabels::Template* tmplate() const;
const glabels::Frame* frame() const;
void setTmplate( const glabels::Template* tmplate );
const Template* tmplate() const;
const Frame* frame() const;
void setTmplate( const Template* tmplate );
bool rotate() const;
void setRotate( bool rotate );
bool rotate() const;
void setRotate( bool rotate );
glabels::Distance w() const;
glabels::Distance h() const;
Distance w() const;
Distance h() const;
const QList<LabelModelObject*>& objectList() const;
const QList<LabelModelObject*>& objectList() const;
merge::Merge* merge() const;
void setMerge( merge::Merge* merge );
merge::Merge* merge() const;
void setMerge( merge::Merge* merge );
/////////////////////////////////
// Manage objects
/////////////////////////////////
public:
void addObject( LabelModelObject* object );
void deleteObject( LabelModelObject* object );
/////////////////////////////////
// Manage objects
/////////////////////////////////
public:
void addObject( LabelModelObject* object );
void deleteObject( LabelModelObject* object );
LabelModelObject* objectAt( double scale,
const glabels::Distance& x,
const glabels::Distance& y ) const;
LabelModelObject* objectAt( 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;
/////////////////////////////////
// Manipulate selection
/////////////////////////////////
public:
void selectObject( LabelModelObject* object );
void unselectObject( LabelModelObject* object );
void selectAll();
void unselectAll();
void selectRegion( const Region& region );
bool isSelectionEmpty();
bool isSelectionAtomic();
/////////////////////////////////
// Manipulate selection
/////////////////////////////////
public:
void selectObject( LabelModelObject* object );
void unselectObject( LabelModelObject* object );
void selectAll();
void unselectAll();
void selectRegion( const Region& region );
bool isSelectionEmpty();
bool isSelectionAtomic();
/////////////////////////////////
// Get selected objects
/////////////////////////////////
public:
QList<LabelModelObject*> getSelection();
LabelModelObject* getFirstSelectedObject();
/////////////////////////////////
// Get selected objects
/////////////////////////////////
public:
QList<LabelModelObject*> getSelection();
LabelModelObject* getFirstSelectedObject();
/////////////////////////////////
// Query selection capabilities
/////////////////////////////////
public:
bool canSelectionText();
bool canSelectionFill();
bool canSelectionLineColor();
bool canSelectionLineWidth();
/////////////////////////////////
// Query selection capabilities
/////////////////////////////////
public:
bool canSelectionText();
bool canSelectionFill();
bool canSelectionLineColor();
bool canSelectionLineWidth();
/////////////////////////////////
// Operations on selections
/////////////////////////////////
public:
void deleteSelection();
void raiseSelectionToTop();
void lowerSelectionToBottom();
void rotateSelection( double thetaDegs );
void rotateSelectionLeft();
void rotateSelectionRight();
void flipSelectionHoriz();
void flipSelectionVert();
void alignSelectionLeft();
void alignSelectionRight();
void alignSelectionHCenter();
void alignSelectionTop();
void alignSelectionBottom();
void alignSelectionVCenter();
void centerSelectionHoriz();
void centerSelectionVert();
void moveSelection( const glabels::Distance& dx, const glabels::Distance& dy );
void setSelectionFontFamily( const QString& fontFamily );
void setSelectionFontSize( double fontSize );
void setSelectionFontWeight( QFont::Weight fontWeight );
void setSelectionFontItalicFlag( bool fontItalicFlag );
void setSelectionTextHAlign( Qt::Alignment textHAlign );
void setSelectionTextVAlign( Qt::Alignment textVAlign );
void setSelectionTextLineSpacing( double textLineSpacing );
void setSelectionTextColorNode( ColorNode textColorNode );
void setSelectionLineWidth( const glabels::Distance& lineWidth );
void setSelectionLineColorNode( ColorNode lineColorNode );
void setSelectionFillColorNode( ColorNode fillColorNode );
/////////////////////////////////
// Operations on selections
/////////////////////////////////
public:
void deleteSelection();
void raiseSelectionToTop();
void lowerSelectionToBottom();
void rotateSelection( double thetaDegs );
void rotateSelectionLeft();
void rotateSelectionRight();
void flipSelectionHoriz();
void flipSelectionVert();
void alignSelectionLeft();
void alignSelectionRight();
void alignSelectionHCenter();
void alignSelectionTop();
void alignSelectionBottom();
void alignSelectionVCenter();
void centerSelectionHoriz();
void centerSelectionVert();
void moveSelection( const Distance& dx, const Distance& dy );
void setSelectionFontFamily( const QString& fontFamily );
void setSelectionFontSize( double fontSize );
void setSelectionFontWeight( QFont::Weight fontWeight );
void setSelectionFontItalicFlag( bool fontItalicFlag );
void setSelectionTextHAlign( Qt::Alignment textHAlign );
void setSelectionTextVAlign( Qt::Alignment textVAlign );
void setSelectionTextLineSpacing( double textLineSpacing );
void setSelectionTextColorNode( ColorNode textColorNode );
void setSelectionLineWidth( const Distance& lineWidth );
void setSelectionLineColorNode( ColorNode lineColorNode );
void setSelectionFillColorNode( ColorNode fillColorNode );
/////////////////////////////////
// Clipboard operations
/////////////////////////////////
void copySelection();
void cutSelection();
bool canPaste();
void paste();
/////////////////////////////////
// Clipboard operations
/////////////////////////////////
void copySelection();
void cutSelection();
bool canPaste();
void paste();
/////////////////////////////////
// Drawing operations
/////////////////////////////////
public:
void draw( QPainter* painter, bool inEditor = true, merge::Record* record = 0 ) const;
/////////////////////////////////
// Drawing operations
/////////////////////////////////
public:
void draw( QPainter* painter, bool inEditor = true, merge::Record* record = 0 ) const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onObjectChanged();
void onObjectMoved();
void onMergeSourceChanged();
void onMergeSelectionChanged();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onObjectChanged();
void onObjectMoved();
void onMergeSourceChanged();
void onMergeSelectionChanged();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
int mUntitledInstance;
bool mModified;
QString mFileName;
int mCompressionLevel;
const glabels::Template* mTmplate;
const glabels::Frame* mFrame;
bool mRotate;
/////////////////////////////////
// Private data
/////////////////////////////////
private:
int mUntitledInstance;
bool mModified;
QString mFileName;
int mCompressionLevel;
const Template* mTmplate;
const Frame* mFrame;
bool mRotate;
QList<LabelModelObject*> mObjectList;
QList<LabelModelObject*> mObjectList;
merge::Merge* mMerge;
};
merge::Merge* mMerge;
};
}
#endif // LabelModel_h
+127 -115
View File
@@ -25,134 +25,146 @@
#include <QPen>
namespace
namespace glabels
{
const double slopPixels = 2;
}
///
/// Constructor
///
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() )
//
// Private
//
namespace
{
painter->setPen( Qt::NoPen );
painter->setBrush( shadowColor );
const double slopPixels = 2;
}
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->drawRect( QRectF( -mLineWidth.pt()/2,
-mLineWidth.pt()/2,
(mW + mLineWidth).pt(),
(mH + mLineWidth).pt() ) );
painter->setPen( Qt::NoPen );
painter->setBrush( shadowColor );
if ( lineColor.alpha() )
{
/* Has FILL and OUTLINE: adjust size to account for line width. */
painter->drawRect( QRectF( -mLineWidth.pt()/2,
-mLineWidth.pt()/2,
(mW + mLineWidth).pt(),
(mH + mLineWidth).pt() ) );
}
else
{
/* Has FILL, but no OUTLINE. */
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
}
else
{
/* Has FILL, but no OUTLINE. */
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
}
else
{
if ( lineColor.alpha() )
{
/* Has only OUTLINE. */
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
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
///
void LabelModelBoxObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record );
///
/// Draw object itself
///
void LabelModelBoxObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->setBrush( fillColor );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->setBrush( fillColor );
painter->drawRect( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
///
/// Path to test for hover condition
///
QPainterPath LabelModelBoxObject::hoverPath( double scale ) const
{
double s = 1 / scale;
QPainterPath path;
if ( mFillColorNode.color().alpha() && mLineColorNode.color().alpha() )
{
path.addRect( -mLineWidth.pt()/2, -mLineWidth.pt()/2, (mW+mLineWidth).pt(), (mH+mLineWidth).pt() );
}
else if ( mFillColorNode.color().alpha() && !(mLineColorNode.color().alpha()) )
{
path.addRect( 0, 0, mW.pt(), mH.pt() );
}
else if ( mLineColorNode.color().alpha() )
{
path.addRect( (-mLineWidth.pt()/2) - s*slopPixels,
(-mLineWidth.pt()/2) - s*slopPixels,
(mW + mLineWidth).pt() + s*2*slopPixels,
(mH + mLineWidth).pt() + s*2*slopPixels );
path.closeSubpath();
path.addRect( mLineWidth.pt()/2 + s*slopPixels,
mLineWidth.pt()/2 + s*slopPixels,
(mW - mLineWidth).pt() - s*2*slopPixels,
(mH - mLineWidth).pt() - s*2*slopPixels );
}
return path;
}
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"
///
/// Label Model Box Object
///
class LabelModelBoxObject : public LabelModelShapeObject
namespace glabels
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelBoxObject();
LabelModelBoxObject( const LabelModelBoxObject* object );
virtual ~LabelModelBoxObject();
///
/// Label Model Box Object
///
class LabelModelBoxObject : public LabelModelShapeObject
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelBoxObject();
LabelModelBoxObject( const LabelModelBoxObject* object );
virtual ~LabelModelBoxObject();
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelBoxObject* clone() const;
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelBoxObject* clone() const;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
};
};
}
#endif // LabelModelBoxObject_h
+127 -115
View File
@@ -25,134 +25,146 @@
#include <QPen>
namespace
namespace glabels
{
const double slopPixels = 2;
}
///
/// Constructor
///
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() )
//
// Private
//
namespace
{
painter->setPen( Qt::NoPen );
painter->setBrush( shadowColor );
const double slopPixels = 2;
}
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->drawEllipse( QRectF( -mLineWidth.pt()/2,
-mLineWidth.pt()/2,
(mW + mLineWidth).pt(),
(mH + mLineWidth).pt() ) );
painter->setPen( Qt::NoPen );
painter->setBrush( shadowColor );
if ( lineColor.alpha() )
{
/* 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
{
/* Has FILL, but no OUTLINE. */
painter->drawEllipse( QRectF( 0, 0, mW.pt(), mH.pt() ) );
}
}
else
{
if ( lineColor.alpha() )
{
/* Has only OUTLINE. */
painter->setPen( QPen( shadowColor, mLineWidth.pt() ) );
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
///
void LabelModelEllipseObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record );
///
/// Draw object itself
///
void LabelModelEllipseObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const
{
QColor lineColor = mLineColorNode.color( record );
QColor fillColor = mFillColorNode.color( record );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
painter->setBrush( fillColor );
painter->setPen( QPen( lineColor, mLineWidth.pt() ) );
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"
///
/// Label Model Ellipse Object
///
class LabelModelEllipseObject : public LabelModelShapeObject
namespace glabels
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelEllipseObject();
LabelModelEllipseObject( const LabelModelEllipseObject* object );
virtual ~LabelModelEllipseObject();
///
/// Label Model Ellipse Object
///
class LabelModelEllipseObject : public LabelModelShapeObject
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelEllipseObject();
LabelModelEllipseObject( const LabelModelEllipseObject* object );
virtual ~LabelModelEllipseObject();
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelEllipseObject* clone() const;
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelEllipseObject* clone() const;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
};
};
}
#endif // LabelModelEllipseObject_h
+246 -246
View File
@@ -30,287 +30,287 @@
#include "Size.h"
namespace
namespace glabels
{
}
///
/// Static data
///
QImage* LabelModelImageObject::smDefaultImage = 0;
///
/// Static data
///
QImage* LabelModelImageObject::smDefaultImage = 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 )
///
/// Constructor
///
LabelModelImageObject::LabelModelImageObject() : mImage(0), mSvg(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 );
///
/// 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 )
if ( smDefaultImage == 0 )
{
painter->setBrush( shadowColor );
painter->setPen( QPen( Qt::NoPen ) );
painter->drawRect( destRect );
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
}
}
///
/// 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 )
///
/// Copy constructor
///
LabelModelImageObject::LabelModelImageObject( const LabelModelImageObject* object ) : LabelModelObject(object)
{
delete mImage;
}
if ( mSvg )
{
delete mSvg;
mFilenameNode = object->mFilenameNode;
}
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 );
if ( !mSvg->isValid() )
{
mSvg = 0;
}
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;
}
}
painter->setBrush( shadowColor );
painter->setPen( QPen( Qt::NoPen ) );
painter->drawRect( destRect );
}
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 ( mImage->isNull() )
if ( (fileInfo.suffix() == "svg") || (fileInfo.suffix() == "SVG") )
{
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 )
mSvg = new QSvgRenderer( filename );
if ( !mSvg->isValid() )
{
mH = mW*aspectRatio;
mSvg = 0;
}
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
///
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++ )
///
/// Create shadow image
///
QImage* LabelModelImageObject::createShadowImage( const QColor& color ) const
{
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"
///
/// Label Model Image Object
///
class LabelModelImageObject : public LabelModelObject
namespace glabels
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelImageObject();
LabelModelImageObject( const LabelModelImageObject* object );
virtual ~LabelModelImageObject();
///
/// Label Model Image Object
///
class LabelModelImageObject : public LabelModelObject
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelImageObject();
LabelModelImageObject( const LabelModelImageObject* object );
virtual ~LabelModelImageObject();
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelImageObject* clone() const;
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelImageObject* clone() const;
///////////////////////////////////////////////////////////////
// Property Implementations
///////////////////////////////////////////////////////////////
public:
//
// Image Property: filenameNode
//
virtual TextNode filenameNode( void ) const;
virtual void setFilenameNode( const TextNode& value );
///////////////////////////////////////////////////////////////
// Property Implementations
///////////////////////////////////////////////////////////////
public:
//
// Image Property: filenameNode
//
virtual TextNode filenameNode( void ) const;
virtual void setFilenameNode( const TextNode& value );
//
// Image Property: originalSize
//
virtual Size originalSize() const;
//
// Image Property: originalSize
//
virtual Size originalSize() const;
///////////////////////////////////////////////////////////////
// Capability Implementations
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Capability Implementations
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
///////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////
void loadImage();
QImage* createShadowImage( const QColor& color ) const;
///////////////////////////////////////////////////////////////
// Private
///////////////////////////////////////////////////////////////
void loadImage();
QImage* createShadowImage( const QColor& color ) const;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
protected:
TextNode mFilenameNode;
QImage* mImage;
QSvgRenderer* mSvg;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
protected:
TextNode mFilenameNode;
QImage* mImage;
QSvgRenderer* mSvg;
static QImage* smDefaultImage;
static QImage* smDefaultImage;
};
};
}
#endif // LabelModelImageObject_h
+156 -147
View File
@@ -25,176 +25,185 @@
#include <QPen>
namespace
namespace glabels
{
const double slopPixels = 2;
}
///
/// Constructor
///
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 )
//
// Private
//
namespace
{
delete handle;
const double slopPixels = 2;
}
mHandles.clear();
}
///
/// Clone
///
LabelModelLineObject* LabelModelLineObject::clone() const
{
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 )
///
/// Constructor
///
LabelModelLineObject::LabelModelLineObject()
{
mLineWidth = value;
emit changed();
mOutline = 0;
mHandles << new HandleP1( this );
mHandles << new HandleP2( this );
mLineWidth = 1.0;
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
}
}
///
/// 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 )
///
/// Copy constructor
///
LabelModelLineObject::LabelModelLineObject( const LabelModelLineObject* object )
: LabelModelObject(object)
{
mLineColorNode = value;
emit changed();
mLineWidth = object->mLineWidth;
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
///
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() )
///
/// Can Line Color Capability Implementation
///
bool LabelModelLineObject::canLineColor()
{
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() );
}
}
///
/// 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
///
QPainterPath LabelModelLineObject::hoverPath( double scale ) const
{
QPainterPath path;
if ( mLineColorNode.color().alpha() )
///
/// Path to test for hover condition
///
QPainterPath LabelModelLineObject::hoverPath( double scale ) const
{
//
// Build a thin rectangle representing line
//
double rPts = mLineWidth.pt()/2 + slopPixels / scale;
QPainterPath path;
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
if ( mLineColorNode.color().alpha() )
{
//
// 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.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.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( - rPts*dx, rPts*dy );
path.closeSubpath();
path.closeSubpath();
}
return path;
}
return path;
}
+55 -50
View File
@@ -25,71 +25,76 @@
#include "LabelModelObject.h"
///
/// Label Model Line Object
///
class LabelModelLineObject : public LabelModelObject
namespace glabels
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelLineObject();
LabelModelLineObject( const LabelModelLineObject* object );
virtual ~LabelModelLineObject();
///
/// Label Model Line Object
///
class LabelModelLineObject : public LabelModelObject
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelLineObject();
LabelModelLineObject( const LabelModelLineObject* object );
virtual ~LabelModelLineObject();
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelLineObject* clone() const;
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelLineObject* clone() const;
///////////////////////////////////////////////////////////////
// Property Implementations
///////////////////////////////////////////////////////////////
public:
//
// Line Property: lineWidth
//
virtual glabels::Distance lineWidth( void ) const;
virtual void setLineWidth( const glabels::Distance& value );
///////////////////////////////////////////////////////////////
// Property Implementations
///////////////////////////////////////////////////////////////
public:
//
// Line Property: lineWidth
//
virtual Distance lineWidth( void ) const;
virtual void setLineWidth( const Distance& value );
//
// Line Property: lineColorNode
//
virtual ColorNode lineColorNode( void ) const;
virtual void setLineColorNode( const ColorNode& value );
//
// Line Property: lineColorNode
//
virtual ColorNode lineColorNode( void ) const;
virtual void setLineColorNode( const ColorNode& value );
///////////////////////////////////////////////////////////////
// Capability Implementations
///////////////////////////////////////////////////////////////
public:
virtual bool canLineColor();
virtual bool canLineWidth();
///////////////////////////////////////////////////////////////
// Capability Implementations
///////////////////////////////////////////////////////////////
public:
virtual bool canLineColor();
virtual bool canLineWidth();
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
protected:
glabels::Distance mLineWidth;
ColorNode mLineColorNode;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
protected:
Distance mLineWidth;
ColorNode mLineColorNode;
};
};
}
#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"
// Forward References
class Region;
class Size;
///
/// Label Model Object Base Class
///
class LabelModelObject : public QObject
namespace glabels
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
protected:
LabelModelObject();
LabelModelObject( const LabelModelObject* object );
public:
virtual ~LabelModelObject();
// Forward References
class Region;
class Size;
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelObject* clone() const = 0;
///
/// Label Model Object Base Class
///
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:
void moved();
void changed();
///////////////////////////////////////////////////////////////
// Signals
///////////////////////////////////////////////////////////////
signals:
void moved();
void changed();
///////////////////////////////////////////////////////////////
// Common Properties
///////////////////////////////////////////////////////////////
public:
//
// ID Property.
//
int id() const;
///////////////////////////////////////////////////////////////
// Common Properties
///////////////////////////////////////////////////////////////
public:
//
// ID Property.
//
int id() const;
//
// Selected Property.
//
bool isSelected() const;
void select( bool value = true );
void unselect();
//
// Selected Property.
//
bool isSelected() const;
void select( bool value = true );
void unselect();
//
// x0 Property ( x coordinate of origin )
//
glabels::Distance x0() const;
void setX0( const glabels::Distance& value );
//
// x0 Property ( x coordinate of origin )
//
Distance x0() const;
void setX0( const Distance& value );
//
// y0 Property ( y coordinate of origin )
//
glabels::Distance y0() const;
void setY0( const glabels::Distance& value );
//
// y0 Property ( y coordinate of origin )
//
Distance y0() const;
void setY0( const Distance& value );
//
// w Property ( width of bounding box )
//
glabels::Distance w() const;
void setW( const glabels::Distance& value );
//
// w Property ( width of bounding box )
//
Distance w() const;
void setW( const Distance& value );
//
// h Property ( height of bounding box )
//
glabels::Distance h() const;
void setH( const glabels::Distance& value );
//
// h Property ( height of bounding box )
//
Distance h() const;
void setH( const Distance& value );
//
// Transformation Matrix Property
//
QMatrix matrix() const;
void setMatrix( const QMatrix& value );
//
// Transformation Matrix Property
//
QMatrix matrix() const;
void setMatrix( const QMatrix& value );
//
// Shadow State Property
//
bool shadow() const;
void setShadow( bool value );
//
// Shadow State Property
//
bool shadow() const;
void setShadow( bool value );
//
// Shadow x Offset Property
//
glabels::Distance shadowX() const;
void setShadowX( const glabels::Distance& value );
//
// Shadow x Offset Property
//
Distance shadowX() const;
void setShadowX( const Distance& value );
//
// Shadow y Offset Property
//
glabels::Distance shadowY() const;
void setShadowY( const glabels::Distance& value );
//
// Shadow y Offset Property
//
Distance shadowY() const;
void setShadowY( const Distance& value );
//
// Shadow opacity Property
//
double shadowOpacity() const;
void setShadowOpacity( double value );
//
// Shadow opacity Property
//
double shadowOpacity() const;
void setShadowOpacity( double value );
//
// Shadow Color Property
//
ColorNode shadowColorNode() const;
void setShadowColorNode( const ColorNode& value );
//
// Shadow Color Property
//
ColorNode shadowColorNode() const;
void setShadowColorNode( const ColorNode& value );
///////////////////////////////////////////////////////////////
// Text Properties Virtual Interface
///////////////////////////////////////////////////////////////
public:
//
// Virtual Text Property: text
//
virtual QString text() const;
virtual void setText( const QString &value );
///////////////////////////////////////////////////////////////
// Text Properties Virtual Interface
///////////////////////////////////////////////////////////////
public:
//
// Virtual Text Property: text
//
virtual QString text() const;
virtual void setText( const QString &value );
//
// Virtual Text Property: fontFamily
//
virtual QString fontFamily() const;
virtual void setFontFamily( const QString &value );
//
// Virtual Text Property: fontFamily
//
virtual QString fontFamily() const;
virtual void setFontFamily( const QString &value );
//
// Virtual Text Property: fontSize
//
virtual double fontSize() const;
virtual void setFontSize( double value );
//
// Virtual Text Property: fontSize
//
virtual double fontSize() const;
virtual void setFontSize( double value );
//
// Virtual Text Property: fontWeight
//
virtual QFont::Weight fontWeight() const;
virtual void setFontWeight( QFont::Weight value );
//
// Virtual Text Property: fontWeight
//
virtual QFont::Weight fontWeight() const;
virtual void setFontWeight( QFont::Weight value );
//
// Virtual Text Property: fontItalicFlag
//
virtual bool fontItalicFlag() const;
virtual void setFontItalicFlag( bool value );
//
// Virtual Text Property: fontItalicFlag
//
virtual bool fontItalicFlag() const;
virtual void setFontItalicFlag( bool value );
//
// Virtual Text Property: fontUnderlineFlag
//
virtual bool fontUnderlineFlag() const;
virtual void setFontUnderlineFlag( bool value );
//
// Virtual Text Property: fontUnderlineFlag
//
virtual bool fontUnderlineFlag() const;
virtual void setFontUnderlineFlag( bool value );
//
// Virtual Text Property: textColorNode
//
virtual ColorNode textColorNode() const;
virtual void setTextColorNode( const ColorNode &value );
//
// Virtual Text Property: textColorNode
//
virtual ColorNode textColorNode() const;
virtual void setTextColorNode( const ColorNode &value );
//
// Virtual Text Property: textHAlign
//
virtual Qt::Alignment textHAlign() const;
virtual void setTextHAlign( Qt::Alignment value );
//
// Virtual Text Property: textHAlign
//
virtual Qt::Alignment textHAlign() const;
virtual void setTextHAlign( Qt::Alignment value );
//
// Virtual Text Property: textVAlign
//
virtual Qt::Alignment textVAlign() const;
virtual void setTextVAlign( Qt::Alignment value );
//
// Virtual Text Property: textVAlign
//
virtual Qt::Alignment textVAlign() const;
virtual void setTextVAlign( Qt::Alignment value );
//
// Virtual Text Property: textLineSpacing
//
virtual double textLineSpacing() const;
virtual void setTextLineSpacing( double value );
//
// Virtual Text Property: textLineSpacing
//
virtual double textLineSpacing() const;
virtual void setTextLineSpacing( double value );
///////////////////////////////////////////////////////////////
// Image Properties Virtual Interface
///////////////////////////////////////////////////////////////
public:
//
// Virtual Image Property: filenameNode
//
virtual TextNode filenameNode() const;
virtual void setFilenameNode( const TextNode &value );
///////////////////////////////////////////////////////////////
// Image Properties Virtual Interface
///////////////////////////////////////////////////////////////
public:
//
// Virtual Image Property: filenameNode
//
virtual TextNode filenameNode() const;
virtual void setFilenameNode( const TextNode &value );
//
// Virtual Image Property: originalSize (read-only)
//
virtual Size originalSize() const;
//
// Virtual Image Property: originalSize (read-only)
//
virtual Size originalSize() const;
///////////////////////////////////////////////////////////////
// Shape Properties Virtual Interface
///////////////////////////////////////////////////////////////
public:
//
// Virtual Shape Property: lineWidth
//
virtual glabels::Distance lineWidth() const;
virtual void setLineWidth( const glabels::Distance& value );
///////////////////////////////////////////////////////////////
// Shape Properties Virtual Interface
///////////////////////////////////////////////////////////////
public:
//
// Virtual Shape Property: lineWidth
//
virtual Distance lineWidth() const;
virtual void setLineWidth( const Distance& value );
//
// Virtual Shape Property: lineColorNode
//
virtual ColorNode lineColorNode() const;
virtual void setLineColorNode( const ColorNode &value );
//
// Virtual Shape Property: lineColorNode
//
virtual ColorNode lineColorNode() const;
virtual void setLineColorNode( const ColorNode &value );
//
// Virtual Shape Property: fillColorNode
//
virtual ColorNode fillColorNode() const;
virtual void setFillColorNode( const ColorNode &value );
//
// Virtual Shape Property: fillColorNode
//
virtual ColorNode fillColorNode() const;
virtual void setFillColorNode( const ColorNode &value );
///////////////////////////////////////////////////////////////
// Barcode Properties Virtual Interface
///////////////////////////////////////////////////////////////
public:
//
// Virtual Barcode Property: bcDataNode
//
virtual TextNode bcDataNode() const;
virtual void setBcDataNode( const TextNode &value );
///////////////////////////////////////////////////////////////
// Barcode Properties Virtual Interface
///////////////////////////////////////////////////////////////
public:
//
// Virtual Barcode Property: bcDataNode
//
virtual TextNode bcDataNode() const;
virtual void setBcDataNode( const TextNode &value );
//
// Virtual Barcode Property: bcTextFlag
//
virtual bool bcTextFlag() const;
virtual void setBcTextFlag( bool value );
//
// Virtual Barcode Property: bcTextFlag
//
virtual bool bcTextFlag() const;
virtual void setBcTextFlag( bool value );
//
// Virtual Barcode Property: bcChecksumFlag
//
virtual bool bcChecksumFlag() const;
virtual void setBcChecksumFlag( bool value );
//
// Virtual Barcode Property: bcChecksumFlag
//
virtual bool bcChecksumFlag() const;
virtual void setBcChecksumFlag( bool value );
//
// Virtual Barcode Property: bcColorNode
//
virtual ColorNode bcColorNode() const;
virtual void setBcColorNode( const ColorNode &value );
//
// Virtual Barcode Property: bcColorNode
//
virtual ColorNode bcColorNode() const;
virtual void setBcColorNode( const ColorNode &value );
//
// Virtual Barcode Property: bcStyle
//
virtual BarcodeStyle bcStyle() const;
virtual void setBcStyle( const BarcodeStyle &value );
//
// Virtual Barcode Property: bcStyle
//
virtual BarcodeStyle bcStyle() const;
virtual void setBcStyle( const BarcodeStyle &value );
//
// Virtual Barcode Property: bcFormatDigits
//
virtual int bcFormatDigits() const;
virtual void setBcFormatDigits( int value );
//
// Virtual Barcode Property: bcFormatDigits
//
virtual int bcFormatDigits() const;
virtual void setBcFormatDigits( int value );
///////////////////////////////////////////////////////////////
// Capabilities (Overridden by concrete classes.)
///////////////////////////////////////////////////////////////
public:
virtual bool canText() const;
virtual bool canFill() const;
virtual bool canLineColor() const;
virtual bool canLineWidth() const;
///////////////////////////////////////////////////////////////
// Capabilities (Overridden by concrete classes.)
///////////////////////////////////////////////////////////////
public:
virtual bool canText() const;
virtual bool canFill() const;
virtual bool canLineColor() const;
virtual bool canLineWidth() const;
///////////////////////////////////////////////////////////////
// Position and Size methods
///////////////////////////////////////////////////////////////
public:
void setPosition( const glabels::Distance& x0, const glabels::Distance& y0 );
void setPositionRelative( const glabels::Distance& dx, const glabels::Distance& dy );
Size size() const;
void setSize( const glabels::Distance& w, const glabels::Distance& h );
void setSize( const Size& size );
void setSizeHonorAspect( const glabels::Distance& w, const glabels::Distance& h );
void setWHonorAspect( const glabels::Distance& w );
void setHHonorAspect( const glabels::Distance& h );
Region getExtent();
void rotate( double thetaDegs );
void flipHoriz();
void flipVert();
bool isLocatedAt( double scale, const glabels::Distance& x, const glabels::Distance& y ) const;
Handle* handleAt( double scale, const glabels::Distance& x, const glabels::Distance& y ) const;
///////////////////////////////////////////////////////////////
// Position and Size methods
///////////////////////////////////////////////////////////////
public:
void setPosition( const Distance& x0, const Distance& y0 );
void setPositionRelative( const Distance& dx, const Distance& dy );
Size size() const;
void setSize( const Distance& w, const Distance& h );
void setSize( const Size& size );
void setSizeHonorAspect( const Distance& w, const Distance& h );
void setWHonorAspect( const Distance& w );
void setHHonorAspect( const Distance& h );
Region getExtent();
void rotate( double thetaDegs );
void flipHoriz();
void flipVert();
bool isLocatedAt( double scale, const Distance& x, const Distance& y ) const;
Handle* handleAt( double scale, const Distance& x, const Distance& y ) const;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
public:
void draw( QPainter* painter, bool inEditor, merge::Record* record ) const;
void drawSelectionHighlight( QPainter* painter, double scale ) const;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
public:
void draw( QPainter* painter, bool inEditor, merge::Record* record ) const;
void drawSelectionHighlight( QPainter* painter, double scale ) const;
protected:
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 QPainterPath hoverPath( double scale ) const = 0;
protected:
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 QPainterPath hoverPath( double scale ) const = 0;
virtual void sizeUpdated();
virtual void sizeUpdated();
///////////////////////////////////////////////////////////////
// Protected Members
///////////////////////////////////////////////////////////////
protected:
bool mSelectedFlag;
///////////////////////////////////////////////////////////////
// Protected Members
///////////////////////////////////////////////////////////////
protected:
bool mSelectedFlag;
glabels::Distance mX0;
glabels::Distance mY0;
glabels::Distance mW;
glabels::Distance mH;
Distance mX0;
Distance mY0;
Distance mW;
Distance mH;
bool mShadowState;
glabels::Distance mShadowX;
glabels::Distance mShadowY;
double mShadowOpacity;
ColorNode mShadowColorNode;
bool mShadowState;
Distance mShadowX;
Distance mShadowY;
double mShadowOpacity;
ColorNode mShadowColorNode;
QList<Handle*> mHandles;
Outline* mOutline;
QList<Handle*> mHandles;
Outline* mOutline;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
private:
static int msNextId;
int mId;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
private:
static int msNextId;
int mId;
QMatrix mMatrix;
QMatrix mMatrix;
};
};
}
#endif // LabelModelObject_h
+125 -120
View File
@@ -25,142 +25,147 @@
#include <QPen>
///
/// Constructor
///
LabelModelShapeObject::LabelModelShapeObject()
namespace glabels
{
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 ) );
}
///
/// 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 )
///
/// Constructor
///
LabelModelShapeObject::LabelModelShapeObject()
{
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
///
glabels::Distance LabelModelShapeObject::lineWidth( void ) const
{
return mLineWidth;
}
///
/// Line Width Property Setter
///
void LabelModelShapeObject::setLineWidth( const glabels::Distance& value )
{
if ( mLineWidth != value )
///
/// Copy constructor
///
LabelModelShapeObject::LabelModelShapeObject( const LabelModelShapeObject* object ) : LabelModelObject(object)
{
mLineWidth = value;
emit changed();
mLineWidth = object->mLineWidth;
mLineColorNode = object->mLineColorNode;
mFillColorNode = object->mFillColorNode;
}
}
///
/// 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 )
///
/// Destructor
///
LabelModelShapeObject::~LabelModelShapeObject()
{
mLineColorNode = value;
emit changed();
delete mOutline;
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
///
ColorNode LabelModelShapeObject::fillColorNode( void ) const
{
return mFillColorNode;
}
///
/// Fill Color Node Property Setter
///
void LabelModelShapeObject::setFillColorNode( const ColorNode& value )
{
if ( mFillColorNode != value )
///
/// Fill Color Node Property Getter
///
ColorNode LabelModelShapeObject::fillColorNode( void ) const
{
mFillColorNode = value;
emit changed();
return mFillColorNode;
}
///
/// Fill Color Node Property Setter
///
void LabelModelShapeObject::setFillColorNode( const ColorNode& value )
{
if ( mFillColorNode != value )
{
mFillColorNode = value;
emit changed();
}
}
}
///
/// Can Fill Capability Implementation
///
bool LabelModelShapeObject::canFill()
{
return true;
}
///
/// Can Line Color Capability Implementation
///
bool LabelModelShapeObject::canLineColor()
{
return true;
}
///
/// Can Line Width Capability Implementation
///
bool LabelModelShapeObject::canLineWidth()
{
return true;
///
/// Can Fill Capability Implementation
///
bool LabelModelShapeObject::canFill()
{
return true;
}
///
/// Can Line Color Capability Implementation
///
bool LabelModelShapeObject::canLineColor()
{
return true;
}
///
/// Can Line Width Capability Implementation
///
bool LabelModelShapeObject::canLineWidth()
{
return true;
}
}
+52 -47
View File
@@ -25,66 +25,71 @@
#include "LabelModelObject.h"
///
/// Label Model Shape Object (Box or Ellipse)
///
class LabelModelShapeObject : public LabelModelObject
namespace glabels
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
protected:
LabelModelShapeObject();
LabelModelShapeObject( const LabelModelShapeObject* object );
public:
virtual ~LabelModelShapeObject();
///
/// Label Model Shape Object (Box or Ellipse)
///
class LabelModelShapeObject : public LabelModelObject
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
protected:
LabelModelShapeObject();
LabelModelShapeObject( const LabelModelShapeObject* object );
public:
virtual ~LabelModelShapeObject();
///////////////////////////////////////////////////////////////
// Property Implementations
///////////////////////////////////////////////////////////////
public:
//
// Shape Property: lineWidth
//
virtual glabels::Distance lineWidth( void ) const;
virtual void setLineWidth( const glabels::Distance& value );
///////////////////////////////////////////////////////////////
// Property Implementations
///////////////////////////////////////////////////////////////
public:
//
// Shape Property: lineWidth
//
virtual Distance lineWidth( void ) const;
virtual void setLineWidth( const Distance& value );
//
// Shape Property: lineColorNode
//
virtual ColorNode lineColorNode( void ) const;
virtual void setLineColorNode( const ColorNode& value );
//
// Shape Property: lineColorNode
//
virtual ColorNode lineColorNode( void ) const;
virtual void setLineColorNode( const ColorNode& value );
//
// Shape Property: fillColorNode
//
virtual ColorNode fillColorNode( void ) const;
virtual void setFillColorNode( const ColorNode& value );
//
// Shape Property: fillColorNode
//
virtual ColorNode fillColorNode( void ) const;
virtual void setFillColorNode( const ColorNode& value );
///////////////////////////////////////////////////////////////
// Capability Implementations
///////////////////////////////////////////////////////////////
public:
virtual bool canFill();
virtual bool canLineColor();
virtual bool canLineWidth();
///////////////////////////////////////////////////////////////
// Capability Implementations
///////////////////////////////////////////////////////////////
public:
virtual bool canFill();
virtual bool canLineColor();
virtual bool canLineWidth();
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
protected:
glabels::Distance mLineWidth;
ColorNode mLineColorNode;
ColorNode mFillColorNode;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
protected:
Distance mLineWidth;
ColorNode mLineColorNode;
ColorNode mFillColorNode;
};
};
}
#endif // LabelModelShapeObject_h
File diff suppressed because it is too large Load Diff
+113 -108
View File
@@ -27,148 +27,153 @@
#include "LabelModelObject.h"
///
/// Label Model Line Object
///
class LabelModelTextObject : public LabelModelObject
namespace glabels
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelTextObject();
LabelModelTextObject( const LabelModelTextObject* object );
virtual ~LabelModelTextObject();
///
/// Label Model Line Object
///
class LabelModelTextObject : public LabelModelObject
{
Q_OBJECT
///////////////////////////////////////////////////////////////
// Lifecycle Methods
///////////////////////////////////////////////////////////////
public:
LabelModelTextObject();
LabelModelTextObject( const LabelModelTextObject* object );
virtual ~LabelModelTextObject();
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelTextObject* clone() const;
///////////////////////////////////////////////////////////////
// Object duplication
///////////////////////////////////////////////////////////////
virtual LabelModelTextObject* clone() const;
///////////////////////////////////////////////////////////////
// Property Implementations
///////////////////////////////////////////////////////////////
public:
//
// Text Property: text
//
virtual QString text() const;
virtual void setText( const QString &value );
///////////////////////////////////////////////////////////////
// Property Implementations
///////////////////////////////////////////////////////////////
public:
//
// Text Property: text
//
virtual QString text() const;
virtual void setText( const QString &value );
//
// Text Property: fontFamily
//
virtual QString fontFamily() const;
virtual void setFontFamily( const QString &value );
//
// Text Property: fontFamily
//
virtual QString fontFamily() const;
virtual void setFontFamily( const QString &value );
//
// Text Property: fontSize
//
virtual double fontSize() const;
virtual void setFontSize( double value );
//
// Text Property: fontSize
//
virtual double fontSize() const;
virtual void setFontSize( double value );
//
// Text Property: fontWeight
//
virtual QFont::Weight fontWeight() const;
virtual void setFontWeight( QFont::Weight value );
//
// Text Property: fontWeight
//
virtual QFont::Weight fontWeight() const;
virtual void setFontWeight( QFont::Weight value );
//
// Text Property: fontItalicFlag
//
virtual bool fontItalicFlag() const;
virtual void setFontItalicFlag( bool value );
//
// Text Property: fontItalicFlag
//
virtual bool fontItalicFlag() const;
virtual void setFontItalicFlag( bool value );
//
// Text Property: fontUnderlineFlag
//
virtual bool fontUnderlineFlag() const;
virtual void setFontUnderlineFlag( bool value );
//
// Text Property: fontUnderlineFlag
//
virtual bool fontUnderlineFlag() const;
virtual void setFontUnderlineFlag( bool value );
//
// Text Property: textColorNode
//
virtual ColorNode textColorNode() const;
virtual void setTextColorNode( const ColorNode &value );
//
// Text Property: textColorNode
//
virtual ColorNode textColorNode() const;
virtual void setTextColorNode( const ColorNode &value );
//
// Text Property: textHAlign
//
virtual Qt::Alignment textHAlign() const;
virtual void setTextHAlign( Qt::Alignment value );
//
// Text Property: textHAlign
//
virtual Qt::Alignment textHAlign() const;
virtual void setTextHAlign( Qt::Alignment value );
//
// Text Property: textVAlign
//
virtual Qt::Alignment textVAlign() const;
virtual void setTextVAlign( Qt::Alignment value );
//
// Text Property: textVAlign
//
virtual Qt::Alignment textVAlign() const;
virtual void setTextVAlign( Qt::Alignment value );
//
// Text Property: textLineSpacing
//
virtual double textLineSpacing() const;
virtual void setTextLineSpacing( double value );
//
// Text Property: textLineSpacing
//
virtual double textLineSpacing() const;
virtual void setTextLineSpacing( double value );
///////////////////////////////////////////////////////////////
// Capability Implementations
///////////////////////////////////////////////////////////////
public:
virtual bool canText();
///////////////////////////////////////////////////////////////
// Capability Implementations
///////////////////////////////////////////////////////////////
public:
virtual bool canText();
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
virtual void drawShadow( 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;
///////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////
private:
virtual void sizeUpdated();
void update();
void drawTextInEditor( QPainter* painter, const QColor& color ) const;
void drawText( QPainter* painter, const QColor&color, merge::Record* record ) const;
QString expandText( QString text, merge::Record* record ) const;
///////////////////////////////////////////////////////////////
// Private methods
///////////////////////////////////////////////////////////////
private:
virtual void sizeUpdated();
void update();
void drawTextInEditor( QPainter* painter, const QColor& color ) const;
void drawText( QPainter* painter, const QColor&color, merge::Record* record ) const;
QString expandText( QString text, merge::Record* record ) const;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
private:
QString mText;
QString mFontFamily;
double mFontSize;
QFont::Weight mFontWeight;
bool mFontItalicFlag;
bool mFontUnderlineFlag;
ColorNode mTextColorNode;
Qt::Alignment mTextHAlign;
Qt::Alignment mTextVAlign;
double mTextLineSpacing;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
private:
QString mText;
QString mFontFamily;
double mFontSize;
QFont::Weight mFontWeight;
bool mFontItalicFlag;
bool mFontUnderlineFlag;
ColorNode mTextColorNode;
Qt::Alignment mTextHAlign;
Qt::Alignment mTextVAlign;
double mTextLineSpacing;
QList<QTextLayout*> mEditorLayouts;
QPainterPath mHoverPath;
QList<QTextLayout*> mEditorLayouts;
QPainterPath mHoverPath;
};
};
}
#endif // LabelModelTextObject_h
+9 -7
View File
@@ -23,7 +23,7 @@
#include <cmath>
#include "privateConstants.h"
#include "Constants.h"
namespace glabels
@@ -37,6 +37,7 @@ namespace glabels
const Distance& 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),
mDx(other.mDx), mDy(other.mDy)
{
// empty
}
@@ -85,12 +87,12 @@ namespace glabels
bool Layout::isSimilarTo( const Layout *other )
{
return ( (mNx == other->mNx) &&
(mNy == other->mNy) &&
(fabs(mX0 - other->mX0) < Constants::EPSILON) &&
(fabs(mY0 - other->mY0) < Constants::EPSILON) &&
(fabs(mDx - other->mDx) < Constants::EPSILON) &&
(fabs(mDy - other->mDy) < Constants::EPSILON) );
return ( (mNx == other->mNx) &&
(mNy == other->mNy) &&
(fabs(mX0 - other->mX0) < EPSILON) &&
(fabs(mY0 - other->mY0) < EPSILON) &&
(fabs(mDx - other->mDx) < 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 <QToolBar>
// Forward References
class LabelEditor;
class LabelModel;
class MergeView;
class ObjectEditor;
class PrintView;
class PropertiesView;
class StartupView;
class UndoRedoModel;
///
/// MainWindow Widget
///
class MainWindow : public QMainWindow
namespace glabels
{
Q_OBJECT
// Forward References
class LabelEditor;
class LabelModel;
class MergeView;
class ObjectEditor;
class PrintView;
class PropertiesView;
class StartupView;
class UndoRedoModel;
/////////////////////////////////////
// Lifecycle
/////////////////////////////////////
public:
MainWindow();
virtual ~MainWindow();
///
/// MainWindow Widget
///
class MainWindow : public QMainWindow
{
Q_OBJECT
/////////////////////////////////////
// Public Methods
/////////////////////////////////////
public:
LabelModel* model() const;
void setModel( LabelModel* label );
bool isEmpty() const;
/////////////////////////////////////
// Lifecycle
/////////////////////////////////////
public:
MainWindow();
virtual ~MainWindow();
/////////////////////////////////////
// Events
/////////////////////////////////////
protected:
void closeEvent( QCloseEvent *event );
/////////////////////////////////////
// Public Methods
/////////////////////////////////////
public:
LabelModel* model() const;
void setModel( LabelModel* label );
bool isEmpty() const;
/////////////////////////////////////
// Slots
/////////////////////////////////////
private slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
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();
/////////////////////////////////////
// Events
/////////////////////////////////////
protected:
void closeEvent( QCloseEvent *event );
/////////////////////////////////////
// Internal Private Methods
/////////////////////////////////////
private:
void createActions();
void createMenus();
void createToolBars();
void createStatusBar();
/////////////////////////////////////
// Slots
/////////////////////////////////////
private slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous);
QWidget* createWelcomePage();
QWidget* createPropertiesPage();
QWidget* createEditorPage();
QWidget* createMergePage();
QWidget* createPrintPage();
void clipboardChanged();
void setWelcomeMode( bool );
void setDocVerbsEnabled( bool );
void setDocModifiedVerbsEnabled( bool );
void setPasteVerbsEnabled( bool );
void setSelectionVerbsEnabled( bool );
void setMultiSelectionVerbsEnabled( bool );
void fileNew();
void fileOpen();
void fileSave();
void fileSaveAs();
void fileTemplateDesigner();
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 writeSettings();
void viewFileToolBar( bool );
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:
QMenu* fileMenu;
QMenu* editMenu;
QMenu* viewMenu;
QMenu* viewToolBarsMenu;
QMenu* objectsMenu;
QMenu* objectsCreateMenu;
QMenu* objectsOrderMenu;
QMenu* objectsXformMenu;
QMenu* objectsAlignMenu;
QMenu* objectsCenterMenu;
QMenu* helpMenu;
/////////////////////////////////////
// Private Data
/////////////////////////////////////
private:
QMenu* fileMenu;
QMenu* editMenu;
QMenu* viewMenu;
QMenu* viewToolBarsMenu;
QMenu* objectsMenu;
QMenu* objectsCreateMenu;
QMenu* objectsOrderMenu;
QMenu* objectsXformMenu;
QMenu* objectsAlignMenu;
QMenu* objectsCenterMenu;
QMenu* helpMenu;
QMenu* contextMenu;
QMenu* contextOrderMenu;
QMenu* contextXformMenu;
QMenu* contextAlignMenu;
QMenu* contextCenterMenu;
QMenu* noSelectionContextMenu;
QMenu* contextMenu;
QMenu* contextOrderMenu;
QMenu* contextXformMenu;
QMenu* contextAlignMenu;
QMenu* contextCenterMenu;
QMenu* noSelectionContextMenu;
QToolBar* fileToolBar;
QToolBar* editorToolBar;
QToolBar* fileToolBar;
QToolBar* editorToolBar;
LabelModel* mModel;
UndoRedoModel* mUndoRedoModel;
LabelModel* mModel;
UndoRedoModel* mUndoRedoModel;
QListWidget* mContents;
QListWidgetItem* mWelcomeButton;
QListWidgetItem* mPropertiesButton;
QListWidgetItem* mEditorButton;
QListWidgetItem* mMergeButton;
QListWidgetItem* mPrintButton;
QListWidget* mContents;
QListWidgetItem* mWelcomeButton;
QListWidgetItem* mPropertiesButton;
QListWidgetItem* mEditorButton;
QListWidgetItem* mMergeButton;
QListWidgetItem* mPrintButton;
QStackedWidget* mPages;
StartupView* mWelcomeView;
PropertiesView* mPropertiesView;
QScrollArea* mLabelEditorScrollArea;
LabelEditor* mLabelEditor;
ObjectEditor* mObjectEditor;
MergeView* mMergeView;
PrintView* mPrintView;
QStackedWidget* mPages;
StartupView* mWelcomeView;
PropertiesView* mPropertiesView;
QScrollArea* mLabelEditorScrollArea;
LabelEditor* mLabelEditor;
ObjectEditor* mObjectEditor;
MergeView* mMergeView;
PrintView* mPrintView;
QLabel* zoomInfoLabel;
QLabel* cursorInfoLabel;
QLabel* zoomInfoLabel;
QLabel* cursorInfoLabel;
QAction* fileNewAction;
QAction* fileOpenAction;
QAction* fileSaveAction;
QAction* fileSaveAsAction;
QAction* fileTemplateDesignerAction;
QAction* fileCloseAction;
QAction* fileExitAction;
QAction* fileNewAction;
QAction* fileOpenAction;
QAction* fileSaveAction;
QAction* fileSaveAsAction;
QAction* fileTemplateDesignerAction;
QAction* fileCloseAction;
QAction* fileExitAction;
QAction* editUndoAction;
QAction* editRedoAction;
QAction* editCutAction;
QAction* editCopyAction;
QAction* editPasteAction;
QAction* editDeleteAction;
QAction* editSelectAllAction;
QAction* editUnSelectAllAction;
QAction* editPreferencesAction;
QAction* editUndoAction;
QAction* editRedoAction;
QAction* editCutAction;
QAction* editCopyAction;
QAction* editPasteAction;
QAction* editDeleteAction;
QAction* editSelectAllAction;
QAction* editUnSelectAllAction;
QAction* editPreferencesAction;
QAction* viewFileToolBarAction;
QAction* viewEditorToolBarAction;
QAction* viewGridAction;
QAction* viewMarkupAction;
QAction* viewZoomInAction;
QAction* viewZoomOutAction;
QAction* viewZoom1To1Action;
QAction* viewZoomToFitAction;
QAction* viewFileToolBarAction;
QAction* viewEditorToolBarAction;
QAction* viewGridAction;
QAction* viewMarkupAction;
QAction* viewZoomInAction;
QAction* viewZoomOutAction;
QAction* viewZoom1To1Action;
QAction* viewZoomToFitAction;
QAction* objectsArrowModeAction;
QAction* objectsCreateTextAction;
QAction* objectsCreateBoxAction;
QAction* objectsCreateLineAction;
QAction* objectsCreateEllipseAction;
QAction* objectsCreateImageAction;
QAction* objectsCreateBarcodeAction;
QAction* objectsOrderRaiseAction;
QAction* objectsOrderLowerAction;
QAction* objectsXformRotateLeftAction;
QAction* objectsXformRotateRightAction;
QAction* objectsXformFlipHorizAction;
QAction* objectsXformFlipVertAction;
QAction* objectsAlignLeftAction;
QAction* objectsAlignHCenterAction;
QAction* objectsAlignRightAction;
QAction* objectsAlignTopAction;
QAction* objectsAlignVCenterAction;
QAction* objectsAlignBottomAction;
QAction* objectsCenterHorizAction;
QAction* objectsCenterVertAction;
QAction* objectsArrowModeAction;
QAction* objectsCreateTextAction;
QAction* objectsCreateBoxAction;
QAction* objectsCreateLineAction;
QAction* objectsCreateEllipseAction;
QAction* objectsCreateImageAction;
QAction* objectsCreateBarcodeAction;
QAction* objectsOrderRaiseAction;
QAction* objectsOrderLowerAction;
QAction* objectsXformRotateLeftAction;
QAction* objectsXformRotateRightAction;
QAction* objectsXformFlipHorizAction;
QAction* objectsXformFlipVertAction;
QAction* objectsAlignLeftAction;
QAction* objectsAlignHCenterAction;
QAction* objectsAlignRightAction;
QAction* objectsAlignTopAction;
QAction* objectsAlignVCenterAction;
QAction* objectsAlignBottomAction;
QAction* objectsCenterHorizAction;
QAction* objectsCenterVertAction;
QAction* helpContentsAction;
QAction* helpAboutAction;
QAction* helpContentsAction;
QAction* helpAboutAction;
QAction* contextCutAction;
QAction* contextCopyAction;
QAction* contextPasteAction;
QAction* contextDeleteAction;
};
QAction* contextCutAction;
QAction* contextCopyAction;
QAction* contextPasteAction;
QAction* contextDeleteAction;
};
}
#endif // MainWindow_h
+157 -154
View File
@@ -31,191 +31,194 @@
#include "TextSemicolonKeys.h"
namespace merge
namespace glabels
{
///
/// Static data
///
QMap<QString,Factory::BackendEntry> Factory::mBackendIdMap;
QMap<QString,Factory::BackendEntry> Factory::mBackendNameMap;
QStringList Factory::mNameList;
///
/// Constructor
///
Factory::Factory()
namespace merge
{
registerBackend( None::id(),
tr("None"),
NONE,
&None::create );
//
// 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,
&None::create );
registerBackend( TextCsv::id(),
tr("Text: Comma Separated Values (CSV)"),
FILE,
&TextCsv::create );
registerBackend( TextCsv::id(),
tr("Text: Comma Separated Values (CSV)"),
FILE,
&TextCsv::create );
registerBackend( TextCsvKeys::id(),
tr("Text: Comma Separated Values (CSV), keys on line 1"),
FILE,
&TextCsvKeys::create );
registerBackend( TextCsvKeys::id(),
tr("Text: Comma Separated Values (CSV), keys on line 1"),
FILE,
&TextCsvKeys::create );
registerBackend( TextTsv::id(),
tr("Text: Tab Separated Values (TSV)"),
FILE,
&TextTsv::create );
registerBackend( TextTsv::id(),
tr("Text: Tab Separated Values (TSV)"),
FILE,
&TextTsv::create );
registerBackend( TextTsvKeys::id(),
tr("Text: Tab Separated Values (TSV), keys on line 1"),
FILE,
&TextTsvKeys::create );
registerBackend( TextTsvKeys::id(),
tr("Text: Tab Separated Values (TSV), keys on line 1"),
FILE,
&TextTsvKeys::create );
registerBackend( TextColon::id(),
tr("Text: Colon Separated Values"),
FILE,
&TextColon::create );
registerBackend( TextColon::id(),
tr("Text: Colon Separated Values"),
FILE,
&TextColon::create );
registerBackend( TextColonKeys::id(),
tr("Text: Colon Separated Values, keys on line 1"),
FILE,
&TextColonKeys::create );
registerBackend( TextColonKeys::id(),
tr("Text: Colon Separated Values, keys on line 1"),
FILE,
&TextColonKeys::create );
registerBackend( TextSemicolon::id(),
tr("Text: Semicolon Separated Values"),
FILE,
&TextSemicolon::create );
registerBackend( TextSemicolon::id(),
tr("Text: Semicolon Separated Values"),
FILE,
&TextSemicolon::create );
registerBackend( TextSemicolonKeys::id(),
tr("Text: Semicolon Separated Values, keys on line 1"),
FILE,
&TextSemicolonKeys::create );
}
///
/// Initialize
///
void Factory::init()
{
static Factory* singletonInstance = 0;
if ( !singletonInstance )
{
singletonInstance = new Factory();
registerBackend( TextSemicolonKeys::id(),
tr("Text: Semicolon Separated Values, keys on line 1"),
FILE,
&TextSemicolonKeys::create );
}
}
///
/// Create Merge object
///
Merge* Factory::createMerge( const QString& id )
{
QMap<QString,BackendEntry>::iterator iBackend = mBackendIdMap.find( id );
if ( iBackend != mBackendIdMap.end() )
///
/// Initialize
///
void Factory::init()
{
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();
}
///
/// 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;
return None::create();
}
else
{
return tr("None");
}
}
///
/// Convert name to ID
///
QString Factory::nameToId( const QString& name )
{
if ( mBackendNameMap.contains( name ) )
///
/// Get name list
///
QStringList Factory::nameList()
{
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";
}
}
///
/// Convert ID to type
///
Factory::SourceType Factory::idToType( const QString& id )
{
if ( mBackendIdMap.contains( id ) )
///
/// Register backend
///
void Factory::registerBackend( const QString& id,
const QString& name,
SourceType type,
CreateFct create )
{
return mBackendIdMap[id].type;
}
else
{
return NONE;
}
}
BackendEntry backend;
///
/// 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";
}
///
/// 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;
backend.id = id;
backend.name = name;
backend.type = type;
backend.create = create;
mBackendIdMap[ id ] = backend;
mBackendNameMap[ name ] = backend;
mBackendIdMap[ id ] = backend;
mBackendNameMap[ name ] = backend;
mNameList << name;
}
mNameList << name;
}
}
+71 -63
View File
@@ -26,78 +26,86 @@
#include <QMap>
namespace merge
namespace glabels
{
class Merge; // Forward reference
///
/// Factory
///
class Factory
namespace merge
{
Q_DECLARE_TR_FUNCTIONS(Factory)
// Forward references
class Merge;
/////////////////////////////////
// Source Type
/////////////////////////////////
public:
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
///
/// Factory
///
class Factory
{
public:
QString id;
QString name;
SourceType type;
CreateFct create;
};
Q_DECLARE_TR_FUNCTIONS(Factory)
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
+146 -141
View File
@@ -23,188 +23,193 @@
#include "Record.h"
namespace merge
namespace glabels
{
///
/// Constructor
///
Merge::Merge()
namespace merge
{
}
///
/// Constructor
///
Merge::Merge( const Merge* merge ) : mSource(merge->mSource)
{
foreach ( Record* record, merge->mRecordList )
///
/// Constructor
///
Merge::Merge()
{
mRecordList << record->clone();
}
}
///
/// Destructor
///
Merge::~Merge()
{
foreach ( Record* record, mRecordList )
///
/// Constructor
///
Merge::Merge( const Merge* merge ) : mSource(merge->mSource)
{
delete record;
foreach ( Record* record, merge->mRecordList )
{
mRecordList << record->clone();
}
}
mRecordList.clear();
}
///
/// Get id
///
QString Merge::id() const
{
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 )
///
/// Destructor
///
Merge::~Merge()
{
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();
}
///
/// 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();
emit sourceChanged();
}
}
///
/// Select all records
///
void Merge::selectAll()
{
foreach ( Record* record, mRecordList )
///
/// 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();
}
emit selectionChanged();
}
///
/// Unselect all records
///
void Merge::unselectAll()
{
foreach ( Record* record, mRecordList )
///
/// Unselect matching record
///
void Merge::unselect( Record* record )
{
record->setSelected( false );
emit selectionChanged();
}
emit selectionChanged();
}
///
/// Return count of selected records
///
int Merge::nSelectedRecords() const
{
int count = 0;
foreach ( Record* record, mRecordList )
///
/// Select/unselect i'th record
///
void Merge::setSelected( int i, bool state )
{
if ( record->isSelected() )
if ( (i >= 0) && (i < mRecordList.size()) )
{
count++;
mRecordList[i]->setSelected( state );
emit selectionChanged();
}
}
return count;
}
///
/// Return list of selected records
///
const QList<Record*> Merge::selectedRecords() const
{
QList<Record*> list;
foreach ( Record* record, mRecordList )
///
/// Select all records
///
void Merge::selectAll()
{
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>
namespace merge
namespace glabels
{
class Record; // Forward reference
///
/// Merge Object
///
struct Merge : QObject
namespace merge
{
Q_OBJECT
/////////////////////////////////
// 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();
// Forward references
class Record;
int nSelectedRecords() const;
const QList<Record*> selectedRecords() const;
///
/// Merge Object
///
struct Merge : QObject
{
Q_OBJECT
/////////////////////////////////
// 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;
/////////////////////////////////
// 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;
/////////////////////////////////
// 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:
void sourceChanged();
void selectionChanged();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void sourceChanged();
void selectionChanged();
/////////////////////////////////
// Private data
/////////////////////////////////
protected:
QString mId;
private:
QString mSource;
QList<Record*> mRecordList;
};
/////////////////////////////////
// Private data
/////////////////////////////////
protected:
QString mId;
private:
QString mSource;
QList<Record*> mRecordList;
};
}
}
#endif // merge_Merge_h
+78 -73
View File
@@ -21,102 +21,107 @@
#include "None.h"
namespace merge
namespace glabels
{
///
/// Constructor
///
None::None() : Merge()
namespace merge
{
mId = "None";
}
///
/// Constructor
///
None::None() : Merge()
{
mId = "None";
}
///
/// Constructor
///
None::None( const None* merge ) : Merge( merge )
{
}
///
/// Constructor
///
None::None( const None* merge ) : Merge( merge )
{
}
///
/// Destructor
///
None::~None()
{
}
///
/// Destructor
///
None::~None()
{
}
///
/// Clone
///
None* None::clone() const
{
return new None( this );
}
///
/// Clone
///
None* None::clone() const
{
return new None( this );
}
///
/// Get ID
///
QString None::id()
{
return "None";
}
///
/// Get ID
///
QString None::id()
{
return "None";
}
///
/// Create
///
Merge* None::create()
{
return new None();
}
///
/// Create
///
Merge* None::create()
{
return new None();
}
///
/// Get key list
///
QStringList None::keys() const
{
QStringList emptyList;
return emptyList;
}
///
/// Get key list
///
QStringList None::keys() const
{
QStringList emptyList;
return emptyList;
}
///
/// Get primary key
///
QString None::primaryKey() const
{
return "";
}
///
/// Get primary key
///
QString None::primaryKey() const
{
return "";
}
///
/// Open source
///
void None::open()
{
}
///
/// Open source
///
void None::open()
{
}
///
/// Close source
///
void None::close()
{
}
///
/// Close source
///
void None::close()
{
}
///
/// Read next record
///
Record* None::readNextRecord()
{
return 0;
///
/// Read next record
///
Record* None::readNextRecord()
{
return 0;
}
}
}
+40 -34
View File
@@ -24,51 +24,57 @@
#include "Merge.h"
namespace merge
namespace glabels
{
///
/// None Merge Backend
///
struct None : public Merge
namespace merge
{
///
/// None Merge Backend
///
struct None : public Merge
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
None();
None( const None* merge );
virtual ~None();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
None();
None( const None* merge );
virtual ~None();
/////////////////////////////////
// Object duplication
/////////////////////////////////
None* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
None* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Implementation of virtual methods
/////////////////////////////////
public:
QStringList keys() const;
QString primaryKey() const;
protected:
void open();
void close();
Record* readNextRecord();
/////////////////////////////////
// Implementation of virtual methods
/////////////////////////////////
public:
QStringList keys() const;
QString primaryKey() const;
protected:
void open();
void close();
Record* readNextRecord();
};
};
}
}
#endif // merge_None_h
+38 -33
View File
@@ -21,50 +21,55 @@
#include "Record.h"
namespace merge
namespace glabels
{
///
/// Constructor
///
Record::Record() : mSelected( true )
namespace merge
{
}
///
/// Constructor
///
Record::Record() : mSelected( true )
{
}
///
/// Constructor
///
Record::Record( const Record* record )
: QMap<QString,QString>(*record), mSelected(record->mSelected)
{
}
///
/// Constructor
///
Record::Record( const Record* record )
: QMap<QString,QString>(*record), mSelected(record->mSelected)
{
}
///
/// Clone
///
Record* Record::clone() const
{
return new Record( this );
}
///
/// Clone
///
Record* Record::clone() const
{
return new Record( this );
}
///
/// Is record selected?
///
bool Record::isSelected() const
{
return mSelected;
}
///
/// Is record selected?
///
bool Record::isSelected() const
{
return mSelected;
}
///
/// Set selected on not selected
///
void Record::setSelected( bool value )
{
mSelected = value;
///
/// Set selected on not selected
///
void Record::setSelected( bool value )
{
mSelected = value;
}
}
}
+34 -28
View File
@@ -25,45 +25,51 @@
#include <QMap>
namespace merge
namespace glabels
{
///
/// Merge Record
///
struct Record : public QMap<QString,QString>
namespace merge
{
///
/// Merge Record
///
struct Record : public QMap<QString,QString>
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
Record();
Record( const Record* record );
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
Record();
Record( const Record* record );
/////////////////////////////////
// Object duplication
/////////////////////////////////
Record* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
Record* clone() const;
/////////////////////////////////
// Properties
/////////////////////////////////
public:
bool isSelected() const;
void setSelected( bool value );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
bool isSelected() const;
void setSelected( bool value );
/////////////////////////////////
// Private data
/////////////////////////////////
private:
bool mSelected;
/////////////////////////////////
// Private data
/////////////////////////////////
private:
bool mSelected;
};
};
}
}
#endif // merge_Record_h
+338 -333
View File
@@ -24,392 +24,397 @@
#include <QtDebug>
namespace merge
namespace glabels
{
///
/// Constructor
///
Text::Text( QChar delimiter, bool line1HasKeys )
: mNFieldsMax(0), mDelimeter(delimiter), mLine1HasKeys(line1HasKeys)
namespace merge
{
}
///
/// Constructor
///
Text::Text( const Text* merge )
: 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++ )
///
/// Constructor
///
Text::Text( QChar delimiter, bool line1HasKeys )
: mNFieldsMax(0), mDelimeter(delimiter), mLine1HasKeys(line1HasKeys)
{
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() )
///
/// Constructor
///
Text::Text( const Text* merge )
: Merge( merge ),
mNFieldsMax(merge->mNFieldsMax),
mDelimeter(merge->mDelimeter), mLine1HasKeys(merge->mLine1HasKeys)
{
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
{
mNFieldsMax = mKeys.size();
return QString::number( iField+1 );
}
}
}
///
/// Close source
///
void Text::close()
{
if ( mFile.isOpen() )
///
/// 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()
{
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
{
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;
QStringList fields;
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 ) )
enum State
{
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 ) )
{
case DELIM:
switch (c)
switch (state)
{
case '\n':
/* last field is empty. */
fields << "";
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 )
case DELIM:
switch (c)
{
/* field is empty. */
case '\n':
/* last field is empty. */
fields << "";
state = DONE;
break;
case '\r':
/* ignore */
state = DELIM;
}
else
{
/* begining of a simple field. */
field.append( c );
state = SIMPLE;
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. */
fields << "";
state = DELIM;
}
else
{
/* begining of a simple field. */
field.append( c );
state = SIMPLE;
}
break;
}
break;
}
break;
case QUOTED:
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 QUOTED:
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 );
state = SIMPLE;
break;
}
break;
}
break;
case SIMPLE_ESCAPED:
switch (c)
{
case 'n':
/* Decode "\n" as newline. */
field.append( '\n' );
state = SIMPLE;
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 't':
/* Decode "\t" as tab. */
field.append( '\t' );
state = SIMPLE;
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
{
/* 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:
/* Use character literally. */
field.append( (char)c );
state = SIMPLE;
qWarning( "merge::Text::parseLine()::Should not be reached! #1" );
break;
}
break;
default:
qWarning( "merge::Text::parseLine()::Should not be reached! #1" );
break;
}
}
else
{
/* Handle EOF (could also be an error while reading). */
switch (state)
else
{
/* Handle EOF (could also be an error while reading). */
switch (state)
{
case DELIM:
/* EOF, no more lines. */
break;
case DELIM:
/* EOF, no more lines. */
break;
case QUOTED:
/* File ended midway through quoted item. Truncate field. */
fields << QString( field );
break;
case QUOTED:
/* File ended midway through quoted item. Truncate field. */
fields << QString( field );
break;
case QUOTED_QUOTE1:
/* File ended after quoted item. */
fields << QString( field );
break;
case QUOTED_QUOTE1:
/* File ended after quoted item. */
fields << QString( field );
break;
case QUOTED_ESCAPED:
/* File ended midway through quoted item. Truncate field. */
fields << QString( field );
break;
case QUOTED_ESCAPED:
/* File ended midway through quoted item. Truncate field. */
fields << QString( field );
break;
case SIMPLE:
/* File ended after simple item. */
fields << QString( field );
break;
case SIMPLE:
/* File ended after simple item. */
fields << QString( field );
break;
case SIMPLE_ESCAPED:
/* File ended midway through escaped item. */
fields << QString( field );
break;
case SIMPLE_ESCAPED:
/* File ended midway through escaped item. */
fields << QString( field );
break;
default:
qWarning( "merge::Text::parseLine()::Should not be reached! #2" );
break;
}
default:
qWarning( "merge::Text::parseLine()::Should not be reached! #2" );
break;
}
state = DONE;
state = DONE;
}
}
}
return fields;
return fields;
}
}
}
+44 -38
View File
@@ -26,55 +26,61 @@
#include <QFile>
namespace merge
namespace glabels
{
///
/// Text Merge Backend
///
struct Text : public Merge
namespace merge
{
///
/// Text Merge Backend
///
struct Text : public Merge
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
protected:
Text( QChar delimiter, bool line1HasKeys );
Text( const Text* merge );
virtual ~Text();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
protected:
Text( QChar delimiter, bool line1HasKeys );
Text( const Text* merge );
virtual ~Text();
/////////////////////////////////
// Implementation of virtual methods
/////////////////////////////////
public:
QStringList keys() const;
QString primaryKey() const;
protected:
void open();
void close();
Record* readNextRecord();
/////////////////////////////////
// Implementation of virtual methods
/////////////////////////////////
public:
QStringList keys() const;
QString primaryKey() const;
protected:
void open();
void close();
Record* readNextRecord();
/////////////////////////////////
// Private methods
/////////////////////////////////
QString keyFromIndex( int iField ) const;
QStringList parseLine();
/////////////////////////////////
// Private methods
/////////////////////////////////
QString keyFromIndex( int iField ) const;
QStringList parseLine();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
QChar mDelimeter;
bool mLine1HasKeys;
/////////////////////////////////
// Private data
/////////////////////////////////
private:
QChar mDelimeter;
bool mLine1HasKeys;
QFile mFile;
QStringList mKeys;
int mNFieldsMax;
};
QFile mFile;
QStringList mKeys;
int mNFieldsMax;
};
}
}
#endif // merge_Text_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextColon.h"
namespace merge
namespace glabels
{
static const QString ID = "Text/Colon";
///
/// Constructor
///
TextColon::TextColon() : Text(':',false)
namespace merge
{
mId = ID;
}
static const QString ID = "Text/Colon";
///
/// Constructor
///
TextColon::TextColon( const TextColon* merge ) : Text( merge )
{
}
///
/// Constructor
///
TextColon::TextColon() : Text(':',false)
{
mId = ID;
}
///
/// Destructor
///
TextColon::~TextColon()
{
}
///
/// Constructor
///
TextColon::TextColon( const TextColon* merge ) : Text( merge )
{
}
///
/// Clone
///
TextColon* TextColon::clone() const
{
return new TextColon( this );
}
///
/// Destructor
///
TextColon::~TextColon()
{
}
///
/// Get ID
///
QString TextColon::id()
{
return ID;
}
///
/// Clone
///
TextColon* TextColon::clone() const
{
return new TextColon( this );
}
///
/// Create
///
Merge* TextColon::create()
{
return new TextColon();
///
/// Get ID
///
QString TextColon::id()
{
return ID;
}
///
/// Create
///
Merge* TextColon::create()
{
return new TextColon();
}
}
}
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h"
namespace merge
namespace glabels
{
///
/// TextColon Merge Backend
///
struct TextColon : public Text
namespace merge
{
///
/// TextColon Merge Backend
///
struct TextColon : public Text
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextColon();
TextColon( const TextColon* merge );
virtual ~TextColon();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextColon();
TextColon( const TextColon* merge );
virtual ~TextColon();
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextColon* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextColon* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
};
};
}
}
#endif // merge_TextColon_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextColonKeys.h"
namespace merge
namespace glabels
{
static const QString ID = "Text/Colon/Line1Keys";
namespace merge
{
static const QString ID = "Text/Colon/Line1Keys";
///
/// Constructor
///
TextColonKeys::TextColonKeys() : Text(':',true)
{
mId = ID;
}
///
/// Constructor
///
TextColonKeys::TextColonKeys() : Text(':',true)
{
mId = ID;
}
///
/// Constructor
///
TextColonKeys::TextColonKeys( const TextColonKeys* merge ) : Text( merge )
{
}
///
/// Constructor
///
TextColonKeys::TextColonKeys( const TextColonKeys* merge ) : Text( merge )
{
}
///
/// Destructor
///
TextColonKeys::~TextColonKeys()
{
}
///
/// Destructor
///
TextColonKeys::~TextColonKeys()
{
}
///
/// Clone
///
TextColonKeys* TextColonKeys::clone() const
{
return new TextColonKeys( this );
}
///
/// Clone
///
TextColonKeys* TextColonKeys::clone() const
{
return new TextColonKeys( this );
}
///
/// Get ID
///
QString TextColonKeys::id()
{
return ID;
}
///
/// Get ID
///
QString TextColonKeys::id()
{
return ID;
}
///
/// Create
///
Merge* TextColonKeys::create()
{
return new TextColonKeys();
///
/// Create
///
Merge* TextColonKeys::create()
{
return new TextColonKeys();
}
}
}
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h"
namespace merge
namespace glabels
{
///
/// TextColonKeys Merge Backend
///
struct TextColonKeys : public Text
namespace merge
{
///
/// TextColonKeys Merge Backend
///
struct TextColonKeys : public Text
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextColonKeys();
TextColonKeys( const TextColonKeys* merge );
virtual ~TextColonKeys();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextColonKeys();
TextColonKeys( const TextColonKeys* merge );
virtual ~TextColonKeys();
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextColonKeys* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextColonKeys* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
};
};
}
}
#endif // merge_TextColonKeys_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextCsv.h"
namespace merge
namespace glabels
{
static const QString ID = "Text/Comma";
namespace merge
{
static const QString ID = "Text/Comma";
///
/// Constructor
///
TextCsv::TextCsv() : Text(',',false)
{
mId = ID;
}
///
/// Constructor
///
TextCsv::TextCsv() : Text(',',false)
{
mId = ID;
}
///
/// Constructor
///
TextCsv::TextCsv( const TextCsv* merge ) : Text( merge )
{
}
///
/// Constructor
///
TextCsv::TextCsv( const TextCsv* merge ) : Text( merge )
{
}
///
/// Destructor
///
TextCsv::~TextCsv()
{
}
///
/// Destructor
///
TextCsv::~TextCsv()
{
}
///
/// Clone
///
TextCsv* TextCsv::clone() const
{
return new TextCsv( this );
}
///
/// Clone
///
TextCsv* TextCsv::clone() const
{
return new TextCsv( this );
}
///
/// Get ID
///
QString TextCsv::id()
{
return ID;
}
///
/// Get ID
///
QString TextCsv::id()
{
return ID;
}
///
/// Create
///
Merge* TextCsv::create()
{
return new TextCsv();
///
/// Create
///
Merge* TextCsv::create()
{
return new TextCsv();
}
}
}
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h"
namespace merge
namespace glabels
{
///
/// TextCsv Merge Backend
///
struct TextCsv : public Text
namespace merge
{
///
/// TextCsv Merge Backend
///
struct TextCsv : public Text
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextCsv();
TextCsv( const TextCsv* merge );
virtual ~TextCsv();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextCsv();
TextCsv( const TextCsv* merge );
virtual ~TextCsv();
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextCsv* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextCsv* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
};
};
}
}
#endif // merge_TextCsv_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextCsvKeys.h"
namespace merge
namespace glabels
{
static const QString ID = "Text/Comma/Line1Keys";
namespace merge
{
static const QString ID = "Text/Comma/Line1Keys";
///
/// Constructor
///
TextCsvKeys::TextCsvKeys() : Text(',',true)
{
mId = ID;
}
///
/// Constructor
///
TextCsvKeys::TextCsvKeys() : Text(',',true)
{
mId = ID;
}
///
/// Constructor
///
TextCsvKeys::TextCsvKeys( const TextCsvKeys* merge ) : Text( merge )
{
}
///
/// Constructor
///
TextCsvKeys::TextCsvKeys( const TextCsvKeys* merge ) : Text( merge )
{
}
///
/// Destructor
///
TextCsvKeys::~TextCsvKeys()
{
}
///
/// Destructor
///
TextCsvKeys::~TextCsvKeys()
{
}
///
/// Clone
///
TextCsvKeys* TextCsvKeys::clone() const
{
return new TextCsvKeys( this );
}
///
/// Clone
///
TextCsvKeys* TextCsvKeys::clone() const
{
return new TextCsvKeys( this );
}
///
/// Get ID
///
QString TextCsvKeys::id()
{
return ID;
}
///
/// Get ID
///
QString TextCsvKeys::id()
{
return ID;
}
///
/// Create
///
Merge* TextCsvKeys::create()
{
return new TextCsvKeys();
///
/// Create
///
Merge* TextCsvKeys::create()
{
return new TextCsvKeys();
}
}
}
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h"
namespace merge
namespace glabels
{
///
/// TextCsvKeys Merge Backend
///
struct TextCsvKeys : public Text
namespace merge
{
///
/// TextCsvKeys Merge Backend
///
struct TextCsvKeys : public Text
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextCsvKeys();
TextCsvKeys( const TextCsvKeys* merge );
virtual ~TextCsvKeys();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextCsvKeys();
TextCsvKeys( const TextCsvKeys* merge );
virtual ~TextCsvKeys();
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextCsvKeys* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextCsvKeys* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
};
};
}
}
#endif // merge_TextCsvKeys_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextSemicolon.h"
namespace merge
namespace glabels
{
static const QString ID = "Text/Semicolon";
///
/// Constructor
///
TextSemicolon::TextSemicolon() : Text(';',false)
namespace merge
{
mId = ID;
}
static const QString ID = "Text/Semicolon";
///
/// Constructor
///
TextSemicolon::TextSemicolon( const TextSemicolon* merge ) : Text( merge )
{
}
///
/// Constructor
///
TextSemicolon::TextSemicolon() : Text(';',false)
{
mId = ID;
}
///
/// Destructor
///
TextSemicolon::~TextSemicolon()
{
}
///
/// Constructor
///
TextSemicolon::TextSemicolon( const TextSemicolon* merge ) : Text( merge )
{
}
///
/// Clone
///
TextSemicolon* TextSemicolon::clone() const
{
return new TextSemicolon( this );
}
///
/// Destructor
///
TextSemicolon::~TextSemicolon()
{
}
///
/// Get ID
///
QString TextSemicolon::id()
{
return ID;
}
///
/// Clone
///
TextSemicolon* TextSemicolon::clone() const
{
return new TextSemicolon( this );
}
///
/// Create
///
Merge* TextSemicolon::create()
{
return new TextSemicolon();
///
/// Get ID
///
QString TextSemicolon::id()
{
return ID;
}
///
/// Create
///
Merge* TextSemicolon::create()
{
return new TextSemicolon();
}
}
}
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h"
namespace merge
namespace glabels
{
///
/// TextSemicolon Merge Backend
///
struct TextSemicolon : public Text
namespace merge
{
///
/// TextSemicolon Merge Backend
///
struct TextSemicolon : public Text
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextSemicolon();
TextSemicolon( const TextSemicolon* merge );
virtual ~TextSemicolon();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextSemicolon();
TextSemicolon( const TextSemicolon* merge );
virtual ~TextSemicolon();
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextSemicolon* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextSemicolon* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
};
};
}
}
#endif // merge_TextSemicolon_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextSemicolonKeys.h"
namespace merge
namespace glabels
{
static const QString ID = "Text/Semicolon/Keys";
///
/// Constructor
///
TextSemicolonKeys::TextSemicolonKeys() : Text(';',true)
namespace merge
{
mId = ID;
}
static const QString ID = "Text/Semicolon/Keys";
///
/// Constructor
///
TextSemicolonKeys::TextSemicolonKeys( const TextSemicolonKeys* merge ) : Text( merge )
{
}
///
/// Constructor
///
TextSemicolonKeys::TextSemicolonKeys() : Text(';',true)
{
mId = ID;
}
///
/// Destructor
///
TextSemicolonKeys::~TextSemicolonKeys()
{
}
///
/// Constructor
///
TextSemicolonKeys::TextSemicolonKeys( const TextSemicolonKeys* merge ) : Text( merge )
{
}
///
/// Clone
///
TextSemicolonKeys* TextSemicolonKeys::clone() const
{
return new TextSemicolonKeys( this );
}
///
/// Destructor
///
TextSemicolonKeys::~TextSemicolonKeys()
{
}
///
/// Get ID
///
QString TextSemicolonKeys::id()
{
return ID;
}
///
/// Clone
///
TextSemicolonKeys* TextSemicolonKeys::clone() const
{
return new TextSemicolonKeys( this );
}
///
/// Create
///
Merge* TextSemicolonKeys::create()
{
return new TextSemicolonKeys();
///
/// Get ID
///
QString TextSemicolonKeys::id()
{
return ID;
}
///
/// Create
///
Merge* TextSemicolonKeys::create()
{
return new TextSemicolonKeys();
}
}
}
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h"
namespace merge
namespace glabels
{
///
/// TextSemicolonKeys Merge Backend
///
struct TextSemicolonKeys : public Text
namespace merge
{
///
/// TextSemicolonKeys Merge Backend
///
struct TextSemicolonKeys : public Text
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextSemicolonKeys();
TextSemicolonKeys( const TextSemicolonKeys* merge );
virtual ~TextSemicolonKeys();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextSemicolonKeys();
TextSemicolonKeys( const TextSemicolonKeys* merge );
virtual ~TextSemicolonKeys();
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextSemicolonKeys* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextSemicolonKeys* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
};
};
}
}
#endif // merge_TextSemicolonKeys_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextTsv.h"
namespace merge
namespace glabels
{
static const QString ID = "Text/Tab";
namespace merge
{
static const QString ID = "Text/Tab";
///
/// Constructor
///
TextTsv::TextTsv() : Text('\t',false)
{
mId = ID;
}
///
/// Constructor
///
TextTsv::TextTsv() : Text('\t',false)
{
mId = ID;
}
///
/// Constructor
///
TextTsv::TextTsv( const TextTsv* merge ) : Text( merge )
{
}
///
/// Constructor
///
TextTsv::TextTsv( const TextTsv* merge ) : Text( merge )
{
}
///
/// Destructor
///
TextTsv::~TextTsv()
{
}
///
/// Destructor
///
TextTsv::~TextTsv()
{
}
///
/// Clone
///
TextTsv* TextTsv::clone() const
{
return new TextTsv( this );
}
///
/// Clone
///
TextTsv* TextTsv::clone() const
{
return new TextTsv( this );
}
///
/// Get ID
///
QString TextTsv::id()
{
return ID;
}
///
/// Get ID
///
QString TextTsv::id()
{
return ID;
}
///
/// Create
///
Merge* TextTsv::create()
{
return new TextTsv();
///
/// Create
///
Merge* TextTsv::create()
{
return new TextTsv();
}
}
}
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h"
namespace merge
namespace glabels
{
///
/// TextTsv Merge Backend
///
struct TextTsv : public Text
namespace merge
{
///
/// TextTsv Merge Backend
///
struct TextTsv : public Text
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextTsv();
TextTsv( const TextTsv* merge );
virtual ~TextTsv();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextTsv();
TextTsv( const TextTsv* merge );
virtual ~TextTsv();
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextTsv* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextTsv* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
};
};
}
}
#endif // merge_TextTsv_h
+46 -41
View File
@@ -21,60 +21,65 @@
#include "TextTsvKeys.h"
namespace merge
namespace glabels
{
static const QString ID = "Text/Tab/Line1Keys";
///
/// Constructor
///
TextTsvKeys::TextTsvKeys() : Text('\t',true)
namespace merge
{
mId = ID;
}
static const QString ID = "Text/Tab/Line1Keys";
///
/// Constructor
///
TextTsvKeys::TextTsvKeys( const TextTsvKeys* merge ) : Text( merge )
{
}
///
/// Constructor
///
TextTsvKeys::TextTsvKeys() : Text('\t',true)
{
mId = ID;
}
///
/// Destructor
///
TextTsvKeys::~TextTsvKeys()
{
}
///
/// Constructor
///
TextTsvKeys::TextTsvKeys( const TextTsvKeys* merge ) : Text( merge )
{
}
///
/// Clone
///
TextTsvKeys* TextTsvKeys::clone() const
{
return new TextTsvKeys( this );
}
///
/// Destructor
///
TextTsvKeys::~TextTsvKeys()
{
}
///
/// Get ID
///
QString TextTsvKeys::id()
{
return ID;
}
///
/// Clone
///
TextTsvKeys* TextTsvKeys::clone() const
{
return new TextTsvKeys( this );
}
///
/// Create
///
Merge* TextTsvKeys::create()
{
return new TextTsvKeys();
///
/// Get ID
///
QString TextTsvKeys::id()
{
return ID;
}
///
/// Create
///
Merge* TextTsvKeys::create()
{
return new TextTsvKeys();
}
}
}
+31 -25
View File
@@ -24,40 +24,46 @@
#include "Text.h"
namespace merge
namespace glabels
{
///
/// TextTsvKeys Merge Backend
///
struct TextTsvKeys : public Text
namespace merge
{
///
/// TextTsvKeys Merge Backend
///
struct TextTsvKeys : public Text
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextTsvKeys();
TextTsvKeys( const TextTsvKeys* merge );
virtual ~TextTsvKeys();
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
TextTsvKeys();
TextTsvKeys( const TextTsvKeys* merge );
virtual ~TextTsvKeys();
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextTsvKeys* clone() const;
/////////////////////////////////
// Object duplication
/////////////////////////////////
public:
TextTsvKeys* clone() const;
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
/////////////////////////////////
// Static methods
/////////////////////////////////
public:
static QString id();
static Merge* create();
};
};
}
}
#endif // merge_TextTsvKeys_h
+266 -253
View File
@@ -30,289 +30,302 @@
#include "Merge/Factory.h"
///
/// Constructor
///
MergeView::MergeView( QWidget *parent )
: QWidget(parent), mModel(0), mBlock(false)
namespace glabels
{
setupUi( this );
mMergeFormatNames = merge::Factory::nameList();
formatCombo->addItems( mMergeFormatNames );
}
///
/// Destructor
///
MergeView::~MergeView()
{
}
///
/// Set Model
///
void MergeView::setModel( LabelModel* model, UndoRedoModel* undoRedoModel )
{
mModel = model;
mUndoRedoModel = undoRedoModel;
// Initialize CWD
if ( model->fileName().isEmpty() )
///
/// Constructor
///
MergeView::MergeView( QWidget *parent )
: QWidget(parent), mModel(0), mBlock(false)
{
mCwd = ".";
}
else
{
mCwd = QFileInfo( model->fileName() ).absolutePath();
setupUi( this );
mMergeFormatNames = merge::Factory::nameList();
formatCombo->addItems( mMergeFormatNames );
}
onMergeChanged();
connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) );
}
///
/// Merge changed handler
///
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() ) )
///
/// Destructor
///
MergeView::~MergeView()
{
case merge::Factory::NONE:
case merge::Factory::FIXED:
locationLabel->setEnabled( false );
locationButton->setEnabled( false );
locationButton->setText( "" );
break;
// empty
}
case merge::Factory::FILE:
locationLabel->setEnabled( true );
locationButton->setEnabled( true );
if ( mModel->merge()->source().isEmpty() )
///
/// Set Model
///
void MergeView::setModel( LabelModel* model, UndoRedoModel* undoRedoModel )
{
mModel = model;
mUndoRedoModel = undoRedoModel;
// Initialize CWD
if ( model->fileName().isEmpty() )
{
locationButton->setText( "Select file..." );
mCwd = ".";
}
else
{
locationButton->setText( mModel->merge()->source() );
mCwd = QFileInfo( model->fileName() ).absolutePath();
}
break;
default:
qWarning( "MergeView::onMergeChanged()::Should not be reached!" );
break;
onMergeChanged();
connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) );
}
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 )
///
/// Merge changed handler
///
void MergeView::onMergeChanged()
{
QString name = merge::Factory::idToName( mModel->merge()->id() );
int index = mMergeFormatNames.indexOf( name );
mOldFormatComboIndex = index;
formatCombo->setCurrentIndex( index );
mModel->setMerge( merge::Factory::createMerge( merge::Factory::indexToId(index) ) );
}
}
///
/// 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 )
switch ( merge::Factory::idToType( mModel->merge()->id() ) )
{
if ( key != mPrimaryKey )
{
QTableWidgetItem* item = new QTableWidgetItem( key );
item->setFlags( Qt::ItemIsEnabled );
recordsTable->setHorizontalHeaderItem( iCol, item );
case merge::Factory::NONE:
case merge::Factory::FIXED:
locationLabel->setEnabled( false );
locationButton->setEnabled( false );
locationButton->setText( "" );
break;
iCol++;
case merge::Factory::FILE:
locationLabel->setEnabled( true );
locationButton->setEnabled( true );
if ( mModel->merge()->source().isEmpty() )
{
locationButton->setText( "Select file..." );
}
}
// 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 )
else
{
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 );
recordsTable->setItem( iRow, iCol, item );
recordsTable->resizeColumnToContents( iCol );
recordsTable->setHorizontalHeaderItem( iCol, item );
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"
// Forward references
class LabelModel;
class UndoRedoModel;
///
/// merge::Merge Property Editor Widget
///
class MergeView : public QWidget, public Ui_MergeView
namespace glabels
{
Q_OBJECT
/////////////////////////////////
// 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;
// Forward references
class LabelModel;
class UndoRedoModel;
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

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