Moved app/ to glabels/.
@@ -0,0 +1,186 @@
|
||||
/* BarcodeBackends.cpp
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::string default_id = "code39";
|
||||
}
|
||||
|
||||
BarcodeBackends::BackendMap BarcodeBackends::mBackendIdMap;
|
||||
BarcodeBackends::BackendMap BarcodeBackends::mBackendNameMap;
|
||||
|
||||
BarcodeBackends::StyleMap BarcodeBackends::mStyleIdMap;
|
||||
BarcodeBackends::StyleMap BarcodeBackends::mStyleNameMap;
|
||||
|
||||
QList<QString> BarcodeBackends::mBackendNameList;
|
||||
QList<QString> BarcodeBackends::mNameList;
|
||||
|
||||
|
||||
BarcodeBackends::BarcodeBackends()
|
||||
{
|
||||
registerStyle( "postnet", "", tr("POSTNET (any)"),
|
||||
false, false, true, false, "12345-6789-12", false, 11 );
|
||||
|
||||
registerStyle( "postnet-5", "", tr("POSTNET-5 (ZIP only)"),
|
||||
false, false, true, false, "12345", false, 5 );
|
||||
|
||||
registerStyle( "postnet-9", "", tr("POSTNET-9 (ZIP+4)"),
|
||||
false, false, true, false, "12345-6789", false, 9 );
|
||||
|
||||
registerStyle( "postnet-11", "", tr("POSTNET-11 (DPBC)"),
|
||||
false, false, true, false, "12345-6789-12", false, 11 );
|
||||
|
||||
registerStyle( "cepnet", "", tr("CEPNET"),
|
||||
false, false, true, false, "12345-678", false, 8 );
|
||||
|
||||
registerStyle( "onecode", "", tr("USPS Intelligent Mail"),
|
||||
false, false, true, false, "12345678901234567890", false, 20 );
|
||||
|
||||
registerStyle( "code39", "", tr("Code 39"),
|
||||
true, true, true, true, "1234567890", true, 10 );
|
||||
|
||||
registerStyle( "code39ext", "", tr("Code 39 Extended"),
|
||||
true, true, true, true, "1234567890", true, 10 );
|
||||
|
||||
registerStyle( "upc-A", "", tr("UPC-A"),
|
||||
true, false, true, false, "12345678901", false, 11 );
|
||||
|
||||
registerStyle( "ean-13", "", tr("EAN-13"),
|
||||
true, false, true, false, "123456789012", false, 12 );
|
||||
|
||||
registerStyle( "datamatrix", "", tr("DataMatrix"),
|
||||
false, false, true, false, "1234567890AB", false, 12 );
|
||||
|
||||
registerStyle( "qrcode", "", tr("QRCode"),
|
||||
false, false, true, false, "1234567890AB", false, 12 );
|
||||
}
|
||||
|
||||
|
||||
void BarcodeBackends::init( void )
|
||||
{
|
||||
static BarcodeBackends* singletonInstance = NULL;
|
||||
|
||||
if ( singletonInstance == NULL )
|
||||
{
|
||||
singletonInstance = new BarcodeBackends();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QString BarcodeBackends::BackendIdToName( const QString& backendId )
|
||||
{
|
||||
BackendMap::iterator i = mBackendIdMap.find( backendId );
|
||||
if ( i != mBackendIdMap.end() )
|
||||
{
|
||||
return i.value();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
QString BarcodeBackends::BackendNameToId( const QString& backendName )
|
||||
{
|
||||
BackendMap::iterator i = mBackendNameMap.find( backendName );
|
||||
if ( i != mBackendNameMap.end() )
|
||||
{
|
||||
return i.value();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
const QList<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() )
|
||||
{
|
||||
return i.value();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const BarcodeStyle* BarcodeBackends::lookupStyleFromName( const QString& name )
|
||||
{
|
||||
StyleMap::iterator i = mStyleNameMap.find( name );
|
||||
if ( i != mStyleNameMap.end() )
|
||||
{
|
||||
return i.value();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void BarcodeBackends::registerBackend( QString& id, QString& name)
|
||||
{
|
||||
mBackendNameList.append( name );
|
||||
mBackendIdMap.insert( id, name );
|
||||
mBackendNameMap.insert( name, id );
|
||||
}
|
||||
|
||||
|
||||
void BarcodeBackends::registerStyle( const char* id,
|
||||
const char* backendId,
|
||||
const QString& name,
|
||||
bool canText,
|
||||
bool textOptional,
|
||||
bool canChecksum,
|
||||
bool checksumOptional,
|
||||
const char* defaultDigits,
|
||||
bool canFreeForm,
|
||||
int preferedN )
|
||||
{
|
||||
BarcodeStyle* style = new BarcodeStyle( QString(id), QString(backendId), name,
|
||||
canText, textOptional,
|
||||
canChecksum, checksumOptional,
|
||||
QString(defaultDigits), canFreeForm, preferedN );
|
||||
|
||||
QString fqName = QString(backendId) + QString(".") + name; // Name may not be unique
|
||||
|
||||
mNameList.append( name );
|
||||
mStyleIdMap.insert( id, style );
|
||||
mStyleNameMap.insert( fqName, style );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/* BarcodeBackends.h
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_BarcodeBackends_h
|
||||
#define glabels_BarcodeBackends_h
|
||||
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QMap>
|
||||
#include <QList>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Barcode Backends Database
|
||||
///
|
||||
class BarcodeBackends : public QObject
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
private:
|
||||
BarcodeBackends();
|
||||
|
||||
public:
|
||||
static void init( void );
|
||||
|
||||
/////////////////////////////////
|
||||
// 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 BarcodeStyle* lookupStyleFromId( const QString& id );
|
||||
static const BarcodeStyle* lookupStyleFromName( const 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 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Members
|
||||
/////////////////////////////////
|
||||
typedef QMap<QString,QString> BackendMap;
|
||||
static BackendMap mBackendIdMap;
|
||||
static BackendMap mBackendNameMap;
|
||||
|
||||
typedef QMap<QString,BarcodeStyle*> StyleMap;
|
||||
static StyleMap mStyleIdMap;
|
||||
static StyleMap mStyleNameMap;
|
||||
|
||||
static QList<QString> mBackendNameList;
|
||||
static QList<QString> mNameList;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif // glabels_BarcodeBackends_h
|
||||
@@ -0,0 +1,68 @@
|
||||
/* BarcodeMenu.cpp
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BarcodeMenu.h"
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
#include "BarcodeMenuItem.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
BarcodeMenu::BarcodeMenu()
|
||||
{
|
||||
foreach ( QString name, BarcodeBackends::getNameList() )
|
||||
{
|
||||
const BarcodeStyle* bcStyle = BarcodeBackends::lookupStyleFromName( name );
|
||||
|
||||
BarcodeMenuItem* bcMenuItem = new BarcodeMenuItem( bcStyle );
|
||||
connect( bcMenuItem, SIGNAL(activated()), this, SLOT(onMenuItemActivated) );
|
||||
|
||||
addAction( bcMenuItem );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcStyle getter
|
||||
///
|
||||
const BarcodeStyle* BarcodeMenu::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// onMenuItemActivated slot
|
||||
///
|
||||
void BarcodeMenu::onMenuItemActivated( BarcodeStyle *bcStyle )
|
||||
{
|
||||
mBcStyle = bcStyle;
|
||||
|
||||
emit styleChanged();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/* BarcodeMenu.h
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_BarcodeMenu_h
|
||||
#define glabels_BarcodeMenu_h
|
||||
|
||||
#include <QMenu>
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Barcode Menu
|
||||
///
|
||||
class BarcodeMenu : public QMenu
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
BarcodeMenu();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void styleChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
const BarcodeStyle* bcStyle() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onMenuItemActivated( BarcodeStyle *bcStyle );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
BarcodeStyle* mBcStyle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_BarcodeMenu_h
|
||||
@@ -0,0 +1,68 @@
|
||||
/* BarcodeMenuButton.cpp
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BarcodeMenuButton.h"
|
||||
|
||||
#include "BarcodeBackends.h"
|
||||
#include "BarcodeMenuItem.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
BarcodeMenuButton::BarcodeMenuButton( QWidget* parent )
|
||||
: QPushButton(parent)
|
||||
{
|
||||
mMenu = new BarcodeMenu();
|
||||
setMenu( mMenu );
|
||||
|
||||
mBcStyle = BarcodeBackends::lookupStyleFromId( "" ); // Default style
|
||||
setText( mBcStyle->name() );
|
||||
|
||||
connect( mMenu, SIGNAL(styleChanged()), this, SLOT(onMenuStyleChanged()) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcStyle getter
|
||||
///
|
||||
const BarcodeStyle* BarcodeMenuButton::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// onMenuStyleChanged slot
|
||||
///
|
||||
void BarcodeMenuButton::onMenuStyleChanged()
|
||||
{
|
||||
mBcStyle = mMenu->bcStyle();
|
||||
setText( mBcStyle->name() );
|
||||
|
||||
emit styleChanged();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/* BarcodeMenuButton.h
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_BarcodeMenuButton_h
|
||||
#define glabels_BarcodeMenuButton_h
|
||||
|
||||
#include <QPushButton>
|
||||
#include "BarcodeMenu.h"
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Barcode Menu Button
|
||||
///
|
||||
class BarcodeMenuButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
BarcodeMenuButton( QWidget* parent = 0 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void styleChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
const BarcodeStyle* bcStyle() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onMenuStyleChanged();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
BarcodeMenu* mMenu;
|
||||
const BarcodeStyle* mBcStyle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_BarcodeMenuButton_h
|
||||
@@ -0,0 +1,57 @@
|
||||
/* BarcodeMenuItem.cpp
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BarcodeMenuItem.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
BarcodeMenuItem::BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent )
|
||||
: QAction(parent), mBcStyle(bcStyle)
|
||||
{
|
||||
setText( bcStyle->name() );
|
||||
|
||||
connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// bcStyle Property Getter
|
||||
///
|
||||
const BarcodeStyle* BarcodeMenuItem::bcStyle() const
|
||||
{
|
||||
return mBcStyle;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// onTriggered slot
|
||||
///
|
||||
void BarcodeMenuItem::onTriggered()
|
||||
{
|
||||
emit activated( mBcStyle );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/* BarcodeMenuItem.h
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_BarcodeMenuItem_h
|
||||
#define glabels_BarcodeMenuItem_h
|
||||
|
||||
#include <QAction>
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Barcode Menu Item
|
||||
///
|
||||
class BarcodeMenuItem : public QAction
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
BarcodeMenuItem( const BarcodeStyle* bcStyle, QObject* parent = 0 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void activated( const BarcodeStyle* bcStyle );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
const BarcodeStyle* bcStyle() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onTriggered();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
const BarcodeStyle* mBcStyle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_BarcodeMenuItem_h
|
||||
@@ -0,0 +1,182 @@
|
||||
/* BarcodeStyle.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Default Constructor
|
||||
///
|
||||
BarcodeStyle::BarcodeStyle ()
|
||||
: mId( "" ),
|
||||
mBackendId( "" ),
|
||||
mName( "" ),
|
||||
mCanText( false ),
|
||||
mTextOptional( false ),
|
||||
mCanChecksum( false ),
|
||||
mChecksumOptional( false ),
|
||||
mDefaultDigits( "" ),
|
||||
mCanFreeform( false ),
|
||||
mPreferedN( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
BarcodeStyle::BarcodeStyle ( const QString& id,
|
||||
const QString& backendId,
|
||||
const QString& name,
|
||||
bool canText,
|
||||
bool textOptional,
|
||||
bool canChecksum,
|
||||
bool checksumOptional,
|
||||
const QString& defaultDigits,
|
||||
bool canFreeform,
|
||||
int preferedN )
|
||||
: mId( id ),
|
||||
mBackendId( backendId ),
|
||||
mName( name ),
|
||||
mCanText( canText ),
|
||||
mTextOptional( textOptional ),
|
||||
mCanChecksum( canChecksum ),
|
||||
mChecksumOptional( checksumOptional ),
|
||||
mDefaultDigits( defaultDigits ),
|
||||
mCanFreeform( canFreeform ),
|
||||
mPreferedN( preferedN )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// ID Property Getter
|
||||
///
|
||||
const QString& BarcodeStyle::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Backend ID Property Getter
|
||||
///
|
||||
const QString& BarcodeStyle::backendId() const
|
||||
{
|
||||
return mBackendId;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Name Property Getter
|
||||
///
|
||||
const QString& BarcodeStyle::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Text Property Getter
|
||||
///
|
||||
bool BarcodeStyle::canText() const
|
||||
{
|
||||
return mCanText;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Text Optional Property Getter
|
||||
///
|
||||
bool BarcodeStyle::textOptional() const
|
||||
{
|
||||
return mTextOptional;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Checksum Property Getter
|
||||
///
|
||||
bool BarcodeStyle::canChecksum() const
|
||||
{
|
||||
return mCanChecksum;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Checksum Optional Property Getter
|
||||
///
|
||||
bool BarcodeStyle::checksumOptional() const
|
||||
{
|
||||
return mChecksumOptional;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Default Digits Property Getter
|
||||
///
|
||||
const QString& BarcodeStyle::defaultDigits() const
|
||||
{
|
||||
return mDefaultDigits;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Freeform Property Getter
|
||||
///
|
||||
bool BarcodeStyle::canFreeform() const
|
||||
{
|
||||
return mCanFreeform;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Prefered N Property Getter
|
||||
///
|
||||
int BarcodeStyle::preferedN() const
|
||||
{
|
||||
return mPreferedN;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Generate Example Digits
|
||||
///
|
||||
QString BarcodeStyle::exampleDigits( int n ) const
|
||||
{
|
||||
using std::max;
|
||||
|
||||
if ( mCanFreeform )
|
||||
{
|
||||
return QString( max( n, 1 ), QChar('0') );
|
||||
}
|
||||
else
|
||||
{
|
||||
return mDefaultDigits;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/* BarcodeStyle.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_BarcodeStyle_h
|
||||
#define glabels_BarcodeStyle_h
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Barcode Style Type
|
||||
///
|
||||
struct 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 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
const QString& id() const;
|
||||
|
||||
const QString& backendId() const;
|
||||
|
||||
const QString& name() const;
|
||||
|
||||
bool canText() const;
|
||||
|
||||
bool textOptional() const;
|
||||
|
||||
bool canChecksum() const;
|
||||
|
||||
bool checksumOptional() const;
|
||||
|
||||
const QString& defaultDigits() const;
|
||||
|
||||
bool canFreeform() const;
|
||||
|
||||
int preferedN() 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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_BarcodeStyle_h
|
||||
@@ -0,0 +1,79 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
|
||||
project (app CXX)
|
||||
|
||||
set (glabels_sources
|
||||
glabels_main.cpp
|
||||
BarcodeBackends.cpp
|
||||
BarcodeMenu.cpp
|
||||
BarcodeMenuButton.cpp
|
||||
BarcodeMenuItem.cpp
|
||||
BarcodeStyle.cpp
|
||||
ColorNode.cpp
|
||||
ColorSwatch.cpp
|
||||
File.cpp
|
||||
Help.cpp
|
||||
LabelModel.cpp
|
||||
LabelModelObject.cpp
|
||||
LabelModelBoxObject.cpp
|
||||
LabelRegion.cpp
|
||||
MainWindow.cpp
|
||||
MergeField.cpp
|
||||
MergeRecord.cpp
|
||||
TemplatePicker.cpp
|
||||
TemplatePickerItem.cpp
|
||||
TextNode.cpp
|
||||
NewLabelDialog.cpp
|
||||
SimplePreview.cpp
|
||||
View.cpp
|
||||
)
|
||||
|
||||
set (glabels_qobject_headers
|
||||
BarcodeMenu.h
|
||||
BarcodeMenuButton.h
|
||||
BarcodeMenuItem.h
|
||||
LabelModel.h
|
||||
LabelModelObject.h
|
||||
LabelModelBoxObject.h
|
||||
NewLabelDialog.h
|
||||
MainWindow.h
|
||||
SimplePreview.h
|
||||
TemplatePicker.h
|
||||
View.h
|
||||
)
|
||||
|
||||
set (glabels_forms
|
||||
ui/NewLabelDialog.ui
|
||||
)
|
||||
|
||||
set (glabels_resource_files
|
||||
icons.qrc
|
||||
images.qrc
|
||||
)
|
||||
|
||||
qt4_wrap_cpp (glabels_moc_sources ${glabels_qobject_headers})
|
||||
qt4_wrap_ui (glabels_forms_headers ${glabels_forms})
|
||||
qt4_add_resources(glabels_qrc_sources ${glabels_resource_files})
|
||||
|
||||
include (${QT_USE_FILE})
|
||||
|
||||
|
||||
include_directories (
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${glabels_qt_SOURCE_DIR}
|
||||
)
|
||||
|
||||
link_directories (
|
||||
${glabels_qt_SOURCE_DIR}/libglabels
|
||||
)
|
||||
|
||||
add_executable (glabels-qt ${glabels_sources} ${glabels_moc_sources} ${glabels_qrc_sources} ${glabels_forms_headers})
|
||||
|
||||
target_link_libraries (glabels-qt
|
||||
libglabels
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
|
||||
|
||||
install (TARGETS glabels-qt RUNTIME DESTINATION bin)
|
||||
@@ -0,0 +1,151 @@
|
||||
/* ColorNode.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ColorNode.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Default Constructor
|
||||
///
|
||||
ColorNode::ColorNode()
|
||||
: mFieldFlag(false), mColor(QColor::fromRgba(0x00000000)), mKey("")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Data
|
||||
///
|
||||
ColorNode::ColorNode( bool fieldFlag, const QColor& color, const QString& key )
|
||||
: mFieldFlag(fieldFlag), mColor(color), mKey(key)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Color
|
||||
///
|
||||
ColorNode::ColorNode( const QColor& color )
|
||||
: mFieldFlag(false), mColor(color), mKey("")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor From Key
|
||||
///
|
||||
ColorNode::ColorNode( const QString& key )
|
||||
: mFieldFlag(true), mColor(QColor::fromRgba(0x00000000)), mKey(key)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// == Operator
|
||||
///
|
||||
bool ColorNode::operator==( const ColorNode& cn )
|
||||
{
|
||||
return ( (mFieldFlag == cn.mFieldFlag) &&
|
||||
(mColor == cn.mColor) &&
|
||||
(mKey == cn.mKey) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// != Operator
|
||||
///
|
||||
bool ColorNode::operator!=( const ColorNode& cn )
|
||||
{
|
||||
return ( (mFieldFlag != cn.mFieldFlag) ||
|
||||
(mColor != cn.mColor) ||
|
||||
(mKey != cn.mKey) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Field Flag Property Getter
|
||||
///
|
||||
bool ColorNode::fieldFlag( void ) const
|
||||
{
|
||||
return mFieldFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Color Property Getter
|
||||
///
|
||||
const QColor& ColorNode::color( void ) const
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Key Property
|
||||
///
|
||||
const QString& ColorNode::key( void ) const
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
|
||||
|
||||
#if TODO
|
||||
QColor ColorNode::expand( MergeRecord? record )
|
||||
{
|
||||
if ( fieldFlag )
|
||||
{
|
||||
if ( record == null )
|
||||
{
|
||||
return QColor.fromRgba(0x00000000);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? text = record.evalKey( key );
|
||||
if ( text != null )
|
||||
{
|
||||
Gdk.Color gdkColor = Gdk.Color();
|
||||
if ( Gdk.Color.parse( text, out gdkColor ) )
|
||||
{
|
||||
Color color = Color.from_gdkColor( gdkColor );
|
||||
return color;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Color.fromRgba(0x00000000);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Color.fromRgba(0x00000000);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return color;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/* ColorNode.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_ColorNode_h
|
||||
#define glabels_ColorNode_h
|
||||
|
||||
#include <QString>
|
||||
#include <QColor>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Color Node Type
|
||||
///
|
||||
struct ColorNode
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
ColorNode();
|
||||
|
||||
ColorNode( bool fieldFlag, const QColor& color, const QString& key );
|
||||
|
||||
ColorNode( const QColor& color );
|
||||
|
||||
ColorNode( const QString& key );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operators
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool operator==( const ColorNode& cn );
|
||||
|
||||
bool operator!=( const ColorNode& cn );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Field Flag Property
|
||||
//
|
||||
bool fieldFlag( void ) const;
|
||||
|
||||
|
||||
//
|
||||
// Color Property
|
||||
//
|
||||
const QColor& color( void ) const;
|
||||
|
||||
|
||||
//
|
||||
// Key Property
|
||||
//
|
||||
const QString& key( void ) const;
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
#if TODO
|
||||
QColor expand( MergeRecord? record );
|
||||
#endif
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
bool mFieldFlag;
|
||||
QColor mColor;
|
||||
QString mKey;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_ColorNode_h
|
||||
@@ -0,0 +1,83 @@
|
||||
/* ColorSwatch.cpp
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ColorSwatch.h"
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
//
|
||||
// Private Configuration Data
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const QColor outlineColor( 0, 0, 0 );
|
||||
const double outlineWidthPixels = 1;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
ColorSwatch::ColorSwatch( int w, int h, QColor& color, QWidget *parent )
|
||||
: mW(w), mH(h), mColor(color), QGraphicsView(parent)
|
||||
{
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
viewport()->setAutoFillBackground(false);
|
||||
setFrameStyle( QFrame::NoFrame );
|
||||
setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
|
||||
resize( mW, mH );
|
||||
fitInView( 0, 0, mW, mH, Qt::KeepAspectRatio );
|
||||
|
||||
mScene = new QGraphicsScene();
|
||||
setScene( mScene );
|
||||
|
||||
mScene->setSceneRect( 0, 0, mW, mH );
|
||||
|
||||
QBrush brush( mColor );
|
||||
QPen pen( outlineColor );
|
||||
pen.setWidthF( outlineWidthPixels );
|
||||
|
||||
mSwatchItem = new QGraphicsRectItem( 1, 1, mW-2, mH-2 );
|
||||
mSwatchItem->setBrush( brush );
|
||||
mSwatchItem->setPen( pen );
|
||||
|
||||
mScene->addItem( mSwatchItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Color Property Setter
|
||||
///
|
||||
void ColorSwatch::setColor( QColor& color )
|
||||
{
|
||||
mColor = color;
|
||||
|
||||
QBrush brush( mColor );
|
||||
mSwatchItem->setBrush( brush );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/* ColorSwatch.h
|
||||
*
|
||||
* Copyright (C) 2014 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_ColorSwatch_h
|
||||
#define glabels_ColorSwatch_h
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QColor>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Simple Preview Widget
|
||||
///
|
||||
class ColorSwatch : public QGraphicsView
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
ColorSwatch( int w, int h, QColor& color, QWidget *parent = 0 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void setColor( QColor& color );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
int mW;
|
||||
int mH;
|
||||
QColor mColor;
|
||||
|
||||
QGraphicsScene* mScene;
|
||||
QGraphicsRectItem* mSwatchItem;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_ColorSwatch_h
|
||||
@@ -0,0 +1,39 @@
|
||||
/* File.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "File.h"
|
||||
|
||||
#include "NewLabelDialog.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Open a New Label Dialog
|
||||
///
|
||||
void File::newLabel( QWidget *parent )
|
||||
{
|
||||
NewLabelDialog newDialog( parent );
|
||||
newDialog.exec();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/* File.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_File_h
|
||||
#define glabels_File_h
|
||||
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// File Actions
|
||||
///
|
||||
namespace File
|
||||
{
|
||||
void newLabel( QWidget *parent );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_File_h
|
||||
@@ -0,0 +1,62 @@
|
||||
/* Help.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Help.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Display Help Contents
|
||||
///
|
||||
void Help::displayContents( QWidget *parent )
|
||||
{
|
||||
std::cout << "TODO: Help::displayContents" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Display Help->About Dialog
|
||||
///
|
||||
void Help::displayAbout( QWidget *parent )
|
||||
{
|
||||
QMessageBox aboutBox( QMessageBox::NoIcon,
|
||||
QMessageBox::tr("About gLabels"),
|
||||
QMessageBox::tr("<h2>gLabels-qt</h2>"
|
||||
"<p>x.x.x</p>"
|
||||
"<p>A label and business card creation program.</p>"
|
||||
"<font size=\"smaller\">"
|
||||
"<p><a href=\"http://glabels.org\">Homepage</a></p>"
|
||||
"<p>Copyright © 2013 Jim Evins <evins@snaught.com></p>"
|
||||
"</font>"),
|
||||
QMessageBox::Ok,
|
||||
parent );
|
||||
aboutBox.setIconPixmap( QPixmap( ":/images/glabels-logo.png" ) );
|
||||
|
||||
aboutBox.exec();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/* Help.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Help_h
|
||||
#define glabels_Help_h
|
||||
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Help Actions
|
||||
///
|
||||
namespace Help
|
||||
{
|
||||
void displayContents( QWidget *parent );
|
||||
void displayAbout( QWidget *parent );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_Help_h
|
||||
@@ -0,0 +1,472 @@
|
||||
/* Icons.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_Icons_h
|
||||
#define glabels_Icons_h
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Glabels Icons
|
||||
///
|
||||
namespace Icons
|
||||
{
|
||||
|
||||
class Arrow : public QIcon
|
||||
{
|
||||
public:
|
||||
Arrow()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-arrow.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-arrow.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Barcode : public QIcon
|
||||
{
|
||||
public:
|
||||
Barcode()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-barcode.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-barcode.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Box : public QIcon
|
||||
{
|
||||
public:
|
||||
Box()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-box.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-box.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Ellipse : public QIcon
|
||||
{
|
||||
public:
|
||||
Ellipse()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-ellipse.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-ellipse.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Image : public QIcon
|
||||
{
|
||||
public:
|
||||
Image()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-image.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-image.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Line : public QIcon
|
||||
{
|
||||
public:
|
||||
Line()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-line.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-line.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Text : public QIcon
|
||||
{
|
||||
public:
|
||||
Text()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-text.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-text.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Merge : public QIcon
|
||||
{
|
||||
public:
|
||||
Merge()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-merge.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-merge.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ObjectProperties : public QIcon
|
||||
{
|
||||
public:
|
||||
ObjectProperties()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-object-properties.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-object-properties.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignLeft : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignLeft()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-align-left.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignHCenter : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignHCenter()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-align-hcenter.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignRight : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignRight()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-align-right.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignBottom : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignBottom()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-align-bottom.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignVCenter : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignVCenter()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-align-vcenter.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignTop : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignTop()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-align-top.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CenterHoriz : public QIcon
|
||||
{
|
||||
public:
|
||||
CenterHoriz()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-center-horiz.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CenterVert : public QIcon
|
||||
{
|
||||
public:
|
||||
CenterVert()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-center-vert.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FlipHoriz : public QIcon
|
||||
{
|
||||
public:
|
||||
FlipHoriz()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-flip-horiz.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FlipVert : public QIcon
|
||||
{
|
||||
public:
|
||||
FlipVert()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-flip-vert.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class RotateLeft : public QIcon
|
||||
{
|
||||
public:
|
||||
RotateLeft()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-rotate-left.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class RotateRight : public QIcon
|
||||
{
|
||||
public:
|
||||
RotateRight()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-rotate-right.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class OrderBottom : public QIcon
|
||||
{
|
||||
public:
|
||||
OrderBottom()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-order-bottom.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class OrderTop : public QIcon
|
||||
{
|
||||
public:
|
||||
OrderTop()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-order-top.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignTextBottom : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignTextBottom()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/glabels-align-text-bottom.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignTextMiddle : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignTextMiddle()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/glabels-align-text-middle.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class AlignTextTop : public QIcon
|
||||
{
|
||||
public:
|
||||
AlignTextTop()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/glabels-align-text-top.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class BucketFill : public QIcon
|
||||
{
|
||||
public:
|
||||
BucketFill()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-bucket-fill.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-bucket-fill.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Pencil : public QIcon
|
||||
{
|
||||
public:
|
||||
Pencil()
|
||||
{
|
||||
addFile( ":icons/16x16/actions/glabels-pencil.png" );
|
||||
addFile( ":icons/24x24/actions/glabels-pencil.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class Glabels : public QIcon
|
||||
{
|
||||
public:
|
||||
Glabels()
|
||||
{
|
||||
addFile( ":icons/16x16/apps/glabels.png" );
|
||||
addFile( ":icons/24x24/apps/glabels.png" );
|
||||
addFile( ":icons/32x32/apps/glabels.png" );
|
||||
addFile( ":icons/48x48/apps/glabels.png" );
|
||||
addFile( ":icons/scalable/apps/glabels.svg" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// Fallback Icons. These are fallbacks for icons that would normally come from the current theme,
|
||||
/// if supported. These icons are copied from the mate-icon-theme (GPL-v3 or CC-BY-SA-v3).
|
||||
///
|
||||
namespace Fallback
|
||||
{
|
||||
|
||||
class EditCopy : public QIcon
|
||||
{
|
||||
public:
|
||||
EditCopy()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-edit-copy.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class EditCut : public QIcon
|
||||
{
|
||||
public:
|
||||
EditCut()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-edit-cut.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class EditPaste : public QIcon
|
||||
{
|
||||
public:
|
||||
EditPaste()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-edit-paste.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FileNew : public QIcon
|
||||
{
|
||||
public:
|
||||
FileNew()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-file-new.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FileOpen : public QIcon
|
||||
{
|
||||
public:
|
||||
FileOpen()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-file-open.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FilePrint : public QIcon
|
||||
{
|
||||
public:
|
||||
FilePrint()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-file-print.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FileSave : public QIcon
|
||||
{
|
||||
public:
|
||||
FileSave()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-file-save.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FileSaveAs : public QIcon
|
||||
{
|
||||
public:
|
||||
FileSaveAs()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-file-save-as.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ZoomBestFit : public QIcon
|
||||
{
|
||||
public:
|
||||
ZoomBestFit()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-zoom-best-fit.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ZoomIn : public QIcon
|
||||
{
|
||||
public:
|
||||
ZoomIn()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-zoom-in.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ZoomOriginal : public QIcon
|
||||
{
|
||||
public:
|
||||
ZoomOriginal()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-zoom-original.png" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class ZoomOut : public QIcon
|
||||
{
|
||||
public:
|
||||
ZoomOut()
|
||||
{
|
||||
addFile( ":icons/24x24/actions/fallback-zoom-out.png" );
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // glabels_Icons_h
|
||||
@@ -0,0 +1,979 @@
|
||||
/* LabelModel.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModel.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
#include "LabelRegion.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Default constructor.
|
||||
///
|
||||
LabelModel::LabelModel() : mModified(true), mTmplate(0), mRotate(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Add object.
|
||||
///
|
||||
void LabelModel::addObject( LabelModelObject* object )
|
||||
{
|
||||
object->setParent( this );
|
||||
mObjectList << object;
|
||||
|
||||
connect( object, SIGNAL(changed()), this, SLOT(onObjectChanged()) );
|
||||
connect( object, SIGNAL(moved()), this, SLOT(onObjectMoved()) );
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit objectAdded( object );
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Object Changed Slot
|
||||
///
|
||||
void LabelModel::onObjectChanged()
|
||||
{
|
||||
mModified = true;
|
||||
|
||||
emit objectChanged( qobject_cast<LabelModelObject*>(sender()) );
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Object Moved Slot
|
||||
///
|
||||
void LabelModel::onObjectMoved()
|
||||
{
|
||||
mModified = true;
|
||||
|
||||
emit objectMoved( qobject_cast<LabelModelObject*>(sender()) );
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Delete Object
|
||||
///
|
||||
void LabelModel::deleteObject( LabelModelObject* object )
|
||||
{
|
||||
object->unselect();
|
||||
mObjectList.removeOne( object );
|
||||
|
||||
disconnect( object, 0, this, 0 );
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit objectDeleted( object );
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Select Object
|
||||
///
|
||||
void LabelModel::selectObject( LabelModelObject* object )
|
||||
{
|
||||
object->select();
|
||||
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Unselect Object
|
||||
///
|
||||
void LabelModel::unselectObject( LabelModelObject* object )
|
||||
{
|
||||
object->unselect();
|
||||
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Select All Objects
|
||||
///
|
||||
void LabelModel::selectAll()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
object->select();
|
||||
}
|
||||
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Unselect All Objects
|
||||
///
|
||||
void LabelModel::unselectAll()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
object->unselect();
|
||||
}
|
||||
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Select Region
|
||||
///
|
||||
void LabelModel::selectRegion( const LabelRegion ®ion )
|
||||
{
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
double rX1 = min( region.x1(), region.x2() );
|
||||
double rY1 = min( region.y1(), region.y2() );
|
||||
double rX2 = max( region.x1(), region.x2() );
|
||||
double rY2 = max( region.y1(), region.y2() );
|
||||
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
LabelRegion objectExtent = object->getExtent();
|
||||
|
||||
if ( (objectExtent.x1() >= rX1) &&
|
||||
(objectExtent.x2() <= rX2) &&
|
||||
(objectExtent.y1() >= rY1) &&
|
||||
(objectExtent.y2() <= rY2) )
|
||||
{
|
||||
object->select();
|
||||
}
|
||||
}
|
||||
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is Selection Empty?
|
||||
///
|
||||
bool LabelModel::isSelectionEmpty()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is Selection Atomic?
|
||||
///
|
||||
bool LabelModel::isSelectionAtomic()
|
||||
{
|
||||
int nSelected = 0;
|
||||
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
nSelected++;
|
||||
if ( nSelected > 1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (nSelected == 1);
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get List of Selected Objects
|
||||
///
|
||||
QList<LabelModelObject*> LabelModel::getSelection()
|
||||
{
|
||||
QList<LabelModelObject*> selectedList;
|
||||
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
selectedList << object;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get First Object in Selection List
|
||||
///
|
||||
LabelModelObject* LabelModel::getFirstSelectedObject()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
return object;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Any Objects in Selection Accept Text Properties?
|
||||
///
|
||||
bool LabelModel::canSelectionText()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() && object->canText() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Any Objects in Selection Accept Fill Property?
|
||||
///
|
||||
bool LabelModel::canSelectionFill()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() && object->canFill() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Any Objects in Selection Accept Line Color Property?
|
||||
///
|
||||
bool LabelModel::canSelectionLineColor()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() && object->canLineColor() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Any Objects in Selection Accept Line Width Property?
|
||||
///
|
||||
bool LabelModel::canSelectionLineWidth()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() && object->canLineWidth() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Delete Selected Objects
|
||||
///
|
||||
void LabelModel::deleteSelection()
|
||||
{
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
deleteObject( object );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Raise Selected Objects To Top
|
||||
///
|
||||
void LabelModel::raiseSelectionToTop()
|
||||
{
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
mObjectList.removeOne( object );
|
||||
}
|
||||
|
||||
/// Move to end of list, representing top most object.
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
mObjectList.push_back( object );
|
||||
emit objectToTop( object );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Lower Selected Objects To Bottom
|
||||
///
|
||||
void LabelModel::lowerSelectionToBottom()
|
||||
{
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
mObjectList.removeOne( object );
|
||||
}
|
||||
|
||||
/// Move to front of list, representing bottom most object.
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
mObjectList.push_front( object );
|
||||
emit objectToBottom( object );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Rotate Selected Objects
|
||||
///
|
||||
void LabelModel::rotateSelection( double thetaDegs )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->rotate( thetaDegs );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Rotate Selected Objects Left 90 degrees
|
||||
///
|
||||
void LabelModel::rotateSelectionLeft()
|
||||
{
|
||||
rotateSelection( -90.0 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Rotate Selected Objects Right 90 degrees
|
||||
///
|
||||
void LabelModel::rotateSelectionRight()
|
||||
{
|
||||
rotateSelection( 90.0 );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Flip Selected Objects Horizontally
|
||||
///
|
||||
void LabelModel::flipSelectionHoriz()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->flipHoriz();
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Flip Selected Objects Vertically
|
||||
///
|
||||
void LabelModel::flipSelectionVert()
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->flipVert();
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Align Selected Objects To Their Left Edges
|
||||
///
|
||||
void LabelModel::alignSelectionLeft()
|
||||
{
|
||||
if ( isSelectionEmpty() || isSelectionAtomic() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find left-most edge.
|
||||
double x1_min = 7200; /// Start with a very large value: 7200pts = 100in
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
if ( r.x1() < x1_min ) x1_min = r.x1();
|
||||
}
|
||||
|
||||
/// Now adjust the object positions to line up the left edges at left-most edge.
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dx = x1_min - r.x1();
|
||||
object->setPositionRelative( dx, 0 );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Align Selected Objects To Their Right Edges
|
||||
///
|
||||
void LabelModel::alignSelectionRight()
|
||||
{
|
||||
if ( isSelectionEmpty() || isSelectionAtomic() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find right-most edge.
|
||||
double x1_max = -7200; /// Start with a very large negative value: 7200pts = 100in
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
if ( r.x1() > x1_max ) x1_max = r.x1();
|
||||
}
|
||||
|
||||
/// Now adjust the object positions to line up the right edges at right-most edge.
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dx = x1_max - r.x1();
|
||||
object->setPositionRelative( dx, 0 );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Align Selected Objects To Their Horizontal Centers
|
||||
///
|
||||
void LabelModel::alignSelectionHCenter()
|
||||
{
|
||||
if ( isSelectionEmpty() || isSelectionAtomic() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find average center of objects.
|
||||
double xsum = 0;
|
||||
int n = 0;
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
xsum += (r.x1() + r.x2()) / 2.0;
|
||||
n++;
|
||||
}
|
||||
double xavg = xsum / n;
|
||||
|
||||
/// Find object closest to average center of objects.
|
||||
double xcenter = 7200; /// Start with very large value.
|
||||
double dxmin = fabs( xavg - xcenter );
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dx = fabs( xavg - (r.x1() + r.x2())/2.0 );
|
||||
if ( dx < dxmin )
|
||||
{
|
||||
dxmin = dx;
|
||||
xcenter = (r.x1() + r.x2()) / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
/// Now adjust the object positions to line up with the center of this object.
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dx = xcenter - (r.x1() + r.x2())/2.0;
|
||||
object->setPositionRelative( dx, 0 );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Align Selected Objects To Their Top Edges
|
||||
///
|
||||
void LabelModel::alignSelectionTop()
|
||||
{
|
||||
if ( isSelectionEmpty() || isSelectionAtomic() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find top-most edge.
|
||||
double y1_min = 7200; /// Start with a very large value: 7200pts = 100in
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
if ( r.y1() < y1_min ) y1_min = r.y1();
|
||||
}
|
||||
|
||||
/// Now adjust the object positions to line up the top edges at top-most edge.
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dy = y1_min - r.y1();
|
||||
object->setPositionRelative( 0, dy );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Align Selected Objects To Their Bottom Edges
|
||||
///
|
||||
void LabelModel::alignSelectionBottom()
|
||||
{
|
||||
if ( isSelectionEmpty() || isSelectionAtomic() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find bottom-most edge.
|
||||
double y1_max = -7200; /// Start with a very large negative value: 7200pts = 100in
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
if ( r.y1() > y1_max ) y1_max = r.y1();
|
||||
}
|
||||
|
||||
/// Now adjust the object positions to line up the bottom edges at bottom-most edge.
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dy = y1_max - r.y1();
|
||||
object->setPositionRelative( 0, dy );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Align Selected Objects To Their Vertical Centers Edges
|
||||
///
|
||||
void LabelModel::alignSelectionVCenter()
|
||||
{
|
||||
if ( isSelectionEmpty() || isSelectionAtomic() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QList<LabelModelObject*> selectedList = getSelection();
|
||||
|
||||
/// Find average center of objects.
|
||||
double ysum = 0;
|
||||
int n = 0;
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
ysum += (r.y1() + r.y2()) / 2.0;
|
||||
n++;
|
||||
}
|
||||
double yavg = ysum / n;
|
||||
|
||||
/// Find object closest to average center of objects.
|
||||
double ycenter = 7200; /// Start with very large value.
|
||||
double dymin = fabs( yavg - ycenter );
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dy = fabs( yavg - (r.y1() + r.y2())/2.0 );
|
||||
if ( dy < dymin )
|
||||
{
|
||||
dymin = dy;
|
||||
ycenter = (r.y1() + r.y2()) / 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
/// Now adjust the object positions to line up with the center of this object.
|
||||
foreach ( LabelModelObject* object, selectedList )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double dy = ycenter - (r.y1() + r.y2())/2.0;
|
||||
object->setPositionRelative( 0, dy );
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Align Selected Objects To Center Of Label Horizontally
|
||||
///
|
||||
void LabelModel::centerSelectionHoriz()
|
||||
{
|
||||
double xLabelCenter = w() / 2.0;
|
||||
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double xObjectCenter = (r.x1() + r.x2()) / 2.0;
|
||||
double dx = xLabelCenter - xObjectCenter;
|
||||
object->setPositionRelative( dx, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Align Selected Objects To Center Of Label Vertically
|
||||
///
|
||||
void LabelModel::centerSelectionVert()
|
||||
{
|
||||
double yLabelCenter = h() / 2.0;
|
||||
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
LabelRegion r = object->getExtent();
|
||||
double yObjectCenter = (r.y1() + r.y2()) / 2.0;
|
||||
double dy = yLabelCenter - yObjectCenter;
|
||||
object->setPositionRelative( 0, dy );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Move Selected Objects By dx,dy
|
||||
///
|
||||
void LabelModel::moveSelection( double dx, double dy )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setPositionRelative( dx, dy );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Font Family Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionFontFamily( const QString &fontFamily )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setFontFamily( fontFamily );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Font Size Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionFontSize( double fontSize )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setFontSize( fontSize );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Font Weight Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionFontWeight( QFont::Weight fontWeight )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setFontWeight( fontWeight );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Font Italic Flag Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionFontItalicFlag( bool fontItalicFlag )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setFontItalicFlag( fontItalicFlag );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Text Horizontal Alignment Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionTextHAlign( Qt::Alignment textHAlign )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setTextHAlign( textHAlign );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Text Vertical Alignment Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionTextVAlign( Qt::Alignment textVAlign )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setTextVAlign( textVAlign );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Text Line Spacing Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionTextLineSpacing( double textLineSpacing )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setTextLineSpacing( textLineSpacing );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Text Color Node Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionTextColorNode( ColorNode textColorNode )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setTextColorNode( textColorNode );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Line Width Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionLineWidth( double lineWidth )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setLineWidth( lineWidth );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Line Color Node Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionLineColorNode( ColorNode lineColorNode )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setLineColorNode( lineColorNode );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Fill Color Node Of Selected Objects
|
||||
///
|
||||
void LabelModel::setSelectionFillColorNode( ColorNode fillColorNode )
|
||||
{
|
||||
foreach ( LabelModelObject* object, mObjectList )
|
||||
{
|
||||
if ( object->isSelected() )
|
||||
{
|
||||
object->setFillColorNode( fillColorNode );
|
||||
}
|
||||
}
|
||||
|
||||
mModified = true;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
/* LabelModel.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_LabelModel_h
|
||||
#define glabels_LabelModel_h
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
|
||||
#include "libglabels/Template.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
// Forward References
|
||||
class LabelModelObject;
|
||||
class LabelRegion;
|
||||
class ColorNode;
|
||||
|
||||
|
||||
//////////////////////////////////////////////
|
||||
//////////////////////////////////////////////
|
||||
// LabelModel
|
||||
//////////////////////////////////////////////
|
||||
//////////////////////////////////////////////
|
||||
class LabelModel : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Lifecycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
LabelModel();
|
||||
virtual ~LabelModel() {}
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////
|
||||
signals:
|
||||
void changed();
|
||||
void nameChanged();
|
||||
void sizeChanged();
|
||||
void selectionChanged();
|
||||
void objectChanged( LabelModelObject* object );
|
||||
void objectMoved( LabelModelObject* object );
|
||||
void objectAdded( LabelModelObject* object );
|
||||
void objectDeleted( LabelModelObject* object );
|
||||
void objectToTop( LabelModelObject* object );
|
||||
void objectToBottom( LabelModelObject* object );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
inline bool isModified() const;
|
||||
inline void clearModified();
|
||||
|
||||
inline const QString& filename() const;
|
||||
inline void setFilename( const QString &filename );
|
||||
|
||||
inline int compressionLevel() const;
|
||||
inline void setCompressionLevel( int compressionLevel );
|
||||
|
||||
inline const libglabels::Template* tmplate() const;
|
||||
inline const libglabels::Frame* frame() const;
|
||||
inline void setTmplate( const libglabels::Template* tmplate );
|
||||
|
||||
inline bool rotate() const;
|
||||
inline void setRotate( bool rotate );
|
||||
|
||||
inline double w() const;
|
||||
inline double h() const;
|
||||
|
||||
inline const QList<LabelModelObject*>& objectList() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Manage objects
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void addObject( LabelModelObject* object );
|
||||
void deleteObject( LabelModelObject* object );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Manipulate selection
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void selectObject( LabelModelObject* object );
|
||||
void unselectObject( LabelModelObject* object );
|
||||
void selectAll();
|
||||
void unselectAll();
|
||||
void selectRegion( const LabelRegion& region );
|
||||
bool isSelectionEmpty();
|
||||
bool isSelectionAtomic();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Get selected objects
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QList<LabelModelObject*> getSelection();
|
||||
LabelModelObject* getFirstSelectedObject();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Query selection capabilities
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool canSelectionText();
|
||||
bool canSelectionFill();
|
||||
bool canSelectionLineColor();
|
||||
bool canSelectionLineWidth();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operations on selections
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void deleteSelection();
|
||||
void raiseSelectionToTop();
|
||||
void lowerSelectionToBottom();
|
||||
void rotateSelection( double thetaDegs );
|
||||
void rotateSelectionLeft();
|
||||
void rotateSelectionRight();
|
||||
void flipSelectionHoriz();
|
||||
void flipSelectionVert();
|
||||
void alignSelectionLeft();
|
||||
void alignSelectionRight();
|
||||
void alignSelectionHCenter();
|
||||
void alignSelectionTop();
|
||||
void alignSelectionBottom();
|
||||
void alignSelectionVCenter();
|
||||
void centerSelectionHoriz();
|
||||
void centerSelectionVert();
|
||||
void moveSelection( double dx, double 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( double lineWidth );
|
||||
void setSelectionLineColorNode( ColorNode lineColorNode );
|
||||
void setSelectionFillColorNode( ColorNode fillColorNode );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void onObjectChanged();
|
||||
void onObjectMoved();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
bool mModified;
|
||||
QString mFilename;
|
||||
int mCompressionLevel;
|
||||
const libglabels::Template* mTmplate;
|
||||
const libglabels::Frame* mFrame;
|
||||
bool mRotate;
|
||||
|
||||
QList<LabelModelObject*> mObjectList;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// INLINE METHODS
|
||||
/////////////////////////////////
|
||||
|
||||
inline bool LabelModel::isModified() const
|
||||
{
|
||||
return mModified;
|
||||
}
|
||||
|
||||
|
||||
inline void LabelModel::clearModified()
|
||||
{
|
||||
mModified = false;
|
||||
}
|
||||
|
||||
|
||||
inline const QString& LabelModel::filename() const
|
||||
{
|
||||
return mFilename;
|
||||
}
|
||||
|
||||
|
||||
inline void LabelModel::setFilename( const QString &filename )
|
||||
{
|
||||
if ( mFilename != filename )
|
||||
{
|
||||
mFilename = filename;
|
||||
emit nameChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline int LabelModel::compressionLevel() const
|
||||
{
|
||||
return mCompressionLevel;
|
||||
}
|
||||
|
||||
|
||||
inline void LabelModel::setCompressionLevel( int compressionLevel )
|
||||
{
|
||||
mCompressionLevel = compressionLevel;
|
||||
}
|
||||
|
||||
|
||||
inline const libglabels::Template* LabelModel::tmplate() const
|
||||
{
|
||||
return mTmplate;
|
||||
}
|
||||
|
||||
|
||||
inline const libglabels::Frame* LabelModel::frame() const
|
||||
{
|
||||
return mFrame;
|
||||
}
|
||||
|
||||
|
||||
inline void LabelModel::setTmplate( const libglabels::Template* tmplate )
|
||||
{
|
||||
if (mTmplate != tmplate)
|
||||
{
|
||||
mTmplate = tmplate;
|
||||
mFrame = tmplate->frames().first();
|
||||
mModified = true;
|
||||
emit changed();
|
||||
emit sizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline bool LabelModel::rotate() const
|
||||
{
|
||||
return mRotate;
|
||||
}
|
||||
|
||||
|
||||
inline void LabelModel::setRotate( bool rotate )
|
||||
{
|
||||
if (mRotate != rotate)
|
||||
{
|
||||
mRotate = rotate;
|
||||
mModified = true;
|
||||
emit changed();
|
||||
emit sizeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline double LabelModel::w() const
|
||||
{
|
||||
return mRotate ? mFrame->h() : mFrame->w();
|
||||
}
|
||||
|
||||
|
||||
inline double LabelModel::h() const
|
||||
{
|
||||
return mRotate ? mFrame->w() : mFrame->h();
|
||||
}
|
||||
|
||||
|
||||
inline const QList<LabelModelObject*>& LabelModel::objectList() const
|
||||
{
|
||||
return mObjectList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_LabelModel_h
|
||||
@@ -0,0 +1,186 @@
|
||||
/* LabelModelBoxObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelBoxObject.h"
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QBrush>
|
||||
#include <QPen>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelBoxObject::LabelModelBoxObject( QObject* parent ) : LabelModelObject(parent)
|
||||
{
|
||||
/* TODO: initialize default line and fill poperties. */
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelBoxObject::~LabelModelBoxObject()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Getter
|
||||
///
|
||||
double LabelModelBoxObject::lineWidth( void ) const
|
||||
{
|
||||
return mLineWidth;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Width Property Setter
|
||||
///
|
||||
void LabelModelBoxObject::setLineWidth( double value )
|
||||
{
|
||||
if ( mLineWidth != value )
|
||||
{
|
||||
mLineWidth = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Getter
|
||||
///
|
||||
ColorNode LabelModelBoxObject::lineColorNode( void ) const
|
||||
{
|
||||
return mLineColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Line Color Node Property Setter
|
||||
///
|
||||
void LabelModelBoxObject::setLineColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mLineColorNode != value )
|
||||
{
|
||||
mLineColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Fill Color Node Property Getter
|
||||
///
|
||||
ColorNode LabelModelBoxObject::fillColorNode( void ) const
|
||||
{
|
||||
return mFillColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Fill Color Node Property Setter
|
||||
///
|
||||
void LabelModelBoxObject::setFillColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mFillColorNode != value )
|
||||
{
|
||||
mFillColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Fill Capability Implementation
|
||||
///
|
||||
bool LabelModelBoxObject::canFill()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Color Capability Implementation
|
||||
///
|
||||
bool LabelModelBoxObject::canLineColor()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Can Line Width Capability Implementation
|
||||
///
|
||||
bool LabelModelBoxObject::canLineWidth()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create QGraphicsItem suitable for representing this object
|
||||
///
|
||||
QGraphicsItem* LabelModelBoxObject::createGraphicsItem()
|
||||
{
|
||||
QGraphicsRectItem *rectItem = new QGraphicsRectItem( x0(), y0(), w(), h() );
|
||||
|
||||
QBrush brush( fillColorNode().color() );
|
||||
rectItem->setBrush( brush );
|
||||
|
||||
QPen pen( lineColorNode().color() );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
pen.setWidthF( lineWidth() );
|
||||
rectItem->setPen( pen );
|
||||
|
||||
updateGraphicsItemMatrix( rectItem );
|
||||
updateGraphicsItemShadow( rectItem );
|
||||
|
||||
return rectItem;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update a QGraphicsItem to keep it in sync with this object
|
||||
///
|
||||
void LabelModelBoxObject::updateGraphicsItem( QGraphicsItem* graphicsItem )
|
||||
{
|
||||
QGraphicsRectItem *rectItem = dynamic_cast<QGraphicsRectItem*>(graphicsItem);
|
||||
if ( rectItem )
|
||||
{
|
||||
rectItem->setRect( x0(), y0(), w(), h() );
|
||||
|
||||
QBrush brush( fillColorNode().color() );
|
||||
rectItem->setBrush( brush );
|
||||
|
||||
QPen pen( lineColorNode().color() );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
pen.setWidthF( lineWidth() );
|
||||
rectItem->setPen( pen );
|
||||
|
||||
updateGraphicsItemMatrix( rectItem );
|
||||
updateGraphicsItemShadow( rectItem );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
/* LabelModelBoxObject.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_LabelModelBoxObject_h
|
||||
#define glabels_LabelModelBoxObject_h
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Model Box Object
|
||||
///
|
||||
class LabelModelBoxObject : public LabelModelObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelBoxObject( QObject* parent = 0 );
|
||||
virtual ~LabelModelBoxObject();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Property Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Shape Property: lineWidth
|
||||
//
|
||||
virtual double lineWidth( void ) const;
|
||||
virtual void setLineWidth( double 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 );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Capability Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual bool canFill();
|
||||
virtual bool canLineColor();
|
||||
virtual bool canLineWidth();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// QGraphicsItem Method Implementations
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual QGraphicsItem* createGraphicsItem();
|
||||
virtual void updateGraphicsItem( QGraphicsItem* graphicsItem );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
double mLineWidth;
|
||||
ColorNode mLineColorNode;
|
||||
ColorNode mFillColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_LabelModelBoxObject_h
|
||||
@@ -0,0 +1,923 @@
|
||||
/* LabelModelObject.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QTransform>
|
||||
#include <QFont>
|
||||
#include <QGraphicsItem>
|
||||
#include <algorithm>
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "TextNode.h"
|
||||
#include "BarcodeStyle.h"
|
||||
#include "LabelRegion.h"
|
||||
#include "MergeRecord.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Next Object ID
|
||||
///
|
||||
int LabelModelObject::msNextId = 0;
|
||||
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
LabelModelObject::LabelModelObject( QObject *parent = 0 ) : QObject(parent)
|
||||
{
|
||||
mId = msNextId++;
|
||||
|
||||
mX0 = 0;
|
||||
mY0 = 0;
|
||||
mW = 0;
|
||||
mH = 0;
|
||||
mMatrix = QTransform();
|
||||
|
||||
mShadowState = false;
|
||||
mShadowX = 1.3;
|
||||
mShadowY = 1.3;
|
||||
mShadowColorNode = ColorNode( QColor::fromRgb(0x000000) );
|
||||
mShadowOpacity = 0.5;
|
||||
|
||||
mSelectedFlag = false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Destructor
|
||||
///
|
||||
LabelModelObject::~LabelModelObject()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// ID Property Getter
|
||||
///
|
||||
int LabelModelObject::id() const
|
||||
{
|
||||
return mId;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Selected Property Getter
|
||||
///
|
||||
bool LabelModelObject::isSelected() const
|
||||
{
|
||||
return mSelectedFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Selected Property Setter
|
||||
///
|
||||
void LabelModelObject::select( bool value )
|
||||
{
|
||||
mSelectedFlag = value;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clear Selected Property Setter
|
||||
///
|
||||
void LabelModelObject::unselect()
|
||||
{
|
||||
mSelectedFlag = false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// X0 Property Getter
|
||||
///
|
||||
double LabelModelObject::x0() const
|
||||
{
|
||||
return mX0;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// X0 Property Setter
|
||||
///
|
||||
void LabelModelObject::setX0( double value )
|
||||
{
|
||||
if ( mX0 != value )
|
||||
{
|
||||
mX0 = value;
|
||||
emit moved();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Y0 Property Getter
|
||||
///
|
||||
double LabelModelObject::y0() const
|
||||
{
|
||||
return mY0;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Y0 Property Setter
|
||||
///
|
||||
void LabelModelObject::setY0( double value )
|
||||
{
|
||||
if ( mY0 != value )
|
||||
{
|
||||
mY0 = value;
|
||||
emit moved();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// W (Width) Property Getter
|
||||
///
|
||||
double LabelModelObject::w() const
|
||||
{
|
||||
return mW;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// W (Width) Property Setter
|
||||
///
|
||||
void LabelModelObject::setW( double value )
|
||||
{
|
||||
if ( mW != value )
|
||||
{
|
||||
mW = value;
|
||||
emit moved();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// H (Height) Property Getter
|
||||
///
|
||||
double LabelModelObject::h() const
|
||||
{
|
||||
return mH;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// H (Height) Property Setter
|
||||
///
|
||||
void LabelModelObject::setH( double value )
|
||||
{
|
||||
if ( mH != value )
|
||||
{
|
||||
mH = value;
|
||||
emit moved();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Matrix Property Getter
|
||||
///
|
||||
QTransform LabelModelObject::matrix() const
|
||||
{
|
||||
return mMatrix;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Matrix Property Setter
|
||||
///
|
||||
void LabelModelObject::setMatrix( const QTransform& value )
|
||||
{
|
||||
if ( mMatrix != value )
|
||||
{
|
||||
mMatrix = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow State Property Getter
|
||||
///
|
||||
bool LabelModelObject::shadow() const
|
||||
{
|
||||
return mShadowState;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow State Property Setter
|
||||
///
|
||||
void LabelModelObject::setShadow( bool value )
|
||||
{
|
||||
if ( mShadowState != value )
|
||||
{
|
||||
mShadowState = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow X Property Getter
|
||||
///
|
||||
double LabelModelObject::shadowX() const
|
||||
{
|
||||
return mShadowX;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow X Property Setter
|
||||
///
|
||||
void LabelModelObject::setShadowX( double value )
|
||||
{
|
||||
if ( mShadowX != value )
|
||||
{
|
||||
mShadowX = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow Y Property Getter
|
||||
///
|
||||
double LabelModelObject::shadowY() const
|
||||
{
|
||||
return mShadowY;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow Y Property Setter
|
||||
///
|
||||
void LabelModelObject::setShadowY( double value )
|
||||
{
|
||||
if ( mShadowY != value )
|
||||
{
|
||||
mShadowY = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow Opacity Property Getter
|
||||
///
|
||||
double LabelModelObject::shadowOpacity() const
|
||||
{
|
||||
return mShadowOpacity;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow Opacity Property Setter
|
||||
///
|
||||
void LabelModelObject::setShadowOpacity( double value )
|
||||
{
|
||||
if ( mShadowOpacity != value )
|
||||
{
|
||||
mShadowOpacity = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow Color Node Property Getter
|
||||
///
|
||||
ColorNode LabelModelObject::shadowColorNode() const
|
||||
{
|
||||
return mShadowColorNode;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Shadow Color Node Property Setter
|
||||
///
|
||||
void LabelModelObject::setShadowColorNode( const ColorNode& value )
|
||||
{
|
||||
if ( mShadowColorNode != value )
|
||||
{
|
||||
mShadowColorNode = value;
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Family Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
QString LabelModelObject::fontFamily() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Family Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setFontFamily( const QString& value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Size Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
double LabelModelObject::fontSize() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Size Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setFontSize( double value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Weight Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
QFont::Weight LabelModelObject::fontWeight() const
|
||||
{
|
||||
return QFont::Normal;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Weight Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setFontWeight( QFont::Weight value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Italic Flag Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
bool LabelModelObject::fontItalicFlag() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Italic Flag Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setFontItalicFlag( bool value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Underline Flag Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
bool LabelModelObject::fontUnderlineFlag() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Font Underline Flag Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setFontUnderlineFlag( bool value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Color Node Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
ColorNode LabelModelObject::textColorNode() const
|
||||
{
|
||||
return ColorNode( QColor::fromRgba(0x00000000) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Color Node Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setTextColorNode( const ColorNode &value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Horizontal Alignment Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
Qt::Alignment LabelModelObject::textHAlign() const
|
||||
{
|
||||
return Qt::AlignLeft;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Horizontal Alignment Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setTextHAlign( Qt::Alignment value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Vertical Alignment Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
Qt::Alignment LabelModelObject::textVAlign() const
|
||||
{
|
||||
return Qt::AlignTop;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Vertical Alignment Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setTextVAlign( Qt::Alignment value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Line Spacing Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
double LabelModelObject::textLineSpacing() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Text Line Spacing Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setTextLineSpacing( double value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Filename Node Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
TextNode LabelModelObject::filenameNode() const
|
||||
{
|
||||
return TextNode();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Filename Node Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setFilenameNode( const TextNode& value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Line Width Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
double LabelModelObject::lineWidth() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Line Width Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setLineWidth( double value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Line Color Node Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
ColorNode LabelModelObject::lineColorNode() const
|
||||
{
|
||||
return ColorNode( QColor::fromRgba(0x00000000) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Line Color Node Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setLineColorNode( const ColorNode &value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Fill Color Node Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
ColorNode LabelModelObject::fillColorNode() const
|
||||
{
|
||||
return ColorNode( QColor::fromRgba(0x00000000) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Fill Color Node Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setFillColorNode( const ColorNode &value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Data Node Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
TextNode LabelModelObject::bcDataNode() const
|
||||
{
|
||||
return TextNode();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Data Node Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setBcDataNode( const TextNode &value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Text Flag Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
bool LabelModelObject::bcTextFlag() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Text Flag Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setBcTextFlag( bool value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Checksum Flag Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
bool LabelModelObject::bcChecksumFlag() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Checksum Flag Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setBcChecksumFlag( bool value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Color Node Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
ColorNode LabelModelObject::bcColorNode() const
|
||||
{
|
||||
return ColorNode( QColor::fromRgba(0x00000000) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Color Node Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setBcColorNode( const ColorNode &value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Style Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
BarcodeStyle LabelModelObject::bcStyle() const
|
||||
{
|
||||
return BarcodeStyle();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Style Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setBcStyle( const BarcodeStyle &value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Format Digits Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
int LabelModelObject::bcFormatDigits() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Barcode Format Digits Property Default Setter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
void LabelModelObject::setBcFormatDigits( int value )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Can Text Capability Read-Only Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
bool LabelModelObject::canText() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Can Fill Capability Read-Only Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
bool LabelModelObject::canFill() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Can Line Color Capability Read-Only Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
bool LabelModelObject::canLineColor() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Virtual Can Line Width Capability Read-Only Property Default Getter
|
||||
/// (Overridden by concrete class)
|
||||
///
|
||||
bool LabelModelObject::canLineWidth() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Absolute Position
|
||||
///
|
||||
void LabelModelObject::setPosition( double x0, double y0 )
|
||||
{
|
||||
if ( ( mX0 != x0 ) || ( mY0 != y0 ) )
|
||||
{
|
||||
mX0 = x0;
|
||||
mY0 = y0;
|
||||
|
||||
emit moved();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Relative Position
|
||||
///
|
||||
void LabelModelObject::setPositionRelative( double dx, double dy )
|
||||
{
|
||||
if ( ( dx != 0 ) || ( dy != 0 ) )
|
||||
{
|
||||
mX0 += dx;
|
||||
mY0 += dy;
|
||||
|
||||
emit moved();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Size
|
||||
///
|
||||
void LabelModelObject::setSize( double w, double h )
|
||||
{
|
||||
mW = w;
|
||||
mH = h;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Size (But Maintain Current Aspect Ratio)
|
||||
///
|
||||
void LabelModelObject::setSizeHonorAspect( double w, double h )
|
||||
{
|
||||
double aspectRatio = mH / mW;
|
||||
|
||||
if ( h > (w * aspectRatio) )
|
||||
{
|
||||
h = w * aspectRatio;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = h / aspectRatio;
|
||||
}
|
||||
|
||||
if ( ( mW != w ) || ( mH != h ) )
|
||||
{
|
||||
mW = w;
|
||||
mH = h;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Width (But Maintain Current Aspect Ratio)
|
||||
///
|
||||
void LabelModelObject::setWHonorAspect( double w )
|
||||
{
|
||||
double aspectRatio = mH / mW;
|
||||
double h = w * aspectRatio;
|
||||
|
||||
if ( ( mW != w ) || ( mH != h ) )
|
||||
{
|
||||
mW = w;
|
||||
mH = h;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Height (But Maintain Current Aspect Ratio)
|
||||
///
|
||||
void LabelModelObject::setHHonorAspect( double h )
|
||||
{
|
||||
double aspectRatio = mH / mW;
|
||||
double w = h / aspectRatio;
|
||||
|
||||
if ( ( mW != w ) || ( mH != h ) )
|
||||
{
|
||||
mW = w;
|
||||
mH = h;
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get Extent of Bounding Box
|
||||
///
|
||||
LabelRegion LabelModelObject::getExtent()
|
||||
{
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
QPointF a1( - lineWidth()/2, - lineWidth()/2 );
|
||||
QPointF a2( mW + lineWidth()/2, - lineWidth()/2 );
|
||||
QPointF a3( mW + lineWidth()/2, mH + lineWidth()/2 );
|
||||
QPointF a4( - lineWidth()/2, mH + lineWidth()/2 );
|
||||
|
||||
a1 = mMatrix.map( a1 );
|
||||
a2 = mMatrix.map( a2 );
|
||||
a3 = mMatrix.map( a3 );
|
||||
a4 = mMatrix.map( a4 );
|
||||
|
||||
LabelRegion region;
|
||||
region.setX1( min( a1.x(), min( a2.x(), min( a3.x(), a4.x() ) ) ) + mX0 );
|
||||
region.setY1( min( a1.y(), min( a2.y(), min( a3.y(), a4.y() ) ) ) + mY0 );
|
||||
region.setX2( max( a1.x(), max( a2.x(), max( a3.x(), a4.x() ) ) ) + mX0 );
|
||||
region.setY2( max( a1.y(), max( a2.y(), max( a3.y(), a4.y() ) ) ) + mY0 );
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Rotate Object
|
||||
///
|
||||
void LabelModelObject::rotate( double thetaDegs )
|
||||
{
|
||||
if ( thetaDegs != 0 )
|
||||
{
|
||||
mMatrix = mMatrix.rotate( thetaDegs );
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Flip Object Horizontally
|
||||
///
|
||||
void LabelModelObject::flipHoriz()
|
||||
{
|
||||
mMatrix = mMatrix.scale( -1, 1 );
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Flip Object Vertically
|
||||
///
|
||||
void LabelModelObject::flipVert()
|
||||
{
|
||||
mMatrix = mMatrix.scale( 1, -1 );
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update Representative Graphics Item with Object's Transformation Matrix
|
||||
///
|
||||
void LabelModelObject::updateGraphicsItemMatrix( QGraphicsItem* graphicsItem )
|
||||
{
|
||||
graphicsItem->setTransform( mMatrix );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update Representative Graphics Item with Object's Shadow Properties
|
||||
///
|
||||
void LabelModelObject::updateGraphicsItemShadow( QGraphicsItem* graphicsItem )
|
||||
{
|
||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
||||
|
||||
QColor color = mShadowColorNode.color();
|
||||
color.setAlphaF( mShadowOpacity );
|
||||
|
||||
shadowEffect->setColor( color );
|
||||
shadowEffect->setOffset( mShadowX, mShadowY );
|
||||
shadowEffect->setBlurRadius( 0 );
|
||||
|
||||
graphicsItem->setGraphicsEffect( shadowEffect );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,427 @@
|
||||
/* LabelModelObject.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_LabelModelObject_h
|
||||
#define glabels_LabelModelObject_h
|
||||
|
||||
#include <QObject>
|
||||
#include <QFont>
|
||||
#include <QTransform>
|
||||
|
||||
#include "ColorNode.h"
|
||||
#include "TextNode.h"
|
||||
#include "BarcodeStyle.h"
|
||||
|
||||
class QGraphicsItem;
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
// Forward References
|
||||
class LabelRegion;
|
||||
class MergeRecord;
|
||||
|
||||
|
||||
///
|
||||
/// Label Model Object Base Class
|
||||
///
|
||||
class LabelModelObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Lifecycle Methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
LabelModelObject( QObject *parent );
|
||||
virtual ~LabelModelObject();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Signals
|
||||
///////////////////////////////////////////////////////////////
|
||||
signals:
|
||||
void moved();
|
||||
void changed();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Common Properties
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// ID Property.
|
||||
//
|
||||
Q_PROPERTY( int id READ id )
|
||||
|
||||
int id() const;
|
||||
|
||||
//
|
||||
// Selected Property.
|
||||
//
|
||||
Q_PROPERTY( bool selected READ isSelected WRITE select RESET unselect )
|
||||
|
||||
bool isSelected() const;
|
||||
void select( bool value = true );
|
||||
void unselect();
|
||||
|
||||
|
||||
//
|
||||
// x0 Property ( x coordinate of origin )
|
||||
//
|
||||
Q_PROPERTY( double x0 READ x0 WRITE setX0 );
|
||||
|
||||
double x0() const;
|
||||
void setX0( double value );
|
||||
|
||||
|
||||
//
|
||||
// y0 Property ( y coordinate of origin )
|
||||
//
|
||||
Q_PROPERTY( double y0 READ y0 WRITE setY0 );
|
||||
|
||||
double y0() const;
|
||||
void setY0( double value );
|
||||
|
||||
|
||||
//
|
||||
// w Property ( width of bounding box )
|
||||
//
|
||||
Q_PROPERTY( double w READ w WRITE setW );
|
||||
|
||||
double w() const;
|
||||
void setW( double value );
|
||||
|
||||
|
||||
//
|
||||
// h Property ( height of bounding box )
|
||||
//
|
||||
Q_PROPERTY( double h READ h WRITE setH );
|
||||
|
||||
double h() const;
|
||||
void setH( double value );
|
||||
|
||||
|
||||
//
|
||||
// Transformation Matrix Property
|
||||
//
|
||||
Q_PROPERTY( QTransform matrix READ matrix WRITE setMatrix );
|
||||
|
||||
QTransform matrix() const;
|
||||
void setMatrix( const QTransform& value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow State Property
|
||||
//
|
||||
Q_PROPERTY( bool shadow READ shadow WRITE setShadow );
|
||||
|
||||
bool shadow() const;
|
||||
void setShadow( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow x Offset Property
|
||||
//
|
||||
Q_PROPERTY( double shadowX READ shadowX WRITE setShadowX );
|
||||
|
||||
double shadowX() const;
|
||||
void setShadowX( double value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow y Offset Property
|
||||
//
|
||||
Q_PROPERTY( double shadowY READ shadowY WRITE setShadowY );
|
||||
|
||||
double shadowY() const;
|
||||
void setShadowY( double value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow opacity Property
|
||||
//
|
||||
Q_PROPERTY( double shadowOpacity READ shadowOpacity WRITE setShadowOpacity );
|
||||
|
||||
double shadowOpacity() const;
|
||||
void setShadowOpacity( double value );
|
||||
|
||||
|
||||
//
|
||||
// Shadow Color Property
|
||||
//
|
||||
Q_PROPERTY( ColorNode shadowColorNode READ shadowColorNode WRITE setShadowColorNode );
|
||||
|
||||
ColorNode shadowColorNode() const;
|
||||
void setShadowColorNode( const ColorNode& value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Text Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Text Property: fontFamily
|
||||
//
|
||||
Q_PROPERTY( QString fontFamily READ fontFamily WRITE setFontFamily );
|
||||
|
||||
virtual QString fontFamily() const;
|
||||
virtual void setFontFamily( const QString &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontSize
|
||||
//
|
||||
Q_PROPERTY( double fontSize READ fontSize WRITE setFontSize );
|
||||
|
||||
virtual double fontSize() const;
|
||||
virtual void setFontSize( double value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontWeight
|
||||
//
|
||||
Q_PROPERTY( QFont::Weight fontWeight READ fontWeight WRITE setFontWeight );
|
||||
|
||||
virtual QFont::Weight fontWeight() const;
|
||||
virtual void setFontWeight( QFont::Weight value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontItalicFlag
|
||||
//
|
||||
Q_PROPERTY( bool fontItalicFlag READ fontItalicFlag WRITE setFontItalicFlag );
|
||||
|
||||
virtual bool fontItalicFlag() const;
|
||||
virtual void setFontItalicFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: fontUnderlineFlag
|
||||
//
|
||||
Q_PROPERTY( bool fontUnderlineFlag READ fontUnderlineFlag WRITE setFontUnderlineFlag );
|
||||
|
||||
virtual bool fontUnderlineFlag() const;
|
||||
virtual void setFontUnderlineFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textColorNode
|
||||
//
|
||||
Q_PROPERTY( ColorNode textColorNode READ textColorNode WRITE setTextColorNode );
|
||||
|
||||
virtual ColorNode textColorNode() const;
|
||||
virtual void setTextColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textHAlign
|
||||
//
|
||||
Q_PROPERTY( Qt::Alignment textHAlign READ textHAlign WRITE setTextHAlign );
|
||||
|
||||
virtual Qt::Alignment textHAlign() const;
|
||||
virtual void setTextHAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textVAlign
|
||||
//
|
||||
Q_PROPERTY( Qt::Alignment textVAlign READ textVAlign WRITE setTextVAlign );
|
||||
|
||||
virtual Qt::Alignment textVAlign() const;
|
||||
virtual void setTextVAlign( Qt::Alignment value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Text Property: textLineSpacing
|
||||
//
|
||||
Q_PROPERTY( double textLineSpacing READ textLineSpacing WRITE setTextLineSpacing );
|
||||
|
||||
virtual double textLineSpacing() const;
|
||||
virtual void setTextLineSpacing( double value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Image Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Image Property: filenameNode
|
||||
//
|
||||
Q_PROPERTY( TextNode filenameNode READ filenameNode WRITE setFilenameNode );
|
||||
|
||||
virtual TextNode filenameNode() const;
|
||||
virtual void setFilenameNode( const TextNode &value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Shape Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Shape Property: lineWidth
|
||||
//
|
||||
Q_PROPERTY( double lineWidth READ lineWidth WRITE setLineWidth );
|
||||
|
||||
virtual double lineWidth() const;
|
||||
virtual void setLineWidth( double value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: lineColorNode
|
||||
//
|
||||
Q_PROPERTY( ColorNode lineColorNode READ lineColorNode WRITE setLineColorNode );
|
||||
|
||||
virtual ColorNode lineColorNode() const;
|
||||
virtual void setLineColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Shape Property: fillColorNode
|
||||
//
|
||||
Q_PROPERTY( ColorNode fillColorNode READ fillColorNode WRITE setFillColorNode );
|
||||
|
||||
virtual ColorNode fillColorNode() const;
|
||||
virtual void setFillColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Barcode Properties Virtual Interface
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Virtual Barcode Property: bcDataNode
|
||||
//
|
||||
Q_PROPERTY( TextNode bcDataNode READ bcDataNode WRITE setBcDataNode );
|
||||
|
||||
virtual TextNode bcDataNode() const;
|
||||
virtual void setBcDataNode( const TextNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcTextFlag
|
||||
//
|
||||
Q_PROPERTY( bool bcTextFlag READ bcTextFlag WRITE setBcTextFlag );
|
||||
|
||||
virtual bool bcTextFlag() const;
|
||||
virtual void setBcTextFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcChecksumFlag
|
||||
//
|
||||
Q_PROPERTY( bool bcChecksumFlag READ bcChecksumFlag WRITE setBcChecksumFlag );
|
||||
|
||||
virtual bool bcChecksumFlag() const;
|
||||
virtual void setBcChecksumFlag( bool value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcColorNode
|
||||
//
|
||||
Q_PROPERTY( ColorNode bcColorNode READ bcColorNode WRITE setBcColorNode );
|
||||
|
||||
virtual ColorNode bcColorNode() const;
|
||||
virtual void setBcColorNode( const ColorNode &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcStyle
|
||||
//
|
||||
Q_PROPERTY( BarcodeStyle bcStyle READ bcStyle WRITE setBcStyle );
|
||||
|
||||
virtual BarcodeStyle bcStyle() const;
|
||||
virtual void setBcStyle( const BarcodeStyle &value );
|
||||
|
||||
|
||||
//
|
||||
// Virtual Barcode Property: bcFormatDigits
|
||||
//
|
||||
Q_PROPERTY( int bcFormatDigits READ bcFormatDigits WRITE setBcFormatDigits );
|
||||
|
||||
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;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Position and Size methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
void setPosition( double x0, double y0 );
|
||||
void setPositionRelative( double dx, double dy );
|
||||
void setSize( double w, double h );
|
||||
void setSizeHonorAspect( double w, double h );
|
||||
void setWHonorAspect( double w );
|
||||
void setHHonorAspect( double h );
|
||||
LabelRegion getExtent();
|
||||
void rotate( double thetaDegs );
|
||||
void flipHoriz();
|
||||
void flipVert();
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// QGraphicsItem methods
|
||||
///////////////////////////////////////////////////////////////
|
||||
public:
|
||||
virtual QGraphicsItem* createGraphicsItem() = 0;
|
||||
virtual void updateGraphicsItem( QGraphicsItem* graphicsItem ) = 0;
|
||||
|
||||
protected:
|
||||
void updateGraphicsItemMatrix( QGraphicsItem* graphicsItem );
|
||||
void updateGraphicsItemShadow( QGraphicsItem* graphicsItem );
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Private Members
|
||||
///////////////////////////////////////////////////////////////
|
||||
private:
|
||||
static int msNextId;
|
||||
int mId;
|
||||
|
||||
bool mSelectedFlag;
|
||||
|
||||
double mX0;
|
||||
double mY0;
|
||||
double mW;
|
||||
double mH;
|
||||
|
||||
QTransform mMatrix;
|
||||
|
||||
bool mShadowState;
|
||||
double mShadowX;
|
||||
double mShadowY;
|
||||
double mShadowOpacity;
|
||||
ColorNode mShadowColorNode;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_LabelModelObject_h
|
||||
@@ -0,0 +1,45 @@
|
||||
/* LabelRegion.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "LabelRegion.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
QRectF LabelRegion::rect() const
|
||||
{
|
||||
using std::min;
|
||||
using std::fabs;
|
||||
|
||||
QRectF r;
|
||||
|
||||
r.setX( min( mX1, mX2 ) );
|
||||
r.setY( min( mY1, mY2 ) );
|
||||
r.setWidth( fabs( mX2 - mX1 ) );
|
||||
r.setHeight( fabs( mY2 - mY1 ) );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/* LabelRegion.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_LabelRegion_h
|
||||
#define glabels_LabelRegion_h
|
||||
|
||||
#include <QRectF>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Label Region Type
|
||||
///
|
||||
struct LabelRegion
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// X1 Property
|
||||
//
|
||||
inline double x1( void ) const;
|
||||
inline void setX1( double value );
|
||||
|
||||
|
||||
//
|
||||
// Y1 Property
|
||||
//
|
||||
inline double y1( void ) const;
|
||||
inline void setY1( double value );
|
||||
|
||||
|
||||
//
|
||||
// X2 Property
|
||||
//
|
||||
inline double x2( void ) const;
|
||||
inline void setX2( double value );
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Y2 Property
|
||||
//
|
||||
inline double y2( void ) const;
|
||||
inline void setY2( double value );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Methods
|
||||
/////////////////////////////////
|
||||
public:
|
||||
QRectF rect() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
double mX1;
|
||||
double mY1;
|
||||
double mX2;
|
||||
double mY2;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// INLINE METHODS
|
||||
/////////////////////////////////
|
||||
double LabelRegion::x1( void ) const
|
||||
{
|
||||
return mX1;
|
||||
}
|
||||
|
||||
|
||||
void LabelRegion::setX1( double value )
|
||||
{
|
||||
mX1 = value;
|
||||
}
|
||||
|
||||
|
||||
double LabelRegion::y1( void ) const
|
||||
{
|
||||
return mY1;
|
||||
}
|
||||
|
||||
|
||||
void LabelRegion::setY1( double value )
|
||||
{
|
||||
mY1 = value;
|
||||
}
|
||||
|
||||
|
||||
double LabelRegion::x2( void ) const
|
||||
{
|
||||
return mX2;
|
||||
}
|
||||
|
||||
|
||||
void LabelRegion::setX2( double value )
|
||||
{
|
||||
mX2 = value;
|
||||
}
|
||||
|
||||
|
||||
double LabelRegion::y2( void ) const
|
||||
{
|
||||
return mY2;
|
||||
}
|
||||
|
||||
|
||||
void LabelRegion::setY2( double value )
|
||||
{
|
||||
mY2 = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_LabelRegion_h
|
||||
@@ -0,0 +1,234 @@
|
||||
/* MainWindow.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_MainWindow_h
|
||||
#define glabels_MainWindow_h
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
class QAction;
|
||||
class QCloseEvent;
|
||||
class QMenuBar;
|
||||
class QMenu;
|
||||
class QToolBar;
|
||||
class QLabel;
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
// Forward References
|
||||
class View;
|
||||
|
||||
|
||||
///
|
||||
/// MainWindow Widget
|
||||
///
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Lifecycle
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
MainWindow();
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Events
|
||||
/////////////////////////////////////
|
||||
protected:
|
||||
void closeEvent( QCloseEvent *event );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////////
|
||||
private slots:
|
||||
void fileNew();
|
||||
void fileOpen();
|
||||
void fileSave();
|
||||
void fileSaveAs();
|
||||
void filePrint();
|
||||
void fileProperties();
|
||||
void fileTemplateDesigner();
|
||||
void fileClose();
|
||||
void fileExit();
|
||||
|
||||
void editUndo();
|
||||
void editRedo();
|
||||
void editCut();
|
||||
void editCopy();
|
||||
void editPaste();
|
||||
void editDelete();
|
||||
void editSelectAll();
|
||||
void editUnSelectAll();
|
||||
void editPreferences();
|
||||
|
||||
void viewFileToolBar( bool );
|
||||
void viewObjectsToolBar( bool );
|
||||
void viewEditToolBar( bool );
|
||||
void viewViewToolBar( 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 objectsMergeProperties();
|
||||
|
||||
void helpContents();
|
||||
void helpAbout();
|
||||
|
||||
void updateZoomInfo();
|
||||
void updateCursorInfo();
|
||||
void updateCursorInfo( double, double );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Internal Private Methods
|
||||
/////////////////////////////////////
|
||||
private:
|
||||
void createActions();
|
||||
void createMenus();
|
||||
void createToolBars();
|
||||
void createStatusBar();
|
||||
|
||||
void setDocVerbsEnabled( bool );
|
||||
void setDocModifiedVerbsEnabled( bool );
|
||||
void setPasteVerbsEnabled( bool );
|
||||
void setSelectionVerbsEnabled( bool );
|
||||
void setMultiSelectionVerbsEnabled( bool );
|
||||
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// 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;
|
||||
|
||||
QToolBar* fileToolBar;
|
||||
QToolBar* objectsToolBar;
|
||||
QToolBar* editToolBar;
|
||||
QToolBar* viewToolBar;
|
||||
|
||||
View* view;
|
||||
|
||||
QLabel* zoomInfoLabel;
|
||||
QLabel* cursorInfoLabel;
|
||||
|
||||
QAction* fileNewAction;
|
||||
QAction* fileOpenAction;
|
||||
QAction* fileSaveAction;
|
||||
QAction* fileSaveAsAction;
|
||||
QAction* filePrintAction;
|
||||
QAction* filePropertiesAction;
|
||||
QAction* fileTemplateDesignerAction;
|
||||
QAction* fileCloseAction;
|
||||
QAction* fileExitAction;
|
||||
|
||||
QAction* editUndoAction;
|
||||
QAction* editRedoAction;
|
||||
QAction* editCutAction;
|
||||
QAction* editCopyAction;
|
||||
QAction* editPasteAction;
|
||||
QAction* editDeleteAction;
|
||||
QAction* editSelectAllAction;
|
||||
QAction* editUnSelectAllAction;
|
||||
QAction* editPreferencesAction;
|
||||
|
||||
QAction* viewFileToolBarAction;
|
||||
QAction* viewObjectsToolBarAction;
|
||||
QAction* viewEditToolBarAction;
|
||||
QAction* viewViewToolBarAction;
|
||||
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* objectsMergePropertiesAction;
|
||||
|
||||
QAction* helpContentsAction;
|
||||
QAction* helpAboutAction;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_MainWindow_h
|
||||
@@ -0,0 +1,21 @@
|
||||
/* MergeField.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MergeField.h"
|
||||
@@ -0,0 +1,92 @@
|
||||
/* MergeField.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_MergeField_h
|
||||
#define glabels_MergeField_h
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Merge Field Structure
|
||||
///
|
||||
struct MergeField
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Key Property
|
||||
//
|
||||
inline const QString key( void ) const;
|
||||
inline void setKey( const QString &value );
|
||||
|
||||
|
||||
//
|
||||
// Value Property
|
||||
//
|
||||
inline const QString value( void ) const;
|
||||
inline void setValue( const QString &value );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
QString mKey;
|
||||
QString mValue;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// INLINE METHODS
|
||||
/////////////////////////////////
|
||||
const QString MergeField::key( void ) const
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
|
||||
|
||||
void MergeField::setKey( const QString &value )
|
||||
{
|
||||
mKey = value;
|
||||
}
|
||||
|
||||
|
||||
const QString MergeField::value( void ) const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
|
||||
void MergeField::setValue( const QString &value )
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_MergeField_h
|
||||
@@ -0,0 +1,36 @@
|
||||
/* MergeRecord.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MergeRecord.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
MergeRecord::MergeRecord() : mSelected( false )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/* MergeRecord.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_MergeRecord_h
|
||||
#define glabels_MergeRecord_h
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
|
||||
#include "MergeField.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Merge Record Structure
|
||||
///
|
||||
struct MergeRecord
|
||||
{
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
MergeRecord();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
inline bool selected( void ) const;
|
||||
inline void setSelected( bool value );
|
||||
|
||||
inline const QList<MergeField>& fieldList( void ) const;
|
||||
inline void setFieldList( QList<MergeField>& value );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
bool mSelected;
|
||||
QList<MergeField> mFieldList;
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// INLINE METHODS
|
||||
/////////////////////////////////
|
||||
bool MergeRecord::selected( void ) const
|
||||
{
|
||||
return mSelected;
|
||||
}
|
||||
|
||||
|
||||
void MergeRecord::setSelected( bool value )
|
||||
{
|
||||
mSelected = value;
|
||||
}
|
||||
|
||||
|
||||
const QList<MergeField>& MergeRecord::fieldList( void ) const
|
||||
{
|
||||
return mFieldList;
|
||||
}
|
||||
|
||||
|
||||
void MergeRecord::setFieldList( QList<MergeField>& value )
|
||||
{
|
||||
mFieldList = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_MergeRecord_h
|
||||
@@ -0,0 +1,205 @@
|
||||
/* NewLabelDialog.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "NewLabelDialog.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "libglabels/Db.h"
|
||||
#include "TemplatePickerItem.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
NewLabelDialog::NewLabelDialog( QWidget *parent = 0 )
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
// TODO: Set default based on locale
|
||||
pageSizeIsoRadio->setChecked( true );
|
||||
|
||||
QList<libglabels::Template*> tmplates = libglabels::Db::templates();
|
||||
templatePicker->setTemplates( tmplates );
|
||||
|
||||
templatePicker->applyFilter( searchEntry->text(),
|
||||
pageSizeIsoRadio->isChecked(),
|
||||
pageSizeUsRadio->isChecked(),
|
||||
pageSizeOtherRadio->isChecked() );
|
||||
|
||||
similarBrowser->setAttribute(Qt::WA_TranslucentBackground);
|
||||
similarBrowser->viewport()->setAutoFillBackground(false);
|
||||
|
||||
selectionStackedWidget->setCurrentIndex( 0 );
|
||||
|
||||
connect( searchEntry, SIGNAL(textChanged(const QString &)),
|
||||
this, SLOT(searchEntryTextChanged(const QString &)) );
|
||||
|
||||
connect( pageSizeIsoRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) );
|
||||
connect( pageSizeUsRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) );
|
||||
connect( pageSizeOtherRadio, SIGNAL(toggled(bool)), this, SLOT(pageSizeRadioToggled(bool)) );
|
||||
|
||||
connect( templatePicker, SIGNAL(itemSelectionChanged()), this, SLOT(templatePickerSelectionChanged()) );
|
||||
|
||||
connect( orientationNormalRadio, SIGNAL(toggled(bool)), this, SLOT(orientationRadioToggled(bool)) );
|
||||
connect( orientationRotatedRadio, SIGNAL(toggled(bool)), this, SLOT(orientationRadioToggled(bool)) );
|
||||
|
||||
connect( cancelButton, SIGNAL(clicked()), this, SLOT(close()) );
|
||||
connect( createButton, SIGNAL(clicked()), this, SLOT(createButtonClicked()) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Search Entry Text Changed Slot
|
||||
///
|
||||
void NewLabelDialog::searchEntryTextChanged( const QString &text )
|
||||
{
|
||||
templatePicker->applyFilter( text,
|
||||
pageSizeIsoRadio->isChecked(),
|
||||
pageSizeUsRadio->isChecked(),
|
||||
pageSizeOtherRadio->isChecked() );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Page Size Radio Toggled Slot
|
||||
///
|
||||
void NewLabelDialog::pageSizeRadioToggled( bool checked )
|
||||
{
|
||||
if ( checked )
|
||||
{
|
||||
templatePicker->applyFilter( searchEntry->text(),
|
||||
pageSizeIsoRadio->isChecked(),
|
||||
pageSizeUsRadio->isChecked(),
|
||||
pageSizeOtherRadio->isChecked() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Template Picker Selection Changed Slot
|
||||
///
|
||||
void NewLabelDialog::templatePickerSelectionChanged()
|
||||
{
|
||||
orientationNormalRadio->setChecked( true );
|
||||
|
||||
const libglabels::Template *tmplate = templatePicker->selectedTemplate();
|
||||
|
||||
if ( tmplate == NULL )
|
||||
{
|
||||
createButton->setEnabled( false );
|
||||
selectionStackedWidget->setCurrentIndex( 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
createButton->setEnabled( true );
|
||||
selectionStackedWidget->setCurrentIndex( 1 );
|
||||
|
||||
const libglabels::Frame *frame = tmplate->frames().first();
|
||||
|
||||
simplePreview->setTemplate( tmplate );
|
||||
simplePreview->setRotate( false );
|
||||
|
||||
const libglabels::Vendor *vendor = libglabels::Db::lookupVendorFromName( tmplate->brand() );
|
||||
if ( (vendor != NULL) && (vendor->url() != NULL) )
|
||||
{
|
||||
QString markup = "<a href='" + vendor->url() + "'>" + vendor->name() + "</a>";
|
||||
vendorLabel->setText( markup );
|
||||
}
|
||||
else
|
||||
{
|
||||
vendorLabel->setText( tmplate->brand() );
|
||||
}
|
||||
|
||||
if ( tmplate->productUrl() != NULL )
|
||||
{
|
||||
QString markup = "<a href='" + tmplate->productUrl() + "'>" + tmplate->part() + "</a>";
|
||||
partLabel->setText( markup );
|
||||
}
|
||||
else
|
||||
{
|
||||
partLabel->setText( tmplate->part() );
|
||||
}
|
||||
|
||||
descriptionLabel->setText( tmplate->description() );
|
||||
|
||||
QString pgSizeString = libglabels::Db::lookupPaperNameFromId( tmplate->paperId() );
|
||||
pageSizeLabel->setText( pgSizeString );
|
||||
|
||||
QString labelSizeString = frame->sizeDescription( libglabels::Units::inch() );
|
||||
labelSizeLabel->setText( labelSizeString );
|
||||
|
||||
QString layoutString = frame->layoutDescription();
|
||||
layoutLabel->setText( layoutString );
|
||||
|
||||
QStringList list = libglabels::Db::getNameListOfSimilarTemplates( tmplate->name() );
|
||||
if ( list.isEmpty() )
|
||||
{
|
||||
similarLabel->hide();
|
||||
similarBrowser->hide();
|
||||
}
|
||||
else
|
||||
{
|
||||
similarLabel->show();
|
||||
similarBrowser->show();
|
||||
|
||||
QString similarListString;
|
||||
foreach ( QString name, list )
|
||||
{
|
||||
similarListString += name + "\n";
|
||||
}
|
||||
similarBrowser->setText( similarListString );
|
||||
}
|
||||
|
||||
orientationGroupBox->setEnabled( frame->w() != frame->h() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Orientation Radio Button Toggled Slot
|
||||
///
|
||||
void NewLabelDialog::orientationRadioToggled( bool checked )
|
||||
{
|
||||
if ( checked )
|
||||
{
|
||||
simplePreview->setRotate( orientationRotatedRadio->isChecked() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Create Button Clicked Slot
|
||||
///
|
||||
void NewLabelDialog::createButtonClicked()
|
||||
{
|
||||
const libglabels::Template *tmplate = templatePicker->selectedTemplate();
|
||||
|
||||
std::cout << "TODO: create new label, template = '" << qPrintable(tmplate->name())
|
||||
<< "', rotate = " << orientationRotatedRadio->isChecked()
|
||||
<< std::endl;
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/* NewLabelDialog.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_NewLabelDialog_h
|
||||
#define glabels_NewLabelDialog_h
|
||||
|
||||
#include "ui_NewLabelDialog.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// New Label Dialog Widget
|
||||
///
|
||||
class NewLabelDialog : public QDialog, public Ui_NewLabelDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
NewLabelDialog( QWidget *parent );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Slots
|
||||
/////////////////////////////////
|
||||
private slots:
|
||||
void searchEntryTextChanged( const QString &text );
|
||||
void pageSizeRadioToggled( bool checked );
|
||||
void templatePickerSelectionChanged();
|
||||
void orientationRadioToggled( bool checked );
|
||||
void createButtonClicked();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_NewLabelDialog_h
|
||||
@@ -0,0 +1,246 @@
|
||||
/* SimplePreview.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "SimplePreview.h"
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
//
|
||||
// Private Configuration Data
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const QColor paperColor( 255, 255, 255 );
|
||||
const QColor paperOutlineColor( 0, 0, 0 );
|
||||
const double paperOutlineWidthPixels = 1;
|
||||
|
||||
const QColor shadowColor( 64, 64, 64 );
|
||||
const double shadowOffsetPixels = 3;
|
||||
const double shadowRadiusPixels = 12;
|
||||
|
||||
const QColor labelColor( 255, 255, 255 );
|
||||
const QColor labelOutlineColor( 128, 128, 255 );
|
||||
const double labelOutlineWidthPixels = 2;
|
||||
|
||||
const QColor arrowColor( 192, 192, 255, 128 );
|
||||
const double arrowScale = 0.35;
|
||||
|
||||
const QColor upColor( 192, 192, 255, 128 );
|
||||
const double upScale = 0.15;
|
||||
const QString upFontFamily( "Sans" );
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
SimplePreview::SimplePreview( QWidget *parent = 0 )
|
||||
: mScale(1), mTmplate(NULL), mRotateFlag(false), QGraphicsView(parent)
|
||||
{
|
||||
mScene = new QGraphicsScene();
|
||||
setScene( mScene );
|
||||
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
viewport()->setAutoFillBackground(false);
|
||||
|
||||
setFrameStyle( QFrame::NoFrame );
|
||||
setRenderHints( QPainter::Antialiasing );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Template Property Setter
|
||||
///
|
||||
void SimplePreview::setTemplate( const libglabels::Template *tmplate )
|
||||
{
|
||||
mTmplate = tmplate;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Rotate Property Setter
|
||||
///
|
||||
void SimplePreview::setRotate( bool rotateFlag )
|
||||
{
|
||||
mRotateFlag = rotateFlag;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Update View
|
||||
///
|
||||
void SimplePreview::update()
|
||||
{
|
||||
clearScene();
|
||||
|
||||
if ( mTmplate != NULL )
|
||||
{
|
||||
// Set scene up with a 5% margin around paper
|
||||
double x = -0.05 * mTmplate->pageWidth();
|
||||
double y = -0.05 * mTmplate->pageHeight();
|
||||
double w = 1.10 * mTmplate->pageWidth();
|
||||
double h = 1.10 * mTmplate->pageHeight();
|
||||
|
||||
mScene->setSceneRect( x, y, w, h );
|
||||
fitInView( x, y, w, h, Qt::KeepAspectRatio );
|
||||
|
||||
mScale = matrix().m11();
|
||||
|
||||
drawPaper( mTmplate->pageWidth(), mTmplate->pageHeight() );
|
||||
drawLabels();
|
||||
drawArrow();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clear View
|
||||
///
|
||||
void SimplePreview::clearScene()
|
||||
{
|
||||
foreach ( QGraphicsItem *item, mScene->items() )
|
||||
{
|
||||
mScene->removeItem( item );
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Paper
|
||||
///
|
||||
void SimplePreview::drawPaper( double pw, double ph )
|
||||
{
|
||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
||||
shadowEffect->setColor( shadowColor );
|
||||
shadowEffect->setOffset( shadowOffsetPixels );
|
||||
shadowEffect->setBlurRadius( shadowRadiusPixels );
|
||||
|
||||
QBrush brush( paperColor );
|
||||
QPen pen( paperOutlineColor );
|
||||
pen.setWidthF( paperOutlineWidthPixels / mScale );
|
||||
|
||||
QGraphicsRectItem *pageItem = new QGraphicsRectItem( 0, 0, pw, ph );
|
||||
pageItem->setBrush( brush );
|
||||
pageItem->setPen( pen );
|
||||
pageItem->setGraphicsEffect( shadowEffect );
|
||||
|
||||
mScene->addItem( pageItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Labels on Paper
|
||||
///
|
||||
void SimplePreview::drawLabels()
|
||||
{
|
||||
libglabels::Frame *frame = mTmplate->frames().first();
|
||||
|
||||
foreach (libglabels::Point origin, frame->getOrigins() )
|
||||
{
|
||||
drawLabel( origin.x(), origin.y(), frame->path() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw a Single Label at x,y
|
||||
///
|
||||
void SimplePreview::drawLabel( double x, double y, const QPainterPath &path )
|
||||
{
|
||||
QBrush brush( labelColor );
|
||||
QPen pen( labelOutlineColor );
|
||||
pen.setWidthF( labelOutlineWidthPixels / mScale );
|
||||
|
||||
QGraphicsPathItem *labelItem = new QGraphicsPathItem( path );
|
||||
labelItem->setBrush( brush );
|
||||
labelItem->setPen( pen );
|
||||
labelItem->setPos( x, y );
|
||||
|
||||
mScene->addItem( labelItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Draw Arrow Indicating Top of First Label
|
||||
///
|
||||
void SimplePreview::drawArrow()
|
||||
{
|
||||
libglabels::Frame *frame = mTmplate->frames().first();
|
||||
|
||||
double w = frame->w();
|
||||
double h = frame->h();
|
||||
|
||||
double min = ( w < h ) ? w : h;
|
||||
|
||||
QPen pen( arrowColor );
|
||||
pen.setWidthF( 0.25*min*arrowScale );
|
||||
pen.setCapStyle( Qt::FlatCap );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
|
||||
QBrush brush( upColor );
|
||||
|
||||
libglabels::Point origin = frame->getOrigins().first();
|
||||
double x0 = origin.x();
|
||||
double y0 = origin.y();
|
||||
|
||||
QPainterPath path;
|
||||
path.moveTo( 0, min*arrowScale/3 );
|
||||
path.lineTo( 0, -min*arrowScale );
|
||||
path.moveTo( -min*arrowScale/2, -min*arrowScale/2 );
|
||||
path.lineTo( 0, -min*arrowScale );
|
||||
path.lineTo( min*arrowScale/2, -min*arrowScale/2 );
|
||||
|
||||
QGraphicsPathItem *arrowItem = new QGraphicsPathItem( path );
|
||||
arrowItem->setPen( pen );
|
||||
arrowItem->setPos( x0+w/2, y0+h/2 );
|
||||
if ( mRotateFlag )
|
||||
{
|
||||
arrowItem->setRotation( 90 );
|
||||
}
|
||||
|
||||
QGraphicsSimpleTextItem *upItem = new QGraphicsSimpleTextItem( tr("Up") );
|
||||
upItem->setBrush( brush );
|
||||
upItem->setFont( QFont( upFontFamily, min*upScale, QFont::Bold ) );
|
||||
upItem->setPos( x0+w/2, y0+h/2 );
|
||||
QRectF rect = upItem->boundingRect();
|
||||
if ( mRotateFlag )
|
||||
{
|
||||
upItem->setPos( upItem->x()-min/8, upItem->y()-rect.width()/2 );
|
||||
upItem->setRotation( 90 );
|
||||
}
|
||||
else
|
||||
{
|
||||
upItem->setPos( upItem->x()-rect.width()/2, upItem->y()+min/8 );
|
||||
}
|
||||
|
||||
mScene->addItem( arrowItem );
|
||||
mScene->addItem( upItem );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
/* SimplePreview.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_SimplePreview_h
|
||||
#define glabels_SimplePreview_h
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QGraphicsScene>
|
||||
|
||||
#include <QList>
|
||||
|
||||
#include "libglabels/Template.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Simple Preview Widget
|
||||
///
|
||||
class SimplePreview : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
SimplePreview( QWidget *parent );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void setTemplate( const libglabels::Template *tmplate );
|
||||
void setRotate( bool rotateFlag );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Internal Methods
|
||||
/////////////////////////////////
|
||||
private:
|
||||
void update();
|
||||
void clearScene();
|
||||
void drawPaper( double pw, double ph );
|
||||
void drawLabels();
|
||||
void drawLabel( double x, double y, const QPainterPath &path );
|
||||
void drawArrow();
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
const libglabels::Template *mTmplate;
|
||||
bool mRotateFlag;
|
||||
|
||||
QGraphicsScene *mScene;
|
||||
double mScale;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_SimplePreview_h
|
||||
@@ -0,0 +1,102 @@
|
||||
/* TemplatePicker.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TemplatePicker.h"
|
||||
|
||||
#include <QIcon>
|
||||
|
||||
#include "TemplatePickerItem.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TemplatePicker::TemplatePicker( QWidget *parent ) : QListWidget(parent)
|
||||
{
|
||||
setViewMode( QListView::IconMode );
|
||||
setResizeMode( QListView::Adjust );
|
||||
setSpacing( 24 );
|
||||
setWordWrap( true );
|
||||
setUniformItemSizes( true );
|
||||
setIconSize( QSize(libglabels::TEMPLATE_PREVIEW_SIZE, libglabels::TEMPLATE_PREVIEW_SIZE) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set List of Templates to Pick From
|
||||
///
|
||||
void TemplatePicker::setTemplates( const QList <libglabels::Template*> &tmplates )
|
||||
{
|
||||
foreach (libglabels::Template *tmplate, tmplates)
|
||||
{
|
||||
TemplatePickerItem *item = new TemplatePickerItem( tmplate, this );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Apply Filter to Narrow Template Choices
|
||||
///
|
||||
void TemplatePicker::applyFilter( const QString &searchString,
|
||||
bool isoMask, bool usMask, bool otherMask )
|
||||
{
|
||||
foreach ( QListWidgetItem *item, findItems( "*", Qt::MatchWildcard ) )
|
||||
{
|
||||
TemplatePickerItem *tItem = dynamic_cast<TemplatePickerItem *>(item);
|
||||
|
||||
if ( tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ) &&
|
||||
(isoMask == tItem->tmplate()->isSizeIso()) &&
|
||||
(usMask == tItem->tmplate()->isSizeUs()) &&
|
||||
(otherMask == tItem->tmplate()->isSizeOther()) )
|
||||
{
|
||||
item->setHidden( false );
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
item->setHidden( true );
|
||||
item->setSelected( false );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Get Currently Selected Template
|
||||
///
|
||||
const libglabels::Template *TemplatePicker::selectedTemplate()
|
||||
{
|
||||
QList<QListWidgetItem *> items = selectedItems();
|
||||
if ( items.isEmpty() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
TemplatePickerItem *tItem = dynamic_cast<TemplatePickerItem*>(items.first());
|
||||
return tItem->tmplate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/* TemplatePicker.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_TemplatePicker_h
|
||||
#define glabels_TemplatePicker_h
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
#include <QList>
|
||||
|
||||
#include "libglabels/Template.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Template Picker Widget
|
||||
///
|
||||
class TemplatePicker : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TemplatePicker( QWidget *parent = 0 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
void setTemplates( const QList <libglabels::Template*> &tmplates );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Methods
|
||||
/////////////////////////////////
|
||||
void applyFilter( const QString &searchString, bool isoMask, bool usMask, bool otherMask );
|
||||
|
||||
const libglabels::Template *selectedTemplate();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_TemplatePicker_h
|
||||
@@ -0,0 +1,56 @@
|
||||
/* TemplatePickerItem.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TemplatePickerItem.h"
|
||||
|
||||
#include <QListWidgetItem>
|
||||
#include <QIcon>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
TemplatePickerItem::TemplatePickerItem( libglabels::Template *tmplate,
|
||||
QListWidget *parent )
|
||||
: QListWidgetItem(parent)
|
||||
{
|
||||
mTmplate = tmplate;
|
||||
|
||||
setIcon( QIcon(tmplate->preview()) );
|
||||
setText( tmplate->name() );
|
||||
|
||||
setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Template Property Getter
|
||||
///
|
||||
const libglabels::Template *TemplatePickerItem::tmplate() const
|
||||
{
|
||||
return mTmplate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/* TemplatePickerItem.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_TemplatePickerItem_h
|
||||
#define glabels_TemplatePickerItem_h
|
||||
|
||||
#include <QListWidget>
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
#include "libglabels/Template.h"
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Template Picker Item Widget
|
||||
///
|
||||
class TemplatePickerItem : public QListWidgetItem
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TemplatePickerItem( libglabels::Template *tmplate, QListWidget *parent = 0 );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
const libglabels::Template *tmplate() const;
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
libglabels::Template *mTmplate;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_TemplatePickerItem_h
|
||||
@@ -0,0 +1,290 @@
|
||||
/* TextNode.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "TextNode.h"
|
||||
|
||||
|
||||
namespace {
|
||||
typedef enum {
|
||||
START,
|
||||
LITERAL,
|
||||
LITERAL_DOLLAR,
|
||||
START_DOLLAR,
|
||||
FIELD,
|
||||
DONE
|
||||
} State;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Default Constructor
|
||||
///
|
||||
TextNode::TextNode()
|
||||
: mFieldFlag(false), mData("")
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor from Data
|
||||
///
|
||||
TextNode::TextNode( bool field_flag, const QString &data )
|
||||
: mFieldFlag(field_flag), mData(data)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Constructor from Parsing Next Token in Text
|
||||
///
|
||||
TextNode::TextNode( const QString &text, int i_start, int &i_next )
|
||||
{
|
||||
State state = START;
|
||||
QString literal_text;
|
||||
QString field_name;
|
||||
bool field_flag = false;
|
||||
|
||||
int i = i_start;
|
||||
|
||||
while ( state != DONE )
|
||||
{
|
||||
QChar c = text[i];
|
||||
|
||||
switch (state) {
|
||||
|
||||
case START:
|
||||
switch (c.unicode()) {
|
||||
case '$':
|
||||
/* May be start of a field node. */
|
||||
i++;
|
||||
state = START_DOLLAR;
|
||||
break;
|
||||
case '\n':
|
||||
state = DONE;
|
||||
break;
|
||||
case 0:
|
||||
state = DONE;
|
||||
break;
|
||||
default:
|
||||
/* Start a literal text node. */
|
||||
literal_text.append( c );
|
||||
i++;
|
||||
state = LITERAL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LITERAL:
|
||||
switch (c.unicode()) {
|
||||
case '$':
|
||||
/* May be the beginning of a field node. */
|
||||
i++;
|
||||
state = LITERAL_DOLLAR;
|
||||
break;
|
||||
case '\n':
|
||||
state = DONE;
|
||||
break;
|
||||
case 0:
|
||||
state = DONE;
|
||||
break;
|
||||
default:
|
||||
literal_text.append( c );
|
||||
i++;
|
||||
state = LITERAL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case LITERAL_DOLLAR:
|
||||
switch (c.unicode()) {
|
||||
case '{':
|
||||
/* "${" indicates the start of a new field node, gather for literal too. */
|
||||
literal_text.append( '$' );
|
||||
i++;
|
||||
state = DONE;
|
||||
break;
|
||||
case '\n':
|
||||
/* Append "$" to literal text, don't gather newline. */
|
||||
literal_text.append( '$' );
|
||||
i++;
|
||||
state = DONE;
|
||||
break;
|
||||
case 0:
|
||||
/* Append "$" to literal text, don't gather null. */
|
||||
literal_text.append( '$' );
|
||||
i++;
|
||||
state = DONE;
|
||||
break;
|
||||
default:
|
||||
/* Append "$" to literal text, gather this character too. */
|
||||
literal_text.append( '$' );
|
||||
literal_text.append( c );
|
||||
i+=2;
|
||||
state = LITERAL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case START_DOLLAR:
|
||||
switch (c.unicode()) {
|
||||
case '{':
|
||||
/* This is probably the begining of a field node, gather for literal too. */
|
||||
literal_text.append( c );
|
||||
i++;
|
||||
state = FIELD;
|
||||
break;
|
||||
case '\n':
|
||||
state = DONE;
|
||||
break;
|
||||
case 0:
|
||||
state = DONE;
|
||||
break;
|
||||
default:
|
||||
/* The "$" was literal. */
|
||||
literal_text.append( c );
|
||||
i++;
|
||||
state = LITERAL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case FIELD:
|
||||
switch (c.unicode()) {
|
||||
case '}':
|
||||
/* We now finally know that this node is really field node. */
|
||||
field_flag = true;
|
||||
i++;
|
||||
state = DONE;
|
||||
break;
|
||||
case '\n':
|
||||
state = DONE;
|
||||
break;
|
||||
case 0:
|
||||
state = DONE;
|
||||
break;
|
||||
default:
|
||||
/* Gather for field name and literal, just in case. */
|
||||
field_name.append( c );
|
||||
literal_text.append( c );
|
||||
i++;
|
||||
state = FIELD;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mFieldFlag = field_flag;
|
||||
mData = field_flag ? field_name : literal_text;
|
||||
|
||||
i_next = i;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// == Operator
|
||||
///
|
||||
bool TextNode::operator==( const TextNode& other )
|
||||
{
|
||||
return ( (mFieldFlag == other.mFieldFlag) &&
|
||||
(mData == other.mData) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// != Operator
|
||||
///
|
||||
bool TextNode::operator!=( const TextNode& other )
|
||||
{
|
||||
return ( (mFieldFlag != other.mFieldFlag) ||
|
||||
(mData != other.mData) );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Field Flag Property Getter
|
||||
///
|
||||
bool TextNode::fieldFlag( void ) const
|
||||
{
|
||||
return mFieldFlag;
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Data Property Getter
|
||||
///
|
||||
const QString& TextNode::data( void ) const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
|
||||
#if TODO
|
||||
public string expand( MergeRecord? record )
|
||||
{
|
||||
if ( field_flag )
|
||||
{
|
||||
|
||||
if ( record == null )
|
||||
{
|
||||
return "${%s}".printf( data );
|
||||
}
|
||||
else
|
||||
{
|
||||
string? text = record.eval_key( data );
|
||||
if ( text != null )
|
||||
{
|
||||
return text;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool is_empty_field( MergeRecord? record )
|
||||
{
|
||||
if ( (record !=null) && field_flag )
|
||||
{
|
||||
string? text = record.eval_key( data );
|
||||
return ( (text == null) || (text == "") );
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/* TextNode.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_TextNode_h
|
||||
#define glabels_TextNode_h
|
||||
|
||||
#include <QString>
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Text Node Type
|
||||
///
|
||||
struct TextNode
|
||||
{
|
||||
|
||||
/////////////////////////////////
|
||||
// Life Cycle
|
||||
/////////////////////////////////
|
||||
public:
|
||||
TextNode();
|
||||
|
||||
TextNode( bool field_flag, const QString &data );
|
||||
|
||||
TextNode( const QString &text, int i_start, int &i_next );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Operators
|
||||
/////////////////////////////////
|
||||
public:
|
||||
bool operator==( const TextNode& other );
|
||||
|
||||
bool operator!=( const TextNode& other );
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Properties
|
||||
/////////////////////////////////
|
||||
public:
|
||||
//
|
||||
// Field Flag Property
|
||||
//
|
||||
bool fieldFlag( void ) const;
|
||||
|
||||
//
|
||||
// Data Property
|
||||
//
|
||||
const QString& data( void ) const;
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Methods
|
||||
/////////////////////////////////
|
||||
#if TODO
|
||||
string expand( MergeRecord? record );
|
||||
bool is_empty_field( MergeRecord? record );
|
||||
#endif
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// Private Data
|
||||
/////////////////////////////////
|
||||
private:
|
||||
|
||||
bool mFieldFlag;
|
||||
QString mData;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // glabels_TextNode_h
|
||||
@@ -0,0 +1,535 @@
|
||||
/* View.cpp
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "View.h"
|
||||
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsItemGroup>
|
||||
#include <QMouseEvent>
|
||||
#include <QGraphicsLineItem>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
#include "LabelModel.h"
|
||||
#include "LabelModelObject.h"
|
||||
|
||||
#include "libglabels/Markup.h"
|
||||
#include "libglabels/FrameRect.h"
|
||||
#include "libglabels/FrameRound.h"
|
||||
#include "libglabels/FrameEllipse.h"
|
||||
#include "libglabels/FrameCd.h"
|
||||
|
||||
|
||||
//
|
||||
// Private Configuration Data
|
||||
//
|
||||
namespace
|
||||
{
|
||||
const int nZoomLevels = 14;
|
||||
const double zoomLevels[nZoomLevels] = { 8, 6, 4, 3, 2, 1.5, 1, 0.75, 0.67, 0.50, 0.33, 0.25, 0.15, 0.10 };
|
||||
|
||||
const double ZOOM_TO_FIT_PAD = 16.0;
|
||||
|
||||
const QColor shadowColor( 64, 64, 64 );
|
||||
const double shadowOffsetPixels = 3;
|
||||
const double shadowRadiusPixels = 12;
|
||||
|
||||
const QColor labelColor( 255, 255, 255 );
|
||||
const QColor labelOutlineColor( 0, 0, 0 );
|
||||
const double labelOutlineWidthPixels = 1;
|
||||
|
||||
const QColor gridLineColor( 192, 192, 192 );
|
||||
const double gridLineWidthPixels = 1;
|
||||
const double gridSpacing = 9; // TODO: determine from locale.
|
||||
|
||||
const QColor markupLineColor( 240, 99, 99 );
|
||||
const double markupLineWidthPixels = 1;
|
||||
|
||||
const QColor selectRegionFillColor( 192, 192, 255, 128 );
|
||||
const QColor selectRegionOutlineColor( 0, 0, 255, 128 );
|
||||
const double selectRegionOutlineWidthPixels = 3;
|
||||
}
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
|
||||
///
|
||||
/// Constructor
|
||||
///
|
||||
View::View( QWidget *parent ) : QGraphicsView(parent)
|
||||
{
|
||||
mState = IdleState;
|
||||
|
||||
setZoomReal( 1, false );
|
||||
mModel = 0;
|
||||
|
||||
setMouseTracking( true );
|
||||
|
||||
setAttribute( Qt::WA_TranslucentBackground );
|
||||
viewport()->setAutoFillBackground( false );
|
||||
|
||||
mScene = new QGraphicsScene();
|
||||
setScene( mScene );
|
||||
|
||||
mScene->addItem( mLabelLayer = new QGraphicsItemGroup() );
|
||||
mScene->addItem( mGridLayer = new QGraphicsItemGroup() );
|
||||
mScene->addItem( mMarkupLayer = new QGraphicsItemGroup() );
|
||||
mScene->addItem( mObjectLayer = new QGraphicsItemGroup() );
|
||||
mScene->addItem( mForegroundLayer = new QGraphicsItemGroup() );
|
||||
mScene->addItem( mSelectRegionLayer = new QGraphicsItemGroup() );
|
||||
|
||||
initSelectRegionLayer();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Model Parameter Setter
|
||||
///
|
||||
void View::setModel( LabelModel* model )
|
||||
{
|
||||
mModel = model;
|
||||
|
||||
mScene->setSceneRect( 0, 0, model->w(), model->h() );
|
||||
|
||||
initLabelLayer();
|
||||
initGridLayer();
|
||||
initMarkupLayer();
|
||||
|
||||
foreach (LabelModelObject* object, model->objectList() )
|
||||
{
|
||||
addObjectToObjectLayer( object );
|
||||
}
|
||||
|
||||
initForegroundLayer();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Grid Visibility Parameter Setter
|
||||
///
|
||||
void View::setGridVisible( bool visibleFlag )
|
||||
{
|
||||
mGridLayer->setVisible( visibleFlag );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Markup Visibility Parameter Setter
|
||||
///
|
||||
void View::setMarkupVisible( bool visibleFlag )
|
||||
{
|
||||
mMarkupLayer->setVisible( visibleFlag );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Zoom In "One Notch"
|
||||
///
|
||||
void View::zoomIn()
|
||||
{
|
||||
// Find closest standard zoom level to our current zoom
|
||||
// Start with 2nd largest scale
|
||||
int i_min = 1;
|
||||
double dist_min = fabs( zoomLevels[1] - mZoom );
|
||||
|
||||
for ( int i = 2; i < nZoomLevels; i++ )
|
||||
{
|
||||
double dist = fabs( zoomLevels[i] - mZoom );
|
||||
if ( dist < dist_min )
|
||||
{
|
||||
i_min = i;
|
||||
dist_min = dist;
|
||||
}
|
||||
}
|
||||
|
||||
// Zoom in one notch
|
||||
setZoomReal( zoomLevels[i_min-1], false );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Zoom Out "One Notch"
|
||||
///
|
||||
void View::zoomOut()
|
||||
{
|
||||
// Find closest standard zoom level to our current zoom
|
||||
// Start with largest scale, end on 2nd smallest
|
||||
int i_min = 0;
|
||||
double dist_min = fabs( zoomLevels[0] - mZoom );
|
||||
|
||||
for ( int i = 1; i < (nZoomLevels-1); i++ )
|
||||
{
|
||||
double dist = fabs( zoomLevels[i] - mZoom );
|
||||
if ( dist < dist_min )
|
||||
{
|
||||
i_min = i;
|
||||
dist_min = dist;
|
||||
}
|
||||
}
|
||||
|
||||
// Zoom out one notch
|
||||
setZoomReal( zoomLevels[i_min+1], false );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Zoom To 1:1 Scale
|
||||
///
|
||||
void View::zoom1To1()
|
||||
{
|
||||
setZoomReal( 1.0, false );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Zoom To Fit
|
||||
///
|
||||
void View::zoomToFit()
|
||||
{
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
double x_scale = (72.0/physicalDpiX()) * ( width() - ZOOM_TO_FIT_PAD ) / mModel->w();
|
||||
double y_scale = (72.0/physicalDpiY()) * ( height() - ZOOM_TO_FIT_PAD ) / mModel->h();
|
||||
double newZoom = min( x_scale, y_scale );
|
||||
|
||||
// Limits
|
||||
newZoom = min( newZoom, zoomLevels[0] );
|
||||
newZoom = max( newZoom, zoomLevels[nZoomLevels-1] );
|
||||
|
||||
setZoomReal( newZoom, true );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is Zoom at Maximum?
|
||||
///
|
||||
bool View::isZoomMax() const
|
||||
{
|
||||
return ( mZoom >= zoomLevels[0] );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Is Zoom at Minimum?
|
||||
///
|
||||
bool View::isZoomMin() const
|
||||
{
|
||||
return ( mZoom <= zoomLevels[nZoomLevels-1] );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Set Zoom to Value
|
||||
///
|
||||
void View::setZoomReal( double zoom, bool zoomToFitFlag )
|
||||
{
|
||||
mZoom = zoom;
|
||||
mZoomToFitFlag = zoomToFitFlag;
|
||||
|
||||
resetTransform();
|
||||
scale( mZoom*physicalDpiX()/72.0, mZoom*physicalDpiY()/72.0 );
|
||||
|
||||
emit zoomChanged();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Resize Event Handler
|
||||
///
|
||||
void View::resizeEvent( QResizeEvent *event )
|
||||
{
|
||||
if ( mZoomToFitFlag )
|
||||
{
|
||||
zoomToFit();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Refresh to keep view location relative to window
|
||||
resetTransform();
|
||||
scale( mZoom*physicalDpiX()/72.0, mZoom*physicalDpiY()/72.0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Mouse Movement Event Handler
|
||||
///
|
||||
void View::mouseMoveEvent( QMouseEvent* event )
|
||||
{
|
||||
QPointF pointer = mapToScene( event->x(), event->y() );
|
||||
emit pointerMoved( pointer.x(), pointer.y() );
|
||||
|
||||
switch (mState)
|
||||
{
|
||||
|
||||
case IdleState:
|
||||
break;
|
||||
|
||||
case ArrowSelectRegionState:
|
||||
mSelectRegion.setX2( pointer.x() );
|
||||
mSelectRegion.setY2( pointer.y() );
|
||||
|
||||
mSelectRegionItem->setRect( mSelectRegion.rect() );
|
||||
break;
|
||||
|
||||
default:
|
||||
// Should not happen!
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Leave Event Handler
|
||||
///
|
||||
void View::leaveEvent( QEvent* event )
|
||||
{
|
||||
emit pointerExited();
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Mouse Button Press Event Handler
|
||||
///
|
||||
void View::mousePressEvent( QMouseEvent* event )
|
||||
{
|
||||
QPointF pointer = mapToScene( event->x(), event->y() );
|
||||
|
||||
if ( event->button() & Qt::LeftButton )
|
||||
{
|
||||
// Select Region
|
||||
if ( !(event->modifiers() & Qt::ControlModifier) )
|
||||
{
|
||||
mModel->unselectAll();
|
||||
}
|
||||
|
||||
mSelectRegion.setX1( pointer.x() );
|
||||
mSelectRegion.setY1( pointer.y() );
|
||||
mSelectRegion.setX2( pointer.x() );
|
||||
mSelectRegion.setY2( pointer.y() );
|
||||
|
||||
mSelectRegionItem->setRect( mSelectRegion.rect() );
|
||||
mSelectRegionLayer->setVisible( true );
|
||||
|
||||
mState = ArrowSelectRegionState;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Mouse Button Release Event Handler
|
||||
///
|
||||
void View::mouseReleaseEvent( QMouseEvent* event )
|
||||
{
|
||||
QPointF pointer = mapToScene( event->x(), event->y() );
|
||||
|
||||
if ( event->button() & Qt::LeftButton )
|
||||
{
|
||||
switch (mState)
|
||||
{
|
||||
|
||||
case IdleState:
|
||||
break;
|
||||
|
||||
case ArrowSelectRegionState:
|
||||
mSelectRegion.setX2( pointer.x() );
|
||||
mSelectRegion.setY2( pointer.y() );
|
||||
|
||||
mSelectRegionItem->setRect( 0, 0, 0, 0 );
|
||||
mSelectRegionLayer->setVisible( false );
|
||||
|
||||
mModel->selectRegion( mSelectRegion );
|
||||
|
||||
mState = IdleState;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Should not happen!
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Clear Layer (Item Group) of All Child Items
|
||||
///
|
||||
void View::clearLayer( QGraphicsItemGroup* layer )
|
||||
{
|
||||
foreach( QGraphicsItem* item, layer->childItems() )
|
||||
{
|
||||
layer->removeFromGroup( item );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Initialize Label Layer
|
||||
///
|
||||
void View::initLabelLayer()
|
||||
{
|
||||
clearLayer( mLabelLayer );
|
||||
|
||||
QGraphicsPathItem *labelItem = new QGraphicsPathItem( mModel->frame()->path() );
|
||||
|
||||
QBrush brush( labelColor );
|
||||
labelItem->setBrush( brush );
|
||||
|
||||
QGraphicsDropShadowEffect *shadowEffect = new QGraphicsDropShadowEffect();
|
||||
shadowEffect->setColor( shadowColor );
|
||||
shadowEffect->setOffset( shadowOffsetPixels );
|
||||
shadowEffect->setBlurRadius( shadowRadiusPixels );
|
||||
labelItem->setGraphicsEffect( shadowEffect );
|
||||
|
||||
mLabelLayer->addToGroup( labelItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Initialize Grid Layer
|
||||
///
|
||||
void View::initGridLayer()
|
||||
{
|
||||
clearLayer( mGridLayer );
|
||||
|
||||
QGraphicsPathItem *clipItem = new QGraphicsPathItem( mModel->frame()->path() );
|
||||
clipItem->setFlag( QGraphicsItem::ItemClipsChildrenToShape );
|
||||
|
||||
QPen pen( gridLineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( gridLineWidthPixels );
|
||||
|
||||
double w = mModel->w();
|
||||
double h = mModel->h();
|
||||
double x0;
|
||||
double y0;
|
||||
if ( dynamic_cast<const libglabels::FrameRect*>( mModel->frame() ) )
|
||||
{
|
||||
x0 = gridSpacing;
|
||||
y0 = gridSpacing;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* round labels, align grid with center of label. */
|
||||
x0 = fmod( w/2, gridSpacing );
|
||||
y0 = fmod( h/2, gridSpacing );
|
||||
}
|
||||
|
||||
for ( double x = x0; x < w; x += gridSpacing )
|
||||
{
|
||||
QGraphicsLineItem* lineItem = new QGraphicsLineItem( x, 0, x, h, clipItem );
|
||||
lineItem->setPen( pen );
|
||||
}
|
||||
|
||||
for ( double y = y0; y < h; y += gridSpacing )
|
||||
{
|
||||
QGraphicsLineItem* lineItem = new QGraphicsLineItem( 0, y, w, y, clipItem );
|
||||
lineItem->setPen( pen );
|
||||
}
|
||||
|
||||
mGridLayer->addToGroup( clipItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Initialize Markup Layer
|
||||
///
|
||||
void View::initMarkupLayer()
|
||||
{
|
||||
clearLayer( mMarkupLayer );
|
||||
|
||||
QPen pen( markupLineColor );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( markupLineWidthPixels );
|
||||
|
||||
const libglabels::Frame* frame = mModel->frame();
|
||||
|
||||
foreach (libglabels::Markup* markup, frame->markups() )
|
||||
{
|
||||
QGraphicsItem* markupItem = markup->createGraphicsItem( frame, pen );
|
||||
|
||||
mMarkupLayer->addToGroup( markupItem );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Add Object to Object Layer
|
||||
///
|
||||
void View::addObjectToObjectLayer( LabelModelObject* object )
|
||||
{
|
||||
QGraphicsItem* item = object->createGraphicsItem();
|
||||
mObjectLayer->addToGroup( item );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Initialize Foreground Layer
|
||||
///
|
||||
void View::initForegroundLayer()
|
||||
{
|
||||
clearLayer( mForegroundLayer );
|
||||
|
||||
QGraphicsPathItem *outlineItem = new QGraphicsPathItem( mModel->frame()->path() );
|
||||
|
||||
QPen pen( labelOutlineColor );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( labelOutlineWidthPixels );
|
||||
outlineItem->setPen( pen );
|
||||
|
||||
mForegroundLayer->addToGroup( outlineItem );
|
||||
}
|
||||
|
||||
|
||||
///
|
||||
/// Initialize Select Region Layer
|
||||
///
|
||||
void View::initSelectRegionLayer()
|
||||
{
|
||||
clearLayer( mSelectRegionLayer );
|
||||
|
||||
mSelectRegionItem = new QGraphicsRectItem();
|
||||
|
||||
QBrush brush( selectRegionFillColor );
|
||||
mSelectRegionItem->setBrush( brush );
|
||||
|
||||
QPen pen( selectRegionOutlineColor );
|
||||
pen.setJoinStyle( Qt::MiterJoin );
|
||||
pen.setCosmetic( true );
|
||||
pen.setWidthF( selectRegionOutlineWidthPixels );
|
||||
mSelectRegionItem->setPen( pen );
|
||||
|
||||
mSelectRegionLayer->addToGroup( mSelectRegionItem );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/* View.h
|
||||
*
|
||||
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef glabels_View_h
|
||||
#define glabels_View_h
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "LabelRegion.h"
|
||||
|
||||
class QGraphicsScene;
|
||||
class QGraphicsItemGroup;
|
||||
|
||||
|
||||
namespace glabels
|
||||
{
|
||||
// Forward References
|
||||
class LabelModel;
|
||||
class LabelModelObject;
|
||||
|
||||
|
||||
///
|
||||
/// View Widget
|
||||
///
|
||||
class View : public QGraphicsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
/////////////////////////////////////
|
||||
// Lifecycle
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
View( QWidget *parent = 0 );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Signals
|
||||
/////////////////////////////////////
|
||||
signals:
|
||||
void zoomChanged();
|
||||
void pointerMoved( double x, double y );
|
||||
void pointerExited();
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Parameters
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
inline double zoom() const;
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Model
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
void setModel( LabelModel* model );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Visibility operations
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
void setGridVisible( bool visibleFlag );
|
||||
void setMarkupVisible( bool visibleFlag );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Zoom operations
|
||||
/////////////////////////////////////
|
||||
public:
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void zoom1To1();
|
||||
void zoomToFit();
|
||||
bool isZoomMax() const;
|
||||
bool isZoomMin() const;
|
||||
private:
|
||||
void setZoomReal( double zoom, bool zoomToFitFlag );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Event handlers
|
||||
/////////////////////////////////////
|
||||
protected:
|
||||
void resizeEvent( QResizeEvent* event );
|
||||
void mouseMoveEvent( QMouseEvent* event );
|
||||
void mousePressEvent( QMouseEvent* event );
|
||||
void mouseReleaseEvent( QMouseEvent* event );
|
||||
void leaveEvent( QEvent* event );
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Private methods
|
||||
/////////////////////////////////////
|
||||
private:
|
||||
void clearLayer( QGraphicsItemGroup* layer );
|
||||
void initLabelLayer();
|
||||
void initGridLayer();
|
||||
void initMarkupLayer();
|
||||
void addObjectToObjectLayer( LabelModelObject* object );
|
||||
void initForegroundLayer();
|
||||
void initSelectRegionLayer();
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Private data
|
||||
/////////////////////////////////////
|
||||
private:
|
||||
enum State {
|
||||
IdleState,
|
||||
ArrowSelectRegionState
|
||||
};
|
||||
|
||||
State mState;
|
||||
|
||||
QGraphicsScene* mScene;
|
||||
|
||||
QGraphicsItemGroup* mLabelLayer;
|
||||
QGraphicsItemGroup* mGridLayer;
|
||||
QGraphicsItemGroup* mMarkupLayer;
|
||||
QGraphicsItemGroup* mObjectLayer;
|
||||
QGraphicsItemGroup* mForegroundLayer;
|
||||
QGraphicsItemGroup* mSelectRegionLayer;
|
||||
|
||||
QGraphicsRectItem* mSelectRegionItem;
|
||||
LabelRegion mSelectRegion;
|
||||
|
||||
double mZoom;
|
||||
bool mZoomToFitFlag;
|
||||
|
||||
LabelModel* mModel;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/////////////////////////////////
|
||||
// INLINE METHODS
|
||||
/////////////////////////////////
|
||||
|
||||
inline double View::zoom() const
|
||||
{
|
||||
return mZoom;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // glabels_View_h
|
||||
@@ -0,0 +1,53 @@
|
||||
/* glabels_main.cpp
|
||||
*
|
||||
* Copyright (C) 2011 Jim Evins <evins@snaught.com>
|
||||
*
|
||||
* This file is part of gLabels-qt.
|
||||
*
|
||||
* gLabels-qt is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* gLabels-qt is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "libglabels/Db.h"
|
||||
|
||||
using namespace glabels;
|
||||
using namespace libglabels;
|
||||
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
QApplication app( argc, argv );
|
||||
|
||||
QCoreApplication::setOrganizationName( "glabels.org" );
|
||||
QCoreApplication::setOrganizationDomain( "glabels.org" );
|
||||
QCoreApplication::setApplicationName( "glabels-qt" );
|
||||
|
||||
Db::init();
|
||||
////// TEMPORARY TESTING ////////
|
||||
#if 0
|
||||
Db::printKnownPapers();
|
||||
Db::printKnownCategories();
|
||||
Db::printKnownVendors();
|
||||
Db::printKnownTemplates();
|
||||
#endif
|
||||
/////////////////////////////////
|
||||
|
||||
MainWindow mainWin;
|
||||
mainWin.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<!DOCTYPE RCC>
|
||||
|
||||
<RCC version="1.0">
|
||||
<qresource>
|
||||
<file>icons/16x16/actions/glabels-align-bottom.png</file>
|
||||
<file>icons/16x16/actions/glabels-align-hcenter.png</file>
|
||||
<file>icons/16x16/actions/glabels-align-left.png</file>
|
||||
<file>icons/16x16/actions/glabels-align-right.png</file>
|
||||
<file>icons/16x16/actions/glabels-align-top.png</file>
|
||||
<file>icons/16x16/actions/glabels-align-vcenter.png</file>
|
||||
<file>icons/16x16/actions/glabels-arrow.png</file>
|
||||
<file>icons/16x16/actions/glabels-barcode.png</file>
|
||||
<file>icons/16x16/actions/glabels-box.png</file>
|
||||
<file>icons/16x16/actions/glabels-bucket-fill.png</file>
|
||||
<file>icons/16x16/actions/glabels-center-horiz.png</file>
|
||||
<file>icons/16x16/actions/glabels-center-vert.png</file>
|
||||
<file>icons/16x16/actions/glabels-ellipse.png</file>
|
||||
<file>icons/16x16/actions/glabels-flip-horiz.png</file>
|
||||
<file>icons/16x16/actions/glabels-flip-vert.png</file>
|
||||
<file>icons/16x16/actions/glabels-image.png</file>
|
||||
<file>icons/16x16/actions/glabels-line.png</file>
|
||||
<file>icons/16x16/actions/glabels-merge.png</file>
|
||||
<file>icons/16x16/actions/glabels-object-properties.png</file>
|
||||
<file>icons/16x16/actions/glabels-order-bottom.png</file>
|
||||
<file>icons/16x16/actions/glabels-order-top.png</file>
|
||||
<file>icons/16x16/actions/glabels-pencil.png</file>
|
||||
<file>icons/16x16/actions/glabels-rotate-left.png</file>
|
||||
<file>icons/16x16/actions/glabels-rotate-right.png</file>
|
||||
<file>icons/16x16/actions/glabels-text.png</file>
|
||||
<file>icons/16x16/apps/glabels.png</file>
|
||||
<file>icons/24x24/actions/glabels-align-text-bottom.png</file>
|
||||
<file>icons/24x24/actions/glabels-align-text-middle.png</file>
|
||||
<file>icons/24x24/actions/glabels-align-text-top.png</file>
|
||||
<file>icons/24x24/actions/glabels-arrow.png</file>
|
||||
<file>icons/24x24/actions/glabels-barcode.png</file>
|
||||
<file>icons/24x24/actions/glabels-box.png</file>
|
||||
<file>icons/24x24/actions/glabels-bucket-fill.png</file>
|
||||
<file>icons/24x24/actions/glabels-ellipse.png</file>
|
||||
<file>icons/24x24/actions/glabels-image.png</file>
|
||||
<file>icons/24x24/actions/glabels-line.png</file>
|
||||
<file>icons/24x24/actions/glabels-merge.png</file>
|
||||
<file>icons/24x24/actions/glabels-object-properties.png</file>
|
||||
<file>icons/24x24/actions/glabels-pencil.png</file>
|
||||
<file>icons/24x24/actions/glabels-text.png</file>
|
||||
<file>icons/24x24/actions/fallback-edit-copy.png</file>
|
||||
<file>icons/24x24/actions/fallback-edit-cut.png</file>
|
||||
<file>icons/24x24/actions/fallback-edit-paste.png</file>
|
||||
<file>icons/24x24/actions/fallback-file-new.png</file>
|
||||
<file>icons/24x24/actions/fallback-file-open.png</file>
|
||||
<file>icons/24x24/actions/fallback-file-print.png</file>
|
||||
<file>icons/24x24/actions/fallback-file-save-as.png</file>
|
||||
<file>icons/24x24/actions/fallback-file-save.png</file>
|
||||
<file>icons/24x24/actions/fallback-zoom-best-fit.png</file>
|
||||
<file>icons/24x24/actions/fallback-zoom-in.png</file>
|
||||
<file>icons/24x24/actions/fallback-zoom-original.png</file>
|
||||
<file>icons/24x24/actions/fallback-zoom-out.png</file>
|
||||
<file>icons/24x24/apps/glabels.png</file>
|
||||
<file>icons/32x32/apps/glabels.png</file>
|
||||
<file>icons/48x48/apps/glabels.png</file>
|
||||
<file>icons/scalable/apps/glabels.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
After Width: | Height: | Size: 204 B |
|
After Width: | Height: | Size: 212 B |
|
After Width: | Height: | Size: 207 B |
|
After Width: | Height: | Size: 219 B |
|
After Width: | Height: | Size: 209 B |
|
After Width: | Height: | Size: 230 B |
|
After Width: | Height: | Size: 234 B |
|
After Width: | Height: | Size: 293 B |
|
After Width: | Height: | Size: 199 B |
|
After Width: | Height: | Size: 521 B |
|
After Width: | Height: | Size: 202 B |
|
After Width: | Height: | Size: 206 B |
|
After Width: | Height: | Size: 376 B |
|
After Width: | Height: | Size: 183 B |
|
After Width: | Height: | Size: 194 B |
|
After Width: | Height: | Size: 485 B |
|
After Width: | Height: | Size: 252 B |
|
After Width: | Height: | Size: 459 B |
|
After Width: | Height: | Size: 395 B |
|
After Width: | Height: | Size: 200 B |
|
After Width: | Height: | Size: 194 B |
|
After Width: | Height: | Size: 489 B |
|
After Width: | Height: | Size: 243 B |
|
After Width: | Height: | Size: 241 B |
|
After Width: | Height: | Size: 160 B |
|
After Width: | Height: | Size: 669 B |
|
After Width: | Height: | Size: 859 B |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.1 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1021 B |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 878 B |
|
After Width: | Height: | Size: 858 B |
|
After Width: | Height: | Size: 879 B |
|
After Width: | Height: | Size: 791 B |
|
After Width: | Height: | Size: 481 B |
|
After Width: | Height: | Size: 639 B |
|
After Width: | Height: | Size: 398 B |
|
After Width: | Height: | Size: 367 B |
|
After Width: | Height: | Size: 241 B |
|
After Width: | Height: | Size: 320 B |
|
After Width: | Height: | Size: 589 B |
|
After Width: | Height: | Size: 744 B |
|
After Width: | Height: | Size: 704 B |
|
After Width: | Height: | Size: 325 B |
|
After Width: | Height: | Size: 758 B |
|
After Width: | Height: | Size: 484 B |
|
After Width: | Height: | Size: 618 B |
|
After Width: | Height: | Size: 285 B |