Big-Ugly Style Update (#278)

* Bulk replaced tabs with spaces
* Bulk removed trailing whitespace from lines
* Replaced c-style comments with c++-style comments in file banners
* Replace nested namespace definitions with single concise definitions (C++17), this keeps the indentation more manageable
* Cleanup ordering and spacing of include directives
* Bulk renaming of header file extensions from '.h' to '.hpp'.
* Update CODING-STYLE.md
* Update target_compile_features from cxx_std_11 to cxx_std_20.
* Refresh .clang-format file.  Still needs a lot of tweaking.
This commit is contained in:
Jaye Evins
2026-01-07 19:43:34 -05:00
committed by GitHub
parent 3cd173a37f
commit 1c902230fe
454 changed files with 51827 additions and 52031 deletions
+69 -68
View File
@@ -1,87 +1,88 @@
/* AboutDialog.cpp
*
* Copyright (C) 2016 Jaye 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/>.
*/
// AboutDialog.cpp
//
// Copyright (C) 2016 Jaye 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 "AboutDialog.h"
#include "model/Version.h"
#include "AboutDialog.hpp"
#include "model/Version.hpp"
#include <QDebug>
#include <QDesktopServices>
#include <QUrl>
#include <QtDebug>
namespace glabels
{
///
/// Constructor
///
AboutDialog::AboutDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
///
/// Constructor
///
AboutDialog::AboutDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
QString version = tr("Version") + " " + model::Version::LONG_STRING;
QString description = tr("A program to create labels and business cards.");
QString copyright = "Copyright &copy; 2018 Jaye Evins <evins@snaught.com>";
QString licenseParagraph1 =
tr( "gLabels is free software: you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version." );
QString version = tr("Version") + " " + model::Version::LONG_STRING;
QString licenseParagraph2 =
tr( "gLabels is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
"GNU General Public License for more details." );
QString markup =
"<p align='center'>" + version + "</p>" +
"<p align='center'>" + description + "</p>" +
"<p align='center'>" + copyright + "</p>" +
"<p align='left'>" + licenseParagraph1 + "</p>" +
"<p align='left'>" + licenseParagraph2 + "</p>";
QString description = tr("A program to create labels and business cards.");
aboutLabel->setText( markup );
}
QString copyright = "Copyright &copy; 2018 Jaye Evins <evins@snaught.com>";
QString licenseParagraph1 =
tr( "gLabels is free software: you can redistribute it and/or modify "
"it under the terms of the GNU General Public License as published by "
"the Free Software Foundation, either version 3 of the License, or "
"(at your option) any later version." );
QString licenseParagraph2 =
tr( "gLabels is distributed in the hope that it will be useful, "
"but WITHOUT ANY WARRANTY; without even the implied warranty of "
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the "
"GNU General Public License for more details." );
QString markup =
"<p align='center'>" + version + "</p>" +
"<p align='center'>" + description + "</p>" +
"<p align='center'>" + copyright + "</p>" +
"<p align='left'>" + licenseParagraph1 + "</p>" +
"<p align='left'>" + licenseParagraph2 + "</p>";
aboutLabel->setText( markup );
}
///
/// "License" Button Clicked Slot
///
void AboutDialog::onLicenseButtonClicked()
{
QDesktopServices::openUrl( QUrl("http://www.gnu.org/licenses/gpl-3.0.txt") );
}
///
/// "License" Button Clicked Slot
///
void AboutDialog::onLicenseButtonClicked()
{
QDesktopServices::openUrl( QUrl("http://www.gnu.org/licenses/gpl-3.0.txt") );
}
///
/// "Website" Button Clicked Slot
///
void AboutDialog::onWebsiteButtonClicked()
{
QDesktopServices::openUrl( QUrl(model::Version::WEBSITE) );
}
///
/// "Website" Button Clicked Slot
///
void AboutDialog::onWebsiteButtonClicked()
{
QDesktopServices::openUrl( QUrl(model::Version::WEBSITE) );
}
} // namespace glabels
-58
View File
@@ -1,58 +0,0 @@
/* AboutDialog.h
*
* Copyright (C) 2016 Jaye 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 AboutDialog_h
#define AboutDialog_h
#include "ui_AboutDialog.h"
namespace glabels
{
///
/// About Dialog Widget
///
class AboutDialog : public QDialog, public Ui_AboutDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
AboutDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onLicenseButtonClicked();
void onWebsiteButtonClicked();
};
}
#endif // AboutDialog_h
+58
View File
@@ -0,0 +1,58 @@
// AboutDialog.hpp
//
// Copyright (C) 2016 Jaye 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 AboutDialog_hpp
#define AboutDialog_hpp
#include "ui_AboutDialog.h"
namespace glabels
{
///
/// About Dialog Widget
///
class AboutDialog : public QDialog, public Ui_AboutDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
AboutDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onLicenseButtonClicked();
void onWebsiteButtonClicked();
};
}
#endif // AboutDialog_hpp
+71 -70
View File
@@ -1,88 +1,89 @@
/* BarcodeMenu.cpp
*
* Copyright (C) 2014 Jaye 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/>.
*/
// BarcodeMenu.cpp
//
// Copyright (C) 2014 Jaye 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 "BarcodeMenuItem.h"
#include "BarcodeMenu.hpp"
#include "barcode/Backends.h"
#include "BarcodeMenuItem.hpp"
#include <QtDebug>
#include "barcode/Backends.hpp"
#include <QDebug>
namespace glabels
{
///
/// Constructor
///
BarcodeMenu::BarcodeMenu()
{
for ( const barcode::Style& bcStyle : barcode::Backends::styleList() )
{
if ( bcStyle.backendId() == "" )
{
auto* bcMenuItem = new BarcodeMenuItem( bcStyle );
connect( bcMenuItem, SIGNAL(activated(const barcode::Style&)),
this, SLOT(onMenuItemActivated(const barcode::Style&)) );
addAction( bcMenuItem );
}
}
///
/// Constructor
///
BarcodeMenu::BarcodeMenu()
{
for ( const barcode::Style& bcStyle : barcode::Backends::styleList() )
{
if ( bcStyle.backendId() == "" )
{
auto* bcMenuItem = new BarcodeMenuItem( bcStyle );
connect( bcMenuItem, SIGNAL(activated(const barcode::Style&)),
this, SLOT(onMenuItemActivated(const barcode::Style&)) );
for ( const QString& backendId : barcode::Backends::backendList() )
{
QMenu* subMenu = addMenu( barcode::Backends::backendName( backendId ) );
for ( const barcode::Style& bcStyle : barcode::Backends::styleList() )
{
if ( bcStyle.backendId() == backendId )
{
auto* bcMenuItem = new BarcodeMenuItem( bcStyle );
connect( bcMenuItem, SIGNAL(activated(const barcode::Style&)),
this, SLOT(onMenuItemActivated(const barcode::Style&)) );
addAction( bcMenuItem );
}
}
subMenu->addAction( bcMenuItem );
}
}
}
}
for ( const QString& backendId : barcode::Backends::backendList() )
{
QMenu* subMenu = addMenu( barcode::Backends::backendName( backendId ) );
for ( const barcode::Style& bcStyle : barcode::Backends::styleList() )
{
if ( bcStyle.backendId() == backendId )
{
auto* bcMenuItem = new BarcodeMenuItem( bcStyle );
connect( bcMenuItem, SIGNAL(activated(const barcode::Style&)),
this, SLOT(onMenuItemActivated(const barcode::Style&)) );
subMenu->addAction( bcMenuItem );
}
}
}
}
///
/// bcStyle getter
///
barcode::Style BarcodeMenu::bcStyle() const
{
return mBcStyle;
}
///
/// bcStyle getter
///
barcode::Style BarcodeMenu::bcStyle() const
{
return mBcStyle;
}
///
/// onMenuItemActivated slot
///
void BarcodeMenu::onMenuItemActivated( const barcode::Style& bcStyle )
{
mBcStyle = bcStyle;
///
/// onMenuItemActivated slot
///
void BarcodeMenu::onMenuItemActivated( const barcode::Style& bcStyle )
{
mBcStyle = bcStyle;
emit selectionChanged();
}
emit selectionChanged();
}
} // namespace glabels
-79
View File
@@ -1,79 +0,0 @@
/* BarcodeMenu.h
*
* Copyright (C) 2014 Jaye 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 BarcodeMenu_h
#define BarcodeMenu_h
#include "barcode/Style.h"
#include <QMenu>
namespace glabels
{
///
/// Barcode Menu
///
class BarcodeMenu : public QMenu
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenu();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void selectionChanged();
/////////////////////////////////
// Properties
/////////////////////////////////
public:
barcode::Style bcStyle() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuItemActivated( const barcode::Style& bcStyle );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
barcode::Style mBcStyle;
};
}
#endif // BarcodeMenu_h
+79
View File
@@ -0,0 +1,79 @@
// BarcodeMenu.hpp
//
// Copyright (C) 2014 Jaye 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 BarcodeMenu_hpp
#define BarcodeMenu_hpp
#include "barcode/Style.hpp"
#include <QMenu>
namespace glabels
{
///
/// Barcode Menu
///
class BarcodeMenu : public QMenu
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenu();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void selectionChanged();
/////////////////////////////////
// Properties
/////////////////////////////////
public:
barcode::Style bcStyle() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuItemActivated( const barcode::Style& bcStyle );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
barcode::Style mBcStyle;
};
}
#endif // BarcodeMenu_hpp
+61 -60
View File
@@ -1,79 +1,80 @@
/* BarcodeMenuButton.cpp
*
* Copyright (C) 2014 Jaye 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/>.
*/
// BarcodeMenuButton.cpp
//
// Copyright (C) 2014 Jaye 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 "BarcodeMenuItem.h"
#include "BarcodeMenuButton.hpp"
#include "barcode/Backends.h"
#include "BarcodeMenuItem.hpp"
#include <QtDebug>
#include "barcode/Backends.hpp"
#include <QDebug>
namespace glabels
{
///
/// Constructor
///
BarcodeMenuButton::BarcodeMenuButton( QWidget* parent )
: QPushButton(parent)
{
mMenu = new BarcodeMenu();
setMenu( mMenu );
mBcStyle = barcode::Backends::defaultStyle();
setText( mBcStyle.fullName() );
///
/// Constructor
///
BarcodeMenuButton::BarcodeMenuButton( QWidget* parent )
: QPushButton(parent)
{
mMenu = new BarcodeMenu();
setMenu( mMenu );
connect( mMenu, SIGNAL(selectionChanged()), this, SLOT(onMenuSelectionChanged()) );
}
mBcStyle = barcode::Backends::defaultStyle();
setText( mBcStyle.fullName() );
connect( mMenu, SIGNAL(selectionChanged()), this, SLOT(onMenuSelectionChanged()) );
}
///
/// bcStyle getter
///
barcode::Style BarcodeMenuButton::bcStyle() const
{
return mBcStyle;
}
///
/// bcStyle getter
///
barcode::Style BarcodeMenuButton::bcStyle() const
{
return mBcStyle;
}
///
/// bcStyle setter
///
void BarcodeMenuButton::setBcStyle( const barcode::Style& bcStyle )
{
mBcStyle = bcStyle;
setText( mBcStyle.fullName() );
}
///
/// bcStyle setter
///
void BarcodeMenuButton::setBcStyle( const barcode::Style& bcStyle )
{
mBcStyle = bcStyle;
setText( mBcStyle.fullName() );
}
///
/// onMenuStyleChanged slot
///
void BarcodeMenuButton::onMenuSelectionChanged()
{
mBcStyle = mMenu->bcStyle();
setText( mBcStyle.fullName() );
///
/// onMenuStyleChanged slot
///
void BarcodeMenuButton::onMenuSelectionChanged()
{
mBcStyle = mMenu->bcStyle();
setText( mBcStyle.fullName() );
emit selectionChanged();
}
emit selectionChanged();
}
} // namespace glabels
-83
View File
@@ -1,83 +0,0 @@
/* BarcodeMenuButton.h
*
* Copyright (C) 2014 Jaye 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 BarcodeMenuButton_h
#define BarcodeMenuButton_h
#include "BarcodeMenu.h"
#include "barcode/Style.h"
#include <QPushButton>
namespace glabels
{
///
/// Barcode Menu Button
///
class BarcodeMenuButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenuButton( QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void selectionChanged();
/////////////////////////////////
// Properties
/////////////////////////////////
public:
barcode::Style bcStyle() const;
void setBcStyle( const barcode::Style& bcStyle );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuSelectionChanged();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
BarcodeMenu* mMenu;
barcode::Style mBcStyle;
};
}
#endif // BarcodeMenuButton_h
+83
View File
@@ -0,0 +1,83 @@
// BarcodeMenuButton.hpp
//
// Copyright (C) 2014 Jaye 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 BarcodeMenuButton_hpp
#define BarcodeMenuButton_hpp
#include "BarcodeMenu.hpp"
#include "barcode/Style.hpp"
#include <QPushButton>
namespace glabels
{
///
/// Barcode Menu Button
///
class BarcodeMenuButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenuButton( QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void selectionChanged();
/////////////////////////////////
// Properties
/////////////////////////////////
public:
barcode::Style bcStyle() const;
void setBcStyle( const barcode::Style& bcStyle );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuSelectionChanged();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
BarcodeMenu* mMenu;
barcode::Style mBcStyle;
};
}
#endif // BarcodeMenuButton_hpp
+45 -44
View File
@@ -1,58 +1,59 @@
/* BarcodeMenuItem.cpp
*
* Copyright (C) 2014 Jaye 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/>.
*/
// BarcodeMenuItem.cpp
//
// Copyright (C) 2014 Jaye 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"
#include <QtDebug>
#include "BarcodeMenuItem.hpp"
#include <QDebug>
namespace glabels
{
///
/// Constructor From Data
///
BarcodeMenuItem::BarcodeMenuItem( const barcode::Style& bcStyle, QObject* parent )
: QAction(parent), mBcStyle(bcStyle)
{
setText( bcStyle.name() );
///
/// Constructor From Data
///
BarcodeMenuItem::BarcodeMenuItem( const barcode::Style& bcStyle, QObject* parent )
: QAction(parent), mBcStyle(bcStyle)
{
setText( bcStyle.name() );
connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) );
}
connect( this, SIGNAL(triggered()), this, SLOT(onTriggered()) );
}
///
/// bcStyle Property Getter
///
barcode::Style BarcodeMenuItem::bcStyle() const
{
return mBcStyle;
}
///
/// bcStyle Property Getter
///
barcode::Style BarcodeMenuItem::bcStyle() const
{
return mBcStyle;
}
///
/// onTriggered slot
///
void BarcodeMenuItem::onTriggered()
{
emit activated( mBcStyle );
}
///
/// onTriggered slot
///
void BarcodeMenuItem::onTriggered()
{
emit activated( mBcStyle );
}
} // namespace glabels
-79
View File
@@ -1,79 +0,0 @@
/* BarcodeMenuItem.h
*
* Copyright (C) 2014 Jaye 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 BarcodeMenuItem_h
#define BarcodeMenuItem_h
#include "barcode/Style.h"
#include <QAction>
namespace glabels
{
///
/// Barcode Menu Item
///
class BarcodeMenuItem : public QAction
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenuItem( const barcode::Style& bcStyle, QObject* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( const barcode::Style& bcStyle );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
barcode::Style bcStyle() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onTriggered();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
barcode::Style mBcStyle;
};
}
#endif // BarcodeMenuItem_h
+79
View File
@@ -0,0 +1,79 @@
// BarcodeMenuItem.hpp
//
// Copyright (C) 2014 Jaye 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 BarcodeMenuItem_hpp
#define BarcodeMenuItem_hpp
#include "barcode/Style.hpp"
#include <QAction>
namespace glabels
{
///
/// Barcode Menu Item
///
class BarcodeMenuItem : public QAction
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
BarcodeMenuItem( const barcode::Style& bcStyle, QObject* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( const barcode::Style& bcStyle );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
barcode::Style bcStyle() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onTriggered();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
barcode::Style mBcStyle;
};
}
#endif // BarcodeMenuItem_hpp
+30 -30
View File
@@ -45,35 +45,35 @@ set (glabels_sources
)
set (glabels_qobject_headers
AboutDialog.h
BarcodeMenu.h
BarcodeMenuButton.h
BarcodeMenuItem.h
ColorButton.h
ColorHistory.h
ColorPaletteDialog.h
ColorPaletteItem.h
EditVariableDialog.h
FieldButton.h
File.h
LabelEditor.h
MainWindow.h
MergeTableModel.h
MergeView.h
ObjectEditor.h
PreferencesDialog.h
PrinterMonitor.h
PrintView.h
PropertiesView.h
Preview.h
ReportBugDialog.h
SelectProductDialog.h
SimplePreview.h
StartupView.h
TemplateDesigner.h
TemplatePicker.h
UndoRedoModel.h
VariablesView.h
AboutDialog.hpp
BarcodeMenu.hpp
BarcodeMenuButton.hpp
BarcodeMenuItem.hpp
ColorButton.hpp
ColorHistory.hpp
ColorPaletteDialog.hpp
ColorPaletteItem.hpp
EditVariableDialog.hpp
FieldButton.hpp
File.hpp
LabelEditor.hpp
MainWindow.hpp
MergeTableModel.hpp
MergeView.hpp
ObjectEditor.hpp
PreferencesDialog.hpp
PrinterMonitor.hpp
PrintView.hpp
PropertiesView.hpp
Preview.hpp
ReportBugDialog.hpp
SelectProductDialog.hpp
SimplePreview.hpp
StartupView.hpp
TemplateDesigner.hpp
TemplatePicker.hpp
UndoRedoModel.hpp
VariablesView.hpp
)
set (glabels_forms
@@ -131,7 +131,7 @@ add_executable (glabels-qt WIN32
)
target_compile_features (glabels-qt
PUBLIC cxx_std_11
PUBLIC cxx_std_20
)
target_include_directories (glabels-qt
+145 -144
View File
@@ -1,184 +1,185 @@
/* ColorButton.cpp
*
* Copyright (C) 2014-2016 Jaye 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/>.
*/
// ColorButton.cpp
//
// Copyright (C) 2014-2016 Jaye 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 "ColorButton.h"
#include "ColorSwatch.h"
#include "ColorButton.hpp"
#include "ColorSwatch.hpp"
#include <QDebug>
#include <QHBoxLayout>
#include <QIcon>
#include <QtDebug>
//
// Private
//
namespace
{
const int SWATCH_W = 64;
const int SWATCH_H = 24;
}
namespace glabels
{
//
// Private
//
namespace
{
const int SWATCH_W = 64;
const int SWATCH_H = 24;
}
ColorButton::ColorButton( QWidget* parent )
: QPushButton( parent ), mIsDefault(0), mDialog(nullptr)
{
// empty
}
ColorButton::ColorButton( QWidget* parent )
: QPushButton( parent ), mIsDefault(0), mDialog(nullptr)
{
// empty
}
void ColorButton::init( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton )
{
mDefaultColor = defaultColor;
mColorNode = model::ColorNode( color );
setMinimumSize( QSize( 85, 34 ) );
setIconSize( QSize(SWATCH_W, SWATCH_H) );
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) );
setText( "" );
setCheckable( true );
mDialog = new ColorPaletteDialog( defaultLabel,
defaultColor,
color,
showUseFieldButton );
connect( this, SIGNAL(toggled(bool)), this, SLOT(onButtonToggled(bool)) );
connect( mDialog, SIGNAL(colorChanged(model::ColorNode,bool)),
this, SLOT(onPaletteDialogChanged(model::ColorNode,bool)) );
connect( mDialog, SIGNAL(accepted()), this, SLOT(onPaletteDialogAccepted()) );
connect( mDialog, SIGNAL(rejected()), this, SLOT(onPaletteDialogRejected()) );
}
void ColorButton::init( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton )
{
mDefaultColor = defaultColor;
mColorNode = model::ColorNode( color );
void ColorButton::setColorNode( model::ColorNode colorNode )
{
mIsDefault = false;
setMinimumSize( QSize( 85, 34 ) );
setIconSize( QSize(SWATCH_W, SWATCH_H) );
mColorNode = colorNode;
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) );
setText( "" );
setCheckable( true );
if ( colorNode.isField() )
{
setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) );
}
else
{
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
setText( "" );
}
mDialog = new ColorPaletteDialog( defaultLabel,
defaultColor,
color,
showUseFieldButton );
connect( this, SIGNAL(toggled(bool)), this, SLOT(onButtonToggled(bool)) );
connect( mDialog, SIGNAL(colorChanged(model::ColorNode,bool)),
this, SLOT(onPaletteDialogChanged(model::ColorNode,bool)) );
connect( mDialog, SIGNAL(accepted()), this, SLOT(onPaletteDialogAccepted()) );
connect( mDialog, SIGNAL(rejected()), this, SLOT(onPaletteDialogRejected()) );
}
mDialog->setColorNode( colorNode );
}
void ColorButton::setColorNode( model::ColorNode colorNode )
{
mIsDefault = false;
void ColorButton::setColor( QColor color )
{
mIsDefault = false;
mColorNode = colorNode;
mColorNode.setField( false );
mColorNode.setColor( color );
mColorNode.setKey( "" );
if ( colorNode.isField() )
{
setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) );
}
else
{
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
setText( "" );
}
mDialog->setColorNode( colorNode );
}
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) );
setText( "" );
}
void ColorButton::setColor( QColor color )
{
mIsDefault = false;
void ColorButton::setToDefault()
{
mIsDefault = true;
mColorNode.setField( false );
mColorNode.setColor( color );
mColorNode.setKey( "" );
mColorNode.setField( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, color ) ) );
setText( "" );
}
setIcon( QIcon(ColorSwatch( SWATCH_W, SWATCH_H, mDefaultColor ) ) );
setText( "" );
}
void ColorButton::setToDefault()
{
mIsDefault = true;
mColorNode.setField( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
setIcon( QIcon(ColorSwatch( SWATCH_W, SWATCH_H, mDefaultColor ) ) );
setText( "" );
}
model::ColorNode ColorButton::colorNode()
{
return mColorNode;
}
model::ColorNode ColorButton::colorNode()
{
return mColorNode;
}
void ColorButton::setKeys( const merge::Merge* merge,
const model::Variables& variables )
{
mDialog->setKeys( merge, variables );
}
void ColorButton::setKeys( const merge::Merge* merge,
const model::Variables& variables )
{
mDialog->setKeys( merge, variables );
}
void ColorButton::onButtonToggled( bool checked )
{
if ( checked )
{
///
/// @TODO: improve positioning of dialog -- near edges of screen.
///
QPoint dialogPos( 0, height() );
mDialog->move( mapToGlobal(dialogPos) );
mDialog->show();
}
}
void ColorButton::onButtonToggled( bool checked )
{
if ( checked )
{
///
/// @TODO: improve positioning of dialog -- near edges of screen.
///
QPoint dialogPos( 0, height() );
mDialog->move( mapToGlobal(dialogPos) );
mDialog->show();
}
}
void ColorButton::onPaletteDialogAccepted()
{
setChecked( false );
}
void ColorButton::onPaletteDialogAccepted()
{
setChecked( false );
}
void ColorButton::onPaletteDialogRejected()
{
setChecked( false );
}
void ColorButton::onPaletteDialogRejected()
{
setChecked( false );
}
void ColorButton::onPaletteDialogChanged( model::ColorNode colorNode, bool isDefault )
{
mColorNode = colorNode;
mIsDefault = isDefault;
if ( colorNode.isField() )
{
setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) );
}
else
{
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
setText( "" );
}
void ColorButton::onPaletteDialogChanged( model::ColorNode colorNode, bool isDefault )
{
mColorNode = colorNode;
mIsDefault = isDefault;
if ( colorNode.isField() )
{
setIcon( QIcon() );
setText( QString("${%1}").arg( colorNode.key() ) );
}
else
{
setIcon( QIcon( ColorSwatch( SWATCH_W, SWATCH_H, colorNode.color() ) ) );
setText( "" );
}
emit colorChanged();
}
emit colorChanged();
}
} // namespace glabels
-105
View File
@@ -1,105 +0,0 @@
/* ColorButton.h
*
* Copyright (C) 2014-2016 Jaye 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 ColorButton_h
#define ColorButton_h
#include "ColorPaletteDialog.h"
#include "model/ColorNode.h"
#include <QPushButton>
namespace glabels
{
///
/// Color Button
///
class ColorButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorButton( QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void init( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton = true );
void setColorNode( model::ColorNode colorNode );
void setColor( QColor color );
void setToDefault();
model::ColorNode colorNode();
void setKeys( const merge::Merge* merge,
const model::Variables& variables );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onButtonToggled( bool checked );
void onPaletteDialogAccepted();
void onPaletteDialogRejected();
void onPaletteDialogChanged( model::ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
bool mIsDefault;
model::ColorNode mColorNode;
ColorPaletteDialog* mDialog;
};
}
#endif // ColorButton_h
+105
View File
@@ -0,0 +1,105 @@
// ColorButton.hpp
//
// Copyright (C) 2014-2016 Jaye 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 ColorButton_hpp
#define ColorButton_hpp
#include "ColorPaletteDialog.hpp"
#include "model/ColorNode.hpp"
#include <QPushButton>
namespace glabels
{
///
/// Color Button
///
class ColorButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorButton( QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void init( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton = true );
void setColorNode( model::ColorNode colorNode );
void setColor( QColor color );
void setToDefault();
model::ColorNode colorNode();
void setKeys( const merge::Merge* merge,
const model::Variables& variables );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onButtonToggled( bool checked );
void onPaletteDialogAccepted();
void onPaletteDialogRejected();
void onPaletteDialogChanged( model::ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
bool mIsDefault;
model::ColorNode mColorNode;
ColorPaletteDialog* mDialog;
};
}
#endif // ColorButton_hpp
+124 -129
View File
@@ -1,155 +1,150 @@
/* ColorHistory.cpp
*
* Copyright (C) 2014-2016 Jaye 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/>.
*/
// ColorHistory.cpp
//
// Copyright (C) 2014-2016 Jaye 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 "ColorHistory.h"
#include "ColorHistory.hpp"
#include <QDebug>
#include <QSettings>
#include <QtDebug>
namespace glabels
{
ColorHistory::ColorHistory()
{
// empty
}
ColorHistory* ColorHistory::instance()
{
static ColorHistory* singletonInstance = nullptr;
if ( singletonInstance == nullptr )
{
singletonInstance = new ColorHistory();
}
return singletonInstance;
}
ColorHistory* ColorHistory::instance()
{
static ColorHistory* singletonInstance = nullptr;
void ColorHistory::addColor( const QColor &color, const QString& name )
{
QString nameColor = name + ":" + color.name();
if ( singletonInstance == nullptr )
{
singletonInstance = new ColorHistory();
}
QStringList nameColorList = readNameColorList();
return singletonInstance;
}
// Remove any occurrences of this color already in list
nameColorList.removeAll( nameColor );
// Now add to list
nameColorList.append( nameColor );
// Remove oldest colors, if size exceeds current max
while ( nameColorList.size() > MAX_COLORS )
{
nameColorList.removeFirst();
}
writeNameColorList( nameColorList );
emit changed();
}
void ColorHistory::addColor( const QColor &color, const QString& name )
{
QString nameColor = name + ":" + color.name();
QList<QColor> ColorHistory::getColors()
{
QList<QColor> colorList;
QStringList nameColorList = readNameColorList();
for ( QString& nameColor : readNameColorList() )
{
QStringList v = nameColor.split( ':' );
if ( v.size() == 2 )
{
colorList << QColor( v[1] );
}
else if ( v.size() == 1 )
{
// Old-style, no name
colorList << QColor( v[0] );
}
else
{
// Should not happen
qWarning() << "Invalid color history.";
}
}
// Remove any occurrences of this color already in list
nameColorList.removeAll( nameColor );
// Now add to list
nameColorList.append( nameColor );
// Remove oldest colors, if size exceeds current max
while ( nameColorList.size() > MAX_COLORS )
{
nameColorList.removeFirst();
}
writeNameColorList( nameColorList );
emit changed();
}
return colorList;
}
QList<QColor> ColorHistory::getColors()
{
QList<QColor> colorList;
for ( QString& nameColor : readNameColorList() )
{
QStringList v = nameColor.split( ':' );
if ( v.size() == 2 )
{
colorList << QColor( v[1] );
}
else if ( v.size() == 1 )
{
// Old-style, no name
colorList << QColor( v[0] );
}
else
{
// Should not happen
qWarning() << "Invalid color history.";
}
}
QStringList ColorHistory::getNames()
{
QStringList nameList;
return colorList;
}
for ( QString& nameColor : readNameColorList() )
{
QStringList v = nameColor.split( ':' );
if ( v.size() == 2 )
{
nameList << v[0];
}
else if ( v.size() == 1 )
{
// Old-style, no name
nameList << QString(tr("color %1")).arg( v[0] );
}
else
{
// Should not happen
qWarning() << "Invalid color history.";
}
}
return nameList;
}
QStringList ColorHistory::getNames()
{
QStringList nameList;
for ( QString& nameColor : readNameColorList() )
{
QStringList v = nameColor.split( ':' );
if ( v.size() == 2 )
{
nameList << v[0];
}
else if ( v.size() == 1 )
{
// Old-style, no name
nameList << QString(tr("color %1")).arg( v[0] );
}
else
{
// Should not happen
qWarning() << "Invalid color history.";
}
}
QStringList ColorHistory::readNameColorList()
{
QStringList defaultList;
QSettings settings;
return nameList;
}
settings.beginGroup( "ColorHistory" );
QStringList nameColorList = settings.value( "colors", defaultList ).toStringList();
settings.endGroup();
// Remove oldest colors, if size exceeds current max
while ( nameColorList.size() > MAX_COLORS )
{
nameColorList.removeFirst();
}
return nameColorList;
}
QStringList ColorHistory::readNameColorList()
{
QStringList defaultList;
QSettings settings;
settings.beginGroup( "ColorHistory" );
QStringList nameColorList = settings.value( "colors", defaultList ).toStringList();
settings.endGroup();
// Remove oldest colors, if size exceeds current max
while ( nameColorList.size() > MAX_COLORS )
{
nameColorList.removeFirst();
}
return nameColorList;
}
void ColorHistory::writeNameColorList( const QStringList& nameColorList )
{
// Save
QSettings settings;
settings.beginGroup( "ColorHistory" );
settings.setValue( "colors", nameColorList );
settings.endGroup();
}
void ColorHistory::writeNameColorList( const QStringList& nameColorList )
{
// Save
QSettings settings;
settings.beginGroup( "ColorHistory" );
settings.setValue( "colors", nameColorList );
settings.endGroup();
}
} // namespace glabels
-86
View File
@@ -1,86 +0,0 @@
/* ColorHistory.h
*
* Copyright (C) 2014-2016 Jaye 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 ColorHistory_h
#define ColorHistory_h
#include <QColor>
#include <QObject>
namespace glabels
{
///
/// Color History
///
class ColorHistory : public QObject
{
Q_OBJECT
public:
static const int MAX_COLORS = 9;
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
ColorHistory();
public:
static ColorHistory* instance();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void changed();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void addColor( const QColor& color, const QString& name );
QList<QColor> getColors();
QStringList getNames();
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
QStringList readNameColorList();
void writeNameColorList( const QStringList& nameColorList );
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
};
}
#endif // ColorHistory_h
+86
View File
@@ -0,0 +1,86 @@
// ColorHistory.hpp
//
// Copyright (C) 2014-2016 Jaye 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 ColorHistory_hpp
#define ColorHistory_hpp
#include <QColor>
#include <QObject>
namespace glabels
{
///
/// Color History
///
class ColorHistory : public QObject
{
Q_OBJECT
public:
static const int MAX_COLORS = 9;
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
ColorHistory() = default;
public:
static ColorHistory* instance();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void changed();
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void addColor( const QColor& color, const QString& name );
QList<QColor> getColors();
QStringList getNames();
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
QStringList readNameColorList();
void writeNameColorList( const QStringList& nameColorList );
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
};
}
#endif // ColorHistory_hpp
+249 -249
View File
@@ -1,316 +1,316 @@
/* ColorPaletteDialog.cpp
*
* Copyright (C) 2014-2016 Jaye 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/>.
*/
// ColorPaletteDialog.cpp
//
// Copyright (C) 2014-2016 Jaye 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 "ColorPaletteDialog.h"
#include "ColorPaletteDialog.hpp"
#include <QColorDialog>
#include <QDebug>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QPushButton>
#include <QStandardItemModel>
#include <QVBoxLayout>
#include <QtDebug>
namespace glabels
{
//
// Static data
//
ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = {
//
// Static data
//
ColorPaletteDialog::ColorTableEntry ColorPaletteDialog::mColorTable[] = {
{ "#ef2929", QT_TRANSLATE_NOOP("Color name", "Light Scarlet Red") },
{ "#fcaf3e", QT_TRANSLATE_NOOP("Color name", "Light Orange") },
{ "#fce94f", QT_TRANSLATE_NOOP("Color name", "Light Butter") },
{ "#8ae234", QT_TRANSLATE_NOOP("Color name", "Light Chameleon") },
{ "#729fcf", QT_TRANSLATE_NOOP("Color name", "Light Sky Blue") },
{ "#ad7fa8", QT_TRANSLATE_NOOP("Color name", "Light Plum") },
{ "#e9b96e", QT_TRANSLATE_NOOP("Color name", "Light Chocolate") },
{ "#888a85", QT_TRANSLATE_NOOP("Color name", "Light Aluminum 1") },
{ "#eeeeec", QT_TRANSLATE_NOOP("Color name", "Light Aluminum 2") },
{ "#ef2929", QT_TRANSLATE_NOOP("Color name", "Light Scarlet Red") },
{ "#fcaf3e", QT_TRANSLATE_NOOP("Color name", "Light Orange") },
{ "#fce94f", QT_TRANSLATE_NOOP("Color name", "Light Butter") },
{ "#8ae234", QT_TRANSLATE_NOOP("Color name", "Light Chameleon") },
{ "#729fcf", QT_TRANSLATE_NOOP("Color name", "Light Sky Blue") },
{ "#ad7fa8", QT_TRANSLATE_NOOP("Color name", "Light Plum") },
{ "#e9b96e", QT_TRANSLATE_NOOP("Color name", "Light Chocolate") },
{ "#888a85", QT_TRANSLATE_NOOP("Color name", "Light Aluminum 1") },
{ "#eeeeec", QT_TRANSLATE_NOOP("Color name", "Light Aluminum 2") },
{ "#cc0000", QT_TRANSLATE_NOOP("Color name", "Scarlet Red") },
{ "#f57900", QT_TRANSLATE_NOOP("Color name", "Orange") },
{ "#edd400", QT_TRANSLATE_NOOP("Color name", "Butter") },
{ "#73d216", QT_TRANSLATE_NOOP("Color name", "Chameleon") },
{ "#3465a4", QT_TRANSLATE_NOOP("Color name", "Sky Blue") },
{ "#75507b", QT_TRANSLATE_NOOP("Color name", "Plum") },
{ "#c17d11", QT_TRANSLATE_NOOP("Color name", "Chocolate") },
{ "#555753", QT_TRANSLATE_NOOP("Color name", "Aluminum 1") },
{ "#d3d7cf", QT_TRANSLATE_NOOP("Color name", "Aluminum 2") },
{ "#cc0000", QT_TRANSLATE_NOOP("Color name", "Scarlet Red") },
{ "#f57900", QT_TRANSLATE_NOOP("Color name", "Orange") },
{ "#edd400", QT_TRANSLATE_NOOP("Color name", "Butter") },
{ "#73d216", QT_TRANSLATE_NOOP("Color name", "Chameleon") },
{ "#3465a4", QT_TRANSLATE_NOOP("Color name", "Sky Blue") },
{ "#75507b", QT_TRANSLATE_NOOP("Color name", "Plum") },
{ "#c17d11", QT_TRANSLATE_NOOP("Color name", "Chocolate") },
{ "#555753", QT_TRANSLATE_NOOP("Color name", "Aluminum 1") },
{ "#d3d7cf", QT_TRANSLATE_NOOP("Color name", "Aluminum 2") },
{ "#a40000", QT_TRANSLATE_NOOP("Color name", "Dark Scarlet Red") },
{ "#ce5c00", QT_TRANSLATE_NOOP("Color name", "Dark Orange") },
{ "#c4a000", QT_TRANSLATE_NOOP("Color name", "Dark Butter") },
{ "#4e9a06", QT_TRANSLATE_NOOP("Color name", "Dark Chameleon") },
{ "#204a87", QT_TRANSLATE_NOOP("Color name", "Dark Sky Blue") },
{ "#5c3566", QT_TRANSLATE_NOOP("Color name", "Dark Plum") },
{ "#8f5902", QT_TRANSLATE_NOOP("Color name", "Dark Chocolate") },
{ "#2e3436", QT_TRANSLATE_NOOP("Color name", "Dark Aluminum 1") },
{ "#babdb6", QT_TRANSLATE_NOOP("Color name", "Dark Aluminum 2") },
{ "#a40000", QT_TRANSLATE_NOOP("Color name", "Dark Scarlet Red") },
{ "#ce5c00", QT_TRANSLATE_NOOP("Color name", "Dark Orange") },
{ "#c4a000", QT_TRANSLATE_NOOP("Color name", "Dark Butter") },
{ "#4e9a06", QT_TRANSLATE_NOOP("Color name", "Dark Chameleon") },
{ "#204a87", QT_TRANSLATE_NOOP("Color name", "Dark Sky Blue") },
{ "#5c3566", QT_TRANSLATE_NOOP("Color name", "Dark Plum") },
{ "#8f5902", QT_TRANSLATE_NOOP("Color name", "Dark Chocolate") },
{ "#2e3436", QT_TRANSLATE_NOOP("Color name", "Dark Aluminum 1") },
{ "#babdb6", QT_TRANSLATE_NOOP("Color name", "Dark Aluminum 2") },
{ "#000000", QT_TRANSLATE_NOOP("Color name", "Black") },
{ "#2e3436", QT_TRANSLATE_NOOP("Color name", "Very Dark Gray") },
{ "#555753", QT_TRANSLATE_NOOP("Color name", "Darker Gray") },
{ "#888a85", QT_TRANSLATE_NOOP("Color name", "Dark Gray") },
{ "#babdb6", QT_TRANSLATE_NOOP("Color name", "Medium Gray") },
{ "#d3d7cf", QT_TRANSLATE_NOOP("Color name", "Light Gray") },
{ "#eeeeec", QT_TRANSLATE_NOOP("Color name", "Lighter Gray") },
{ "#f3f3f3", QT_TRANSLATE_NOOP("Color name", "Very Light Gray") },
{ "#ffffff", QT_TRANSLATE_NOOP("Color name", "White") }
{ "#000000", QT_TRANSLATE_NOOP("Color name", "Black") },
{ "#2e3436", QT_TRANSLATE_NOOP("Color name", "Very Dark Gray") },
{ "#555753", QT_TRANSLATE_NOOP("Color name", "Darker Gray") },
{ "#888a85", QT_TRANSLATE_NOOP("Color name", "Dark Gray") },
{ "#babdb6", QT_TRANSLATE_NOOP("Color name", "Medium Gray") },
{ "#d3d7cf", QT_TRANSLATE_NOOP("Color name", "Light Gray") },
{ "#eeeeec", QT_TRANSLATE_NOOP("Color name", "Lighter Gray") },
{ "#f3f3f3", QT_TRANSLATE_NOOP("Color name", "Very Light Gray") },
{ "#ffffff", QT_TRANSLATE_NOOP("Color name", "White") }
};
};
ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton,
QWidget* parent )
: QDialog( parent )
{
mColorHistory = ColorHistory::instance();
connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) );
ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton,
QWidget* parent )
: QDialog( parent )
{
mColorHistory = ColorHistory::instance();
connect( mColorHistory, SIGNAL(changed()), this, SLOT(onColorHistoryChanged()) );
mDefaultColor = defaultColor;
mColorNode = model::ColorNode( color );
mDefaultColor = defaultColor;
mColorNode = model::ColorNode( color );
setStyleSheet( ".glabels--ColorPaletteDialog {background: white; border: 1px solid black}" );
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
setStyleSheet( ".glabels--ColorPaletteDialog {background: white; border: 1px solid black}" );
setWindowFlags( Qt::Popup | Qt::FramelessWindowHint );
auto* vLayout = new QVBoxLayout();
vLayout->setContentsMargins( 0, 0, 0, 0 );
vLayout->setSpacing( 0 );
auto* vLayout = new QVBoxLayout();
vLayout->setContentsMargins( 0, 0, 0, 0 );
vLayout->setSpacing( 0 );
//
// Construct Standard Colors Grid
//
auto* standardColorsGroup = new QGroupBox( tr("Standard Colors") );
standardColorsGroup->setAlignment( Qt::AlignHCenter );
vLayout->addWidget( standardColorsGroup );
//
// Construct Standard Colors Grid
//
auto* standardColorsGroup = new QGroupBox( tr("Standard Colors") );
standardColorsGroup->setAlignment( Qt::AlignHCenter );
vLayout->addWidget( standardColorsGroup );
auto* mainPaletteLayout = new QGridLayout();
mainPaletteLayout->setSpacing( 0 );
for ( int iRow = 0; iRow < PALETTE_ROWS; iRow++ )
{
for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ )
{
int i = iRow*PALETTE_COLS + iCol;
auto* mainPaletteLayout = new QGridLayout();
mainPaletteLayout->setSpacing( 0 );
for ( int iRow = 0; iRow < PALETTE_ROWS; iRow++ )
{
for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ )
{
int i = iRow*PALETTE_COLS + iCol;
ColorPaletteItem* item = new ColorPaletteItem( i,
QColor( mColorTable[i].colorSpec ),
tr(mColorTable[i].trname) );
connect( item, SIGNAL(activated(int)),
this, SLOT(onPaletteItemActivated(int)) );
ColorPaletteItem* item = new ColorPaletteItem( i,
QColor( mColorTable[i].colorSpec ),
tr(mColorTable[i].trname) );
connect( item, SIGNAL(activated(int)),
this, SLOT(onPaletteItemActivated(int)) );
mainPaletteLayout->addWidget( item, iRow, iCol );
}
}
standardColorsGroup->setLayout( mainPaletteLayout );
mainPaletteLayout->addWidget( item, iRow, iCol );
}
}
standardColorsGroup->setLayout( mainPaletteLayout );
//
// Construct Recent Colors Grid
//
auto* recentColorsGroup = new QGroupBox( tr("Recent Colors") );
recentColorsGroup->setAlignment( Qt::AlignHCenter );
vLayout->addWidget( recentColorsGroup );
//
// Construct Recent Colors Grid
//
auto* recentColorsGroup = new QGroupBox( tr("Recent Colors") );
recentColorsGroup->setAlignment( Qt::AlignHCenter );
vLayout->addWidget( recentColorsGroup );
auto* customPaletteLayout = new QHBoxLayout();
customPaletteLayout->setSpacing( 0 );
for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ )
{
mHistoryItem[iCol] = new ColorPaletteItem( iCol, QColor(0,0,0,0), "" );
mHistoryItem[iCol]->setEnabled( false );
connect( mHistoryItem[iCol], SIGNAL(activated(int)),
this, SLOT(onHistoryItemActivated(int)) );
auto* customPaletteLayout = new QHBoxLayout();
customPaletteLayout->setSpacing( 0 );
for ( int iCol = 0; iCol < PALETTE_COLS; iCol++ )
{
mHistoryItem[iCol] = new ColorPaletteItem( iCol, QColor(0,0,0,0), "" );
mHistoryItem[iCol]->setEnabled( false );
connect( mHistoryItem[iCol], SIGNAL(activated(int)),
this, SLOT(onHistoryItemActivated(int)) );
customPaletteLayout->addWidget( mHistoryItem[iCol] );
}
recentColorsGroup->setLayout( customPaletteLayout );
customPaletteLayout->addWidget( mHistoryItem[iCol] );
}
recentColorsGroup->setLayout( customPaletteLayout );
//
// Construct Default (e.g. "No Fill") Button
//
auto* defaultColorButton = new QPushButton( defaultLabel );
defaultColorButton->setAutoDefault( false );
defaultColorButton->setDefault( false );
connect( defaultColorButton, SIGNAL(clicked()), this, SLOT(onDefaultButtonClicked()) );
vLayout->addWidget( defaultColorButton );
//
// Construct Custom Color Button
//
auto* customColorButton = new QPushButton( tr("Custom color...") );
customColorButton->setAutoDefault( false );
customColorButton->setDefault( false );
connect( customColorButton, SIGNAL(clicked()), this, SLOT(onCustomColorButtonClicked()) );
vLayout->addWidget( customColorButton );
//
// Construct Default (e.g. "No Fill") Button
//
auto* defaultColorButton = new QPushButton( defaultLabel );
defaultColorButton->setAutoDefault( false );
defaultColorButton->setDefault( false );
connect( defaultColorButton, SIGNAL(clicked()), this, SLOT(onDefaultButtonClicked()) );
vLayout->addWidget( defaultColorButton );
//
// Construct "Use field" Button
//
if ( showUseFieldButton )
{
mFieldButton = new FieldButton();
mFieldButton->setText( tr("Use substitution field") );
mFieldButton->setAutoDefault( false );
mFieldButton->setDefault( false );
connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) );
vLayout->addWidget( mFieldButton );
}
else
{
mFieldButton = nullptr;
}
//
// Construct Custom Color Button
//
auto* customColorButton = new QPushButton( tr("Custom color...") );
customColorButton->setAutoDefault( false );
customColorButton->setDefault( false );
connect( customColorButton, SIGNAL(clicked()), this, SLOT(onCustomColorButtonClicked()) );
vLayout->addWidget( customColorButton );
setLayout( vLayout );
//
// Construct "Use field" Button
//
if ( showUseFieldButton )
{
mFieldButton = new FieldButton();
mFieldButton->setText( tr("Use substitution field") );
mFieldButton->setAutoDefault( false );
mFieldButton->setDefault( false );
connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) );
vLayout->addWidget( mFieldButton );
}
else
{
mFieldButton = nullptr;
}
loadCustomColorHistory();
}
setLayout( vLayout );
loadCustomColorHistory();
}
void ColorPaletteDialog::setColorNode( const model::ColorNode& colorNode )
{
mColorNode = colorNode;
}
void ColorPaletteDialog::setColorNode( const model::ColorNode& colorNode )
{
mColorNode = colorNode;
}
void ColorPaletteDialog::setKeys( const merge::Merge* merge,
const model::Variables& variables )
{
if (mFieldButton)
{
mFieldButton->setKeys( merge, variables );
}
}
void ColorPaletteDialog::setKeys( const merge::Merge* merge,
const model::Variables& variables )
{
if (mFieldButton)
{
mFieldButton->setKeys( merge, variables );
}
}
void ColorPaletteDialog::onPaletteItemActivated( int id )
{
model::ColorNode newColorNode;
newColorNode.setField( false );
newColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
newColorNode.setKey( "" );
void ColorPaletteDialog::onPaletteItemActivated( int id )
{
model::ColorNode newColorNode;
newColorNode.setField( false );
newColorNode.setColor( QColor( mColorTable[id].colorSpec ) );
newColorNode.setKey( "" );
if ( newColorNode != mColorNode )
{
mColorNode = newColorNode;
mColorHistory->addColor( mColorNode.color(), mColorTable[id].trname );
if ( newColorNode != mColorNode )
{
mColorNode = newColorNode;
emit colorChanged( mColorNode, false );
accept();
}
}
mColorHistory->addColor( mColorNode.color(), mColorTable[id].trname );
emit colorChanged( mColorNode, false );
accept();
}
}
void ColorPaletteDialog::onHistoryItemActivated( int id )
{
mColorNode.setField( false );
mColorNode.setColor( mColorHistory->getColors()[id] );
mColorNode.setKey( "" );
void ColorPaletteDialog::onHistoryItemActivated( int id )
{
mColorNode.setField( false );
mColorNode.setColor( mColorHistory->getColors()[id] );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, false );
accept();
}
emit colorChanged( mColorNode, false );
accept();
}
void ColorPaletteDialog::onDefaultButtonClicked()
{
mColorNode.setField( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
void ColorPaletteDialog::onDefaultButtonClicked()
{
mColorNode.setField( false );
mColorNode.setColor( mDefaultColor );
mColorNode.setKey( "" );
emit colorChanged( mColorNode, true );
accept();
}
emit colorChanged( mColorNode, true );
accept();
}
void ColorPaletteDialog::onCustomColorButtonClicked()
{
QColorDialog dlg( mColorNode.color(), this );
dlg.setWindowTitle( tr("Custom Color") );
void ColorPaletteDialog::onCustomColorButtonClicked()
{
QColorDialog dlg( mColorNode.color(), this );
dlg.setWindowTitle( tr("Custom Color") );
if ( dlg.exec() )
{
model::ColorNode newColorNode;
if ( dlg.exec() )
{
model::ColorNode newColorNode;
newColorNode.setField( false );
newColorNode.setColor( dlg.currentColor() );
newColorNode.setKey( "" );
newColorNode.setField( false );
newColorNode.setColor( dlg.currentColor() );
newColorNode.setKey( "" );
if ( newColorNode != mColorNode )
{
mColorNode = newColorNode;
// TRANSLATORS
//: %1 = color specification in hex. String must not contain a colon (:).
mColorHistory->addColor( mColorNode.color(),
QString(tr("Custom Color %1")).arg(mColorNode.color().name()) );
if ( newColorNode != mColorNode )
{
mColorNode = newColorNode;
emit colorChanged( mColorNode, false );
accept();
}
}
}
// TRANSLATORS
//: %1 = color specification in hex. String must not contain a colon (:).
mColorHistory->addColor( mColorNode.color(),
QString(tr("Custom Color %1")).arg(mColorNode.color().name()) );
emit colorChanged( mColorNode, false );
accept();
}
}
}
void ColorPaletteDialog::onColorHistoryChanged()
{
loadCustomColorHistory();
}
void ColorPaletteDialog::onColorHistoryChanged()
{
loadCustomColorHistory();
}
void ColorPaletteDialog::loadCustomColorHistory()
{
QStringList nameList = mColorHistory->getNames();
QList<QColor> colorList = mColorHistory->getColors();
int id = 0;
for ( QColor color : colorList )
{
mHistoryItem[id]->setColor( id, color, nameList[id] );
mHistoryItem[id]->setEnabled( true );
id++;
}
void ColorPaletteDialog::loadCustomColorHistory()
{
QStringList nameList = mColorHistory->getNames();
QList<QColor> colorList = mColorHistory->getColors();
while ( id < PALETTE_ROWS )
{
mHistoryItem[id]->setEnabled( false );
id++;
}
}
int id = 0;
for ( QColor color : colorList )
{
mHistoryItem[id]->setColor( id, color, nameList[id] );
mHistoryItem[id]->setEnabled( true );
id++;
}
while ( id < PALETTE_ROWS )
{
mHistoryItem[id]->setEnabled( false );
id++;
}
}
void ColorPaletteDialog::onKeySelected( QString key )
{
mColorNode.setField( true );
mColorNode.setColor( QColor( 0xee, 0xee, 0xec ) );
mColorNode.setKey( key );
void ColorPaletteDialog::onKeySelected( QString key )
{
mColorNode.setField( true );
mColorNode.setColor( QColor( 0xee, 0xee, 0xec ) );
mColorNode.setKey( key );
emit colorChanged( mColorNode, false );
accept();
}
emit colorChanged( mColorNode, false );
accept();
}
} // namespace glabels
-119
View File
@@ -1,119 +0,0 @@
/* ColorPaletteDialog.h
*
* Copyright (C) 2014-2016 Jaye 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 ColorPaletteDialog_h
#define ColorPaletteDialog_h
#include "ColorHistory.h"
#include "ColorPaletteItem.h"
#include "FieldButton.h"
#include "model/ColorNode.h"
#include <QDialog>
namespace glabels
{
///
/// Color Palette Dialog
///
class ColorPaletteDialog : public QDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton = true,
QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged( model::ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setColorNode( const model::ColorNode& colorNode );
void setKeys( const merge::Merge* merge,
const model::Variables& variables );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onPaletteItemActivated( int id );
void onHistoryItemActivated( int id );
void onDefaultButtonClicked();
void onCustomColorButtonClicked();
void onKeySelected( QString key );
void onColorHistoryChanged();
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
void loadCustomColorHistory();
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
model::ColorNode mColorNode;
static const int PALETTE_COLS = ColorHistory::MAX_COLORS;
static const int PALETTE_ROWS = 4;
struct ColorTableEntry {
QString colorSpec;
const char* trname;
};
static ColorTableEntry mColorTable[];
ColorHistory* mColorHistory;
ColorPaletteItem* mHistoryItem[PALETTE_COLS];
FieldButton* mFieldButton;
};
}
#endif // ColorPaletteDialog_h
+119
View File
@@ -0,0 +1,119 @@
// ColorPaletteDialog.hpp
//
// Copyright (C) 2014-2016 Jaye 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 ColorPaletteDialog_hpp
#define ColorPaletteDialog_hpp
#include "ColorHistory.hpp"
#include "ColorPaletteItem.hpp"
#include "FieldButton.hpp"
#include "model/ColorNode.hpp"
#include <QDialog>
namespace glabels
{
///
/// Color Palette Dialog
///
class ColorPaletteDialog : public QDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteDialog( const QString& defaultLabel,
const QColor& defaultColor,
const QColor& color,
bool showUseFieldButton = true,
QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void colorChanged( model::ColorNode colorNode, bool isDefault );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setColorNode( const model::ColorNode& colorNode );
void setKeys( const merge::Merge* merge,
const model::Variables& variables );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onPaletteItemActivated( int id );
void onHistoryItemActivated( int id );
void onDefaultButtonClicked();
void onCustomColorButtonClicked();
void onKeySelected( QString key );
void onColorHistoryChanged();
/////////////////////////////////
// Private Methods
/////////////////////////////////
private:
void loadCustomColorHistory();
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
QColor mDefaultColor;
model::ColorNode mColorNode;
static const int PALETTE_COLS = ColorHistory::MAX_COLORS;
static const int PALETTE_ROWS = 4;
struct ColorTableEntry {
QString colorSpec;
const char* trname;
};
static ColorTableEntry mColorTable[];
ColorHistory* mColorHistory;
ColorPaletteItem* mHistoryItem[PALETTE_COLS];
FieldButton* mFieldButton;
};
}
#endif // ColorPaletteDialog_hpp
+123 -122
View File
@@ -1,146 +1,147 @@
/* ColorPaletteItem.cpp
*
* Copyright (C) 2014 Jaye 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/>.
*/
// ColorPaletteItem.cpp
//
// Copyright (C) 2014 Jaye 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 "ColorPaletteItem.h"
#include "ColorPaletteItem.hpp"
#include <QMouseEvent>
#include <QPainter>
//
// Private
//
namespace
{
const int border = 4;
const int wSwatch = 25;
const int hSwatch = 25;
const int outlineWidthPixels = 1;
}
namespace glabels
{
//
// Private
//
namespace
{
const int border = 4;
const int wSwatch = 25;
const int hSwatch = 25;
const int outlineWidthPixels = 1;
}
///
/// Constructor From Data
///
ColorPaletteItem::ColorPaletteItem( int id,
const QColor& color,
const QString& tip,
QWidget* parent )
: QWidget(parent), mId(id), mColor(color), mTip(tip), mHover(false)
{
setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
setMinimumSize( wSwatch+2*border+1, hSwatch+2*border+1 );
setToolTip( tip );
}
///
/// Constructor From Data
///
ColorPaletteItem::ColorPaletteItem( int id,
const QColor& color,
const QString& tip,
QWidget* parent )
: QWidget(parent), mId(id), mColor(color), mTip(tip), mHover(false)
{
setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ) );
setMinimumSize( wSwatch+2*border+1, hSwatch+2*border+1 );
setToolTip( tip );
}
///
/// Color Property Setter
///
void ColorPaletteItem::setColor( int id,
const QColor& color,
const QString& tip )
{
mId = id;
mColor = color;
mTip = tip;
setToolTip( tip );
update();
}
///
/// Color Property Setter
///
void ColorPaletteItem::setColor( int id,
const QColor& color,
const QString& tip )
{
mId = id;
mColor = color;
mTip = tip;
///
/// Paint Event
///
void ColorPaletteItem::paintEvent( QPaintEvent* event )
{
QPainter painter(this);
setToolTip( tip );
update();
}
//
// Draw swatch
//
if ( isEnabled() )
{
if ( mHover )
{
QPen pen( palette().color( QPalette::Text ) );
pen.setWidth( 2*outlineWidthPixels );
pen.setJoinStyle( Qt::MiterJoin );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( 1, 1, width()-2, height()-2 );
}
else
{
QPen pen( palette().color( QPalette::Text ) );
pen.setWidth( outlineWidthPixels );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch );
}
///
/// Paint Event
///
void ColorPaletteItem::paintEvent( QPaintEvent* event )
{
QPainter painter(this);
}
else
{
QPen pen( palette().color( QPalette::Disabled, QPalette::Text ) );
pen.setWidth( outlineWidthPixels );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch );
}
//
// Draw swatch
//
if ( isEnabled() )
{
if ( mHover )
{
QPen pen( palette().color( QPalette::Text ) );
pen.setWidth( 2*outlineWidthPixels );
pen.setJoinStyle( Qt::MiterJoin );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( 1, 1, width()-2, height()-2 );
}
else
{
QPen pen( palette().color( QPalette::Text ) );
pen.setWidth( outlineWidthPixels );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch );
}
}
else
{
QPen pen( palette().color( QPalette::Disabled, QPalette::Text ) );
pen.setWidth( outlineWidthPixels );
painter.setPen( pen );
painter.setBrush( QBrush( mColor ) );
painter.drawRect( border, border, wSwatch, hSwatch );
}
}
}
///
/// Enter Event
///
void ColorPaletteItem::enterEvent( QEnterEvent* event )
{
mHover = true;
update();
}
///
/// Enter Event
///
void ColorPaletteItem::enterEvent( QEnterEvent* event )
{
mHover = true;
update();
}
///
/// Leave Event
///
void ColorPaletteItem::leaveEvent( QEvent* event )
{
mHover = false;
update();
}
///
/// Leave Event
///
void ColorPaletteItem::leaveEvent( QEvent* event )
{
mHover = false;
update();
}
///
/// Mouse Press Event
///
void ColorPaletteItem::mousePressEvent( QMouseEvent* event )
{
emit activated( mId );
}
///
/// Mouse Press Event
///
void ColorPaletteItem::mousePressEvent( QMouseEvent* event )
{
emit activated( mId );
}
} // namespace glabels
-89
View File
@@ -1,89 +0,0 @@
/* ColorPaletteItem.h
*
* Copyright (C) 2014 Jaye 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 ColorPaletteItem_h
#define ColorPaletteItem_h
#include <QColor>
#include <QWidget>
namespace glabels
{
///
/// Color Palette Item
///
class ColorPaletteItem : public QWidget
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteItem( int id,
const QColor& color,
const QString& tip,
QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( int id );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setColor( int id,
const QColor& color,
const QString& tip );
/////////////////////////////////
// Event handlers
/////////////////////////////////
protected:
void paintEvent( QPaintEvent* event ) override;
void enterEvent( QEnterEvent* event ) override;
void leaveEvent( QEvent* event ) override;
void mousePressEvent( QMouseEvent* event ) override;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
int mId;
QColor mColor;
QString mTip;
bool mHover;
};
}
#endif // ColorPaletteItem_h
+89
View File
@@ -0,0 +1,89 @@
// ColorPaletteItem.hpp
//
// Copyright (C) 2014 Jaye 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 ColorPaletteItem_hpp
#define ColorPaletteItem_hpp
#include <QColor>
#include <QWidget>
namespace glabels
{
///
/// Color Palette Item
///
class ColorPaletteItem : public QWidget
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorPaletteItem( int id,
const QColor& color,
const QString& tip,
QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void activated( int id );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setColor( int id,
const QColor& color,
const QString& tip );
/////////////////////////////////
// Event handlers
/////////////////////////////////
protected:
void paintEvent( QPaintEvent* event ) override;
void enterEvent( QEnterEvent* event ) override;
void leaveEvent( QEvent* event ) override;
void mousePressEvent( QMouseEvent* event ) override;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
int mId;
QColor mColor;
QString mTip;
bool mHover;
};
}
#endif // ColorPaletteItem_hpp
+47 -46
View File
@@ -1,60 +1,61 @@
/* ColorSwatch.cpp
*
* Copyright (C) 2014 Jaye 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/>.
*/
// ColorSwatch.cpp
//
// Copyright (C) 2014 Jaye 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 "ColorSwatch.hpp"
#include <QPainter>
//
// Private
//
namespace
{
const QColor outlineColor( 0, 0, 0 );
const double outlineWidthPixels = 1;
}
namespace glabels
{
//
// Private
//
namespace
{
const QColor outlineColor( 0, 0, 0 );
const double outlineWidthPixels = 1;
}
///
/// Constructor
///
ColorSwatch::ColorSwatch( int w, int h, const QColor& color )
: QPixmap( w, h )
{
fill( Qt::transparent );
QPainter painter(this );
///
/// Constructor
///
ColorSwatch::ColorSwatch( int w, int h, const QColor& color )
: QPixmap( w, h )
{
fill( Qt::transparent );
painter.setBackgroundMode( Qt::TransparentMode );
QPainter painter(this );
QBrush brush( color );
QPen pen( outlineColor );
pen.setWidth( outlineWidthPixels );
painter.setBackgroundMode( Qt::TransparentMode );
QBrush brush( color );
QPen pen( outlineColor );
pen.setWidth( outlineWidthPixels );
painter.setBrush( brush );
painter.setPen( pen );
painter.drawRect( 1, 1, w-2, h-2 );
}
painter.setBrush( brush );
painter.setPen( pen );
painter.drawRect( 1, 1, w-2, h-2 );
}
} // namespace glabels
-48
View File
@@ -1,48 +0,0 @@
/* ColorSwatch.h
*
* Copyright (C) 2014 Jaye 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 ColorSwatch_h
#define ColorSwatch_h
#include <QPixmap>
namespace glabels
{
///
/// Simple Preview Widget
///
class ColorSwatch : public QPixmap
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorSwatch( int w, int h, const QColor& color );
};
}
#endif // ColorSwatch_h
+48
View File
@@ -0,0 +1,48 @@
// ColorSwatch.hpp
//
// Copyright (C) 2014 Jaye 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 ColorSwatch_hpp
#define ColorSwatch_hpp
#include <QPixmap>
namespace glabels
{
///
/// Simple Preview Widget
///
class ColorSwatch : public QPixmap
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ColorSwatch( int w, int h, const QColor& color );
};
}
#endif // ColorSwatch_hpp
+61 -60
View File
@@ -1,24 +1,25 @@
/* Cursors.cpp
*
* Copyright (C) 2013 Jaye 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/>.
*/
// Cursors.cpp
//
// Copyright (C) 2013 Jaye 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 "Cursors.h"
#include "Cursors.hpp"
#include <QPixmap>
@@ -26,59 +27,59 @@
namespace glabels
{
Cursors::Crosshair::Crosshair()
: QCursor( QPixmap(":cursors/32x32/cursor_crosshair.png"), 15, 15 )
{
// empty
}
Cursors::Crosshair::Crosshair()
: QCursor( QPixmap(":cursors/32x32/cursor_crosshair.png"), 15, 15 )
{
// empty
}
Cursors::Move::Move()
: QCursor( QPixmap(":cursors/32x32/cursor_move.png"), 15, 15 )
{
// empty
}
Cursors::Move::Move()
: QCursor( QPixmap(":cursors/32x32/cursor_move.png"), 15, 15 )
{
// empty
}
Cursors::Barcode::Barcode()
: QCursor( QPixmap(":cursors/32x32/cursor_barcode.png"), 7, 7 )
{
// empty
}
Cursors::Barcode::Barcode()
: QCursor( QPixmap(":cursors/32x32/cursor_barcode.png"), 7, 7 )
{
// empty
}
Cursors::Box::Box()
: QCursor( QPixmap(":cursors/32x32/cursor_box.png"), 7, 7 )
{
// empty
}
Cursors::Box::Box()
: QCursor( QPixmap(":cursors/32x32/cursor_box.png"), 7, 7 )
{
// empty
}
Cursors::Ellipse::Ellipse()
: QCursor( QPixmap(":cursors/32x32/cursor_ellipse.png"), 7, 7 )
{
// empty
}
Cursors::Ellipse::Ellipse()
: QCursor( QPixmap(":cursors/32x32/cursor_ellipse.png"), 7, 7 )
{
// empty
}
Cursors::Image::Image()
: QCursor( QPixmap(":cursors/32x32/cursor_image.png"), 7, 7 )
{
// empty
}
Cursors::Image::Image()
: QCursor( QPixmap(":cursors/32x32/cursor_image.png"), 7, 7 )
{
// empty
}
Cursors::Line::Line()
: QCursor( QPixmap(":cursors/32x32/cursor_line.png"), 7, 7 )
{
// empty
}
Cursors::Line::Line()
: QCursor( QPixmap(":cursors/32x32/cursor_line.png"), 7, 7 )
{
// empty
}
Cursors::Text::Text()
: QCursor( QPixmap(":cursors/32x32/cursor_text.png"), 7, 7 )
{
// empty
}
Cursors::Text::Text()
: QCursor( QPixmap(":cursors/32x32/cursor_text.png"), 7, 7 )
{
// empty
}
} // namespace glabels
-98
View File
@@ -1,98 +0,0 @@
/* Cursors.h
*
* Copyright (C) 2013 Jaye 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 Cursors_h
#define Cursors_h
#include <QCursor>
namespace glabels
{
///
/// Glabels Cursors
///
namespace Cursors
{
class Crosshair : public QCursor
{
public:
Crosshair();
};
class Move : public QCursor
{
public:
Move();
};
class Barcode : public QCursor
{
public:
Barcode();
};
class Box : public QCursor
{
public:
Box();
};
class Ellipse : public QCursor
{
public:
Ellipse();
};
class Image : public QCursor
{
public:
Image();
};
class Line : public QCursor
{
public:
Line();
};
class Text : public QCursor
{
public:
Text();
};
}
}
#endif // Cursors_h
+98
View File
@@ -0,0 +1,98 @@
// Cursors.hpp
//
// Copyright (C) 2013 Jaye 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 Cursors_hpp
#define Cursors_hpp
#include <QCursor>
namespace glabels
{
///
/// Glabels Cursors
///
namespace Cursors
{
class Crosshair : public QCursor
{
public:
Crosshair();
};
class Move : public QCursor
{
public:
Move();
};
class Barcode : public QCursor
{
public:
Barcode();
};
class Box : public QCursor
{
public:
Box();
};
class Ellipse : public QCursor
{
public:
Ellipse();
};
class Image : public QCursor
{
public:
Image();
};
class Line : public QCursor
{
public:
Line();
};
class Text : public QCursor
{
public:
Text();
};
}
}
#endif // Cursors_hpp
+188 -187
View File
@@ -1,220 +1,221 @@
/* EditVariableDialog.cpp
*
* Copyright (C) 2019 Jaye 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/>.
*/
// EditVariableDialog.cpp
//
// Copyright (C) 2019 Jaye 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 "EditVariableDialog.h"
#include "model/Settings.h"
#include "EditVariableDialog.hpp"
#include "model/Settings.hpp"
#include <QPushButton>
namespace
{
// All variable types. (must be in sorted order)
const QVector<glabels::model::Variable::Type> allTypes = {
glabels::model::Variable::Type::STRING,
glabels::model::Variable::Type::INTEGER,
glabels::model::Variable::Type::FLOATING_POINT,
glabels::model::Variable::Type::COLOR
};
// All variable types. (must be in sorted order)
const QVector<glabels::model::Variable::Type> allTypes = {
glabels::model::Variable::Type::STRING,
glabels::model::Variable::Type::INTEGER,
glabels::model::Variable::Type::FLOATING_POINT,
glabels::model::Variable::Type::COLOR
};
// All variable increments. (must be in sorted order)
const QVector<glabels::model::Variable::Increment> allIncrements = {
glabels::model::Variable::Increment::NEVER,
glabels::model::Variable::Increment::PER_ITEM,
glabels::model::Variable::Increment::PER_COPY,
glabels::model::Variable::Increment::PER_PAGE
};
// All variable increments. (must be in sorted order)
const QVector<glabels::model::Variable::Increment> allIncrements = {
glabels::model::Variable::Increment::NEVER,
glabels::model::Variable::Increment::PER_ITEM,
glabels::model::Variable::Increment::PER_COPY,
glabels::model::Variable::Increment::PER_PAGE
};
}
namespace glabels
{
///
/// Constructor
///
EditVariableDialog::EditVariableDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
///
/// Constructor
///
EditVariableDialog::EditVariableDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
QRegularExpression reIdentifier( "[a-zA-Z_][a-zA-Z_0-9]*" );
nameEdit->setValidator( new QRegularExpressionValidator( reIdentifier ) );
QRegularExpression reIdentifier( "[a-zA-Z_][a-zA-Z_0-9]*" );
nameEdit->setValidator( new QRegularExpressionValidator( reIdentifier ) );
colorValueButton->init( tr("Default"),
QColor(0,0,0,255),
QColor(0,0,0,255),
false );
for ( auto type : allTypes )
{
typeCombo->addItem( model::Variable::typeToI18nString( type ) );
}
colorValueButton->init( tr("Default"),
QColor(0,0,0,255),
QColor(0,0,0,255),
false );
for ( auto type : allIncrements )
{
incrementCombo->addItem( model::Variable::incrementToI18nString( type ) );
}
for ( auto type : allTypes )
{
typeCombo->addItem( model::Variable::typeToI18nString( type ) );
}
stepSizeEdit->setText( "1" );
}
for ( auto type : allIncrements )
{
incrementCombo->addItem( model::Variable::incrementToI18nString( type ) );
}
stepSizeEdit->setText( "1" );
}
///
/// Set variable
///
void EditVariableDialog::setVariable( const model::Variable& variable )
{
typeCombo->setCurrentIndex( static_cast<int>(variable.type()) );
nameEdit->setText( variable.name() );
valueEdit->setText( variable.initialValue() );
colorValueButton->setColor( QColor( variable.initialValue() ) );
incrementCombo->setCurrentIndex( static_cast<int>(variable.increment()) );
stepSizeEdit->setText( variable.stepSize() );
///
/// Set variable
///
void EditVariableDialog::setVariable( const model::Variable& variable )
{
typeCombo->setCurrentIndex( static_cast<int>(variable.type()) );
nameEdit->setText( variable.name() );
valueEdit->setText( variable.initialValue() );
colorValueButton->setColor( QColor( variable.initialValue() ) );
incrementCombo->setCurrentIndex( static_cast<int>(variable.increment()) );
stepSizeEdit->setText( variable.stepSize() );
updateControls();
}
updateControls();
}
///
/// Get variable
///
model::Variable EditVariableDialog::variable() const
{
return model::Variable( static_cast<model::Variable::Type>(typeCombo->currentIndex()),
nameEdit->text(),
valueEdit->text(),
static_cast<model::Variable::Increment>(incrementCombo->currentIndex()),
stepSizeEdit->text() );
}
///
/// Get variable
///
model::Variable EditVariableDialog::variable() const
{
return model::Variable( static_cast<model::Variable::Type>(typeCombo->currentIndex()),
nameEdit->text(),
valueEdit->text(),
static_cast<model::Variable::Increment>(incrementCombo->currentIndex()),
stepSizeEdit->text() );
}
///
/// nameEdit Changed
///
void EditVariableDialog::onNameEditChanged()
{
validateCurrentInputs();
}
///
/// typeCombo Changed
///
void EditVariableDialog::onTypeComboChanged()
{
updateControls();
}
///
/// valueEdit Changed
///
void EditVariableDialog::onValueEditChanged()
{
validateCurrentInputs();
}
///
/// colorValueButton Changed
///
void EditVariableDialog::onColorValueButtonChanged()
{
valueEdit->setText( colorValueButton->colorNode().color().name() );
validateCurrentInputs();
}
///
/// incrementCombo Changed
///
void EditVariableDialog::onIncrementComboChanged()
{
updateControls();
}
///
/// stepSizeEdit Changed
///
void EditVariableDialog::onStepSizeEditChanged()
{
validateCurrentInputs();
}
///
/// nameEdit Changed
///
void EditVariableDialog::onNameEditChanged()
{
validateCurrentInputs();
}
///
/// update controls
///
void EditVariableDialog::updateControls()
{
auto type = static_cast<model::Variable::Type>(typeCombo->currentIndex());
auto increment = static_cast<model::Variable::Increment>(incrementCombo->currentIndex());
switch (type)
{
case model::Variable::Type::INTEGER:
valueEdit->setValidator( new QIntValidator() );
stepSizeEdit->setValidator( new QIntValidator() );
break;
case model::Variable::Type::FLOATING_POINT:
valueEdit->setValidator( new QDoubleValidator() );
stepSizeEdit->setValidator( new QDoubleValidator() );
break;
default:
valueEdit->setValidator( nullptr );
stepSizeEdit->setValidator( nullptr );
break;
}
colorValueButton->setVisible( type == model::Variable::Type::COLOR );
bool isNumeric = ( type == model::Variable::Type::INTEGER ) ||
( type == model::Variable::Type::FLOATING_POINT );
incrementGroup->setVisible( isNumeric );
stepSizeLabel->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) );
stepSizeEdit->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) );
validateCurrentInputs();
}
///
/// typeCombo Changed
///
void EditVariableDialog::onTypeComboChanged()
{
updateControls();
}
///
/// validate current inputs
///
void EditVariableDialog::validateCurrentInputs()
{
bool hasValidIdentifier = nameEdit->hasAcceptableInput();
bool hasValidValue = valueEdit->hasAcceptableInput();
bool hasValidStepSize = stepSizeEdit->hasAcceptableInput();
///
/// valueEdit Changed
///
void EditVariableDialog::onValueEditChanged()
{
validateCurrentInputs();
}
///
/// colorValueButton Changed
///
void EditVariableDialog::onColorValueButtonChanged()
{
valueEdit->setText( colorValueButton->colorNode().color().name() );
validateCurrentInputs();
}
///
/// incrementCombo Changed
///
void EditVariableDialog::onIncrementComboChanged()
{
updateControls();
}
///
/// stepSizeEdit Changed
///
void EditVariableDialog::onStepSizeEditChanged()
{
validateCurrentInputs();
}
///
/// update controls
///
void EditVariableDialog::updateControls()
{
auto type = static_cast<model::Variable::Type>(typeCombo->currentIndex());
auto increment = static_cast<model::Variable::Increment>(incrementCombo->currentIndex());
switch (type)
{
case model::Variable::Type::INTEGER:
valueEdit->setValidator( new QIntValidator() );
stepSizeEdit->setValidator( new QIntValidator() );
break;
case model::Variable::Type::FLOATING_POINT:
valueEdit->setValidator( new QDoubleValidator() );
stepSizeEdit->setValidator( new QDoubleValidator() );
break;
default:
valueEdit->setValidator( nullptr );
stepSizeEdit->setValidator( nullptr );
break;
}
colorValueButton->setVisible( type == model::Variable::Type::COLOR );
bool isNumeric = ( type == model::Variable::Type::INTEGER ) ||
( type == model::Variable::Type::FLOATING_POINT );
incrementGroup->setVisible( isNumeric );
stepSizeLabel->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) );
stepSizeEdit->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) );
validateCurrentInputs();
}
///
/// validate current inputs
///
void EditVariableDialog::validateCurrentInputs()
{
bool hasValidIdentifier = nameEdit->hasAcceptableInput();
bool hasValidValue = valueEdit->hasAcceptableInput();
bool hasValidStepSize = stepSizeEdit->hasAcceptableInput();
bool isValid = hasValidIdentifier && hasValidValue && hasValidStepSize;
buttonBox->button(QDialogButtonBox::Ok)->setEnabled( isValid );
}
bool isValid = hasValidIdentifier && hasValidValue && hasValidStepSize;
buttonBox->button(QDialogButtonBox::Ok)->setEnabled( isValid );
}
} // namespace glabels
-76
View File
@@ -1,76 +0,0 @@
/* EditVariableDialog.h
*
* Copyright (C) 2019 Jaye 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 EditVariableDialog_h
#define EditVariableDialog_h
#include "ui_EditVariableDialog.h"
#include "model/Variable.h"
namespace glabels
{
///
/// New Label Dialog Widget
///
class EditVariableDialog : public QDialog, public Ui_EditVariableDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
EditVariableDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Public methods
/////////////////////////////////
void setVariable( const model::Variable& variable );
model::Variable variable() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onNameEditChanged();
void onTypeComboChanged();
void onValueEditChanged();
void onColorValueButtonChanged();
void onIncrementComboChanged();
void onStepSizeEditChanged();
/////////////////////////////////
// Private methods
/////////////////////////////////
void updateControls();
void validateCurrentInputs();
};
}
#endif // EditVariableDialog_h
+77
View File
@@ -0,0 +1,77 @@
// EditVariableDialog.hpp
//
// Copyright (C) 2019 Jaye 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 EditVariableDialog_hpp
#define EditVariableDialog_hpp
#include "ui_EditVariableDialog.h"
#include "model/Variable.hpp"
namespace glabels
{
///
/// New Label Dialog Widget
///
class EditVariableDialog : public QDialog, public Ui_EditVariableDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
EditVariableDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Public methods
/////////////////////////////////
void setVariable( const model::Variable& variable );
model::Variable variable() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onNameEditChanged();
void onTypeComboChanged();
void onValueEditChanged();
void onColorValueButtonChanged();
void onIncrementComboChanged();
void onStepSizeEditChanged();
/////////////////////////////////
// Private methods
/////////////////////////////////
void updateControls();
void validateCurrentInputs();
};
}
#endif // EditVariableDialog_hpp
+74 -73
View File
@@ -1,24 +1,25 @@
/* FieldButton.cpp
*
* Copyright (C) 2019 Jaye 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/>.
*/
// FieldButton.cpp
//
// Copyright (C) 2019 Jaye 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 "FieldButton.h"
#include "FieldButton.hpp"
#include <QLineEdit>
#include <QStandardItemModel>
@@ -27,64 +28,64 @@
namespace glabels
{
///
/// Constructor
///
FieldButton::FieldButton( QWidget* parent ) : QPushButton(parent)
{
setEnabled( false );
setMenu( &mMenu );
connect( &mMenu, SIGNAL(triggered(QAction*)),
this, SLOT(onMenuActionTriggered(QAction*)) );
}
///
/// Constructor
///
FieldButton::FieldButton( QWidget* parent ) : QPushButton(parent)
{
setEnabled( false );
setMenu( &mMenu );
connect( &mMenu, SIGNAL(triggered(QAction*)),
this, SLOT(onMenuActionTriggered(QAction*)) );
}
///
/// Set Keys
///
void FieldButton::setKeys( const merge::Merge* merge,
const model::Variables& variables )
{
// Clear old keys
mMenu.clear();
// Add merge keys, if any
mMenu.addSection( tr("Merge fields") );
for ( auto& key : merge->keys() )
{
auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) );
action->setData( key );
}
if ( merge->keys().empty() )
{
auto* action = mMenu.addAction( "None" );
action->setEnabled( false );
}
///
/// Set Keys
///
void FieldButton::setKeys( const merge::Merge* merge,
const model::Variables& variables )
{
// Clear old keys
mMenu.clear();
// Add variable keys, if any
mMenu.addSection( tr("Variables") );
for ( auto& key : variables.keys() )
{
auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) );
action->setData( key );
}
if ( variables.keys().empty() )
{
auto* action = mMenu.addAction( "None" );
action->setEnabled( false );
}
// Add merge keys, if any
mMenu.addSection( tr("Merge fields") );
for ( auto& key : merge->keys() )
{
auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) );
action->setData( key );
}
if ( merge->keys().empty() )
{
auto* action = mMenu.addAction( "None" );
action->setEnabled( false );
}
setEnabled( !merge->keys().empty() || !variables.keys().empty() );
}
// Add variable keys, if any
mMenu.addSection( tr("Variables") );
for ( auto& key : variables.keys() )
{
auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) );
action->setData( key );
}
if ( variables.keys().empty() )
{
auto* action = mMenu.addAction( "None" );
action->setEnabled( false );
}
setEnabled( !merge->keys().empty() || !variables.keys().empty() );
}
///
/// onMenuActionTriggered slot
///
void FieldButton::onMenuActionTriggered( QAction* action )
{
emit keySelected( action->data().toString() );
}
///
/// onMenuActionTriggered slot
///
void FieldButton::onMenuActionTriggered( QAction* action )
{
emit keySelected( action->data().toString() );
}
} // namespace glabels
-84
View File
@@ -1,84 +0,0 @@
/* FieldButton.h
*
* Copyright (C) 2019 Jaye 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 FieldButton_h
#define FieldButton_h
#include "model/Variables.h"
#include "merge/Merge.h"
#include <QAction>
#include <QPushButton>
#include <QMenu>
#include <QStringList>
namespace glabels
{
///
/// Field Button
///
class FieldButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldButton( QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void keySelected( QString key );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setKeys( const merge::Merge* merge,
const model::Variables& variables );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuActionTriggered( QAction* action );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QMenu mMenu;
};
}
#endif // FieldButton_h
+84
View File
@@ -0,0 +1,84 @@
// FieldButton.hpp
//
// Copyright (C) 2019 Jaye 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 FieldButton_hpp
#define FieldButton_hpp
#include "model/Variables.hpp"
#include "merge/Merge.hpp"
#include <QAction>
#include <QPushButton>
#include <QMenu>
#include <QStringList>
namespace glabels
{
///
/// Field Button
///
class FieldButton : public QPushButton
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
FieldButton( QWidget* parent = nullptr );
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void keySelected( QString key );
/////////////////////////////////
// Public Methods
/////////////////////////////////
public:
void setKeys( const merge::Merge* merge,
const model::Variables& variables );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMenuActionTriggered( QAction* action );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QMenu mMenu;
};
}
#endif // FieldButton_hpp
+260 -259
View File
@@ -1,301 +1,302 @@
/* File.cpp
*
* Copyright (C) 2014 Jaye 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/>.
*/
// File.cpp
//
// Copyright (C) 2014 Jaye 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 "MainWindow.h"
#include "SelectProductDialog.h"
#include "TemplateDesigner.h"
#include "File.hpp"
#include "model/FileUtil.h"
#include "model/Model.h"
#include "model/Settings.h"
#include "model/XmlLabelParser.h"
#include "model/XmlLabelCreator.h"
#include "MainWindow.hpp"
#include "SelectProductDialog.hpp"
#include "TemplateDesigner.hpp"
#include "model/FileUtil.hpp"
#include "model/Model.hpp"
#include "model/Settings.hpp"
#include "model/XmlLabelParser.hpp"
#include "model/XmlLabelCreator.hpp"
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
#include <QtDebug>
namespace glabels
{
//
// Static data
//
QString File::mCwd = ".";
//
// Static data
//
QString File::mCwd = ".";
///
/// New Label Dialog
///
bool File::newLabel( MainWindow *window )
{
SelectProductDialog dialog( window );
dialog.exec();
///
/// New Label Dialog
///
bool File::newLabel( MainWindow *window )
{
SelectProductDialog dialog( window );
dialog.exec();
auto tmplate = dialog.tmplate();
if ( !tmplate.isNull() )
{
auto* model = new model::Model();
model->setTmplate( tmplate );
// Intelligently decide to rotate label by default
auto frame = tmplate.frame();
model->setRotate( frame->h() > frame->w() );
auto tmplate = dialog.tmplate();
if ( !tmplate.isNull() )
{
auto* model = new model::Model();
model->setTmplate( tmplate );
model->clearModified();
// Intelligently decide to rotate label by default
auto frame = tmplate.frame();
model->setRotate( frame->h() > frame->w() );
// Either apply to current window or open a new one
if ( window->isEmpty() )
{
window->setModel( model );
}
else
{
auto *newWindow = new MainWindow();
newWindow->setModel( model );
newWindow->show();
}
model->clearModified();
return true;
}
else
{
return false;
}
}
// Either apply to current window or open a new one
if ( window->isEmpty() )
{
window->setModel( model );
}
else
{
auto *newWindow = new MainWindow();
newWindow->setModel( model );
newWindow->show();
}
return true;
}
else
{
return false;
}
}
///
/// Open File Dialog
///
void File::open( MainWindow *window )
{
// Either use the saved CWD from a previous open/save or grab it from the path of the current file
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
cwd = fileInfo.absolutePath();
}
}
QString fileName =
QFileDialog::getOpenFileName( window,
tr("gLabels - Open Project"),
cwd,
tr("glabels files (*.glabels);;All files (*)")
);
if ( !fileName.isEmpty() )
{
model::Model *model = model::XmlLabelParser::readFile( fileName );
if ( model )
{
// Either apply to current window or open a new one
if ( window->isEmpty() )
{
window->setModel( model );
}
else
{
auto *newWindow = new MainWindow();
newWindow->setModel( model );
newWindow->show();
}
model::Settings::addToRecentFileList( model->fileName() );
///
/// Open File Dialog
///
void File::open( MainWindow *window )
{
// Either use the saved CWD from a previous open/save or grab it from the path of the current file
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
cwd = fileInfo.absolutePath();
}
}
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
}
else
{
model::Settings::removeFromRecentFileList( fileName );
QString fileName =
QFileDialog::getOpenFileName( window,
tr("gLabels - Open Project"),
cwd,
tr("glabels files (*.glabels);;All files (*)")
);
if ( !fileName.isEmpty() )
{
model::Model *model = model::XmlLabelParser::readFile( fileName );
if ( model )
{
// Either apply to current window or open a new one
if ( window->isEmpty() )
{
window->setModel( model );
}
else
{
auto *newWindow = new MainWindow();
newWindow->setModel( model );
newWindow->show();
}
model::Settings::addToRecentFileList( model->fileName() );
QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
msgBox.setDefaultButton( QMessageBox::Ok );
msgBox.exec();
}
}
}
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
}
else
{
model::Settings::removeFromRecentFileList( fileName );
QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
msgBox.setDefaultButton( QMessageBox::Ok );
msgBox.exec();
}
}
}
///
/// Open file
///
void File::open( const QString& fileName, MainWindow *window )
{
if ( !fileName.isEmpty() )
{
model::Model *model = model::XmlLabelParser::readFile( fileName );
if ( model )
{
// Either apply to current window or open a new one
if ( window->isEmpty() )
{
window->setModel( model );
}
else
{
auto *newWindow = new MainWindow();
newWindow->setModel( model );
newWindow->show();
}
model::Settings::addToRecentFileList( model->fileName() );
///
/// Open file
///
void File::open( const QString& fileName, MainWindow *window )
{
if ( !fileName.isEmpty() )
{
model::Model *model = model::XmlLabelParser::readFile( fileName );
if ( model )
{
// Either apply to current window or open a new one
if ( window->isEmpty() )
{
window->setModel( model );
}
else
{
auto *newWindow = new MainWindow();
newWindow->setModel( model );
newWindow->show();
}
model::Settings::addToRecentFileList( model->fileName() );
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
}
else
{
model::Settings::removeFromRecentFileList( fileName );
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
}
else
{
model::Settings::removeFromRecentFileList( fileName );
QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
msgBox.setDefaultButton( QMessageBox::Ok );
msgBox.exec();
}
}
}
QMessageBox msgBox;
msgBox.setText( tr("Unable to open \"") + fileName + tr("\".") );
msgBox.setStandardButtons( QMessageBox::Ok );
msgBox.setDefaultButton( QMessageBox::Ok );
msgBox.exec();
}
}
}
///
/// Save file
///
bool File::save( MainWindow *window )
{
if ( window->model()->fileName().isEmpty() )
{
return saveAs( window );
}
///
/// Save file
///
bool File::save( MainWindow *window )
{
if ( window->model()->fileName().isEmpty() )
{
return saveAs( window );
}
if ( !window->model()->isModified() )
{
return true;
}
if ( !window->model()->isModified() )
{
return true;
}
model::XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
model::Settings::addToRecentFileList( window->model()->fileName() );
model::XmlLabelCreator::writeFile( window->model(), window->model()->fileName() );
model::Settings::addToRecentFileList( window->model()->fileName() );
// Save CWD
mCwd = QFileInfo( window->model()->fileName() ).absolutePath();
// Save CWD
mCwd = QFileInfo( window->model()->fileName() ).absolutePath();
return true;
}
return true;
}
///
/// Save file as
///
bool File::saveAs( MainWindow *window )
{
// Either use the saved CWD from a previous open/save or grab it from the path
// of the current file.
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
cwd = fileInfo.filePath();
}
}
QString rawFileName =
QFileDialog::getSaveFileName( window,
tr("gLabels - Save Project As"),
cwd,
tr("glabels files (*.glabels);;All files (*)"),
nullptr,
QFileDialog::DontConfirmOverwrite );
if ( !rawFileName.isEmpty() )
{
QString fileName = model::FileUtil::addExtension( rawFileName, ".glabels" );
if ( QFileInfo::exists(fileName) )
{
QMessageBox msgBox( window );
msgBox.setWindowTitle( tr("Save Label As") );
msgBox.setIcon( QMessageBox::Warning );
msgBox.setText( tr("%1 already exists.").arg(fileName) );
msgBox.setInformativeText( tr("Do you want to replace it?") );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
msgBox.setDefaultButton( QMessageBox::No );
///
/// Save file as
///
bool File::saveAs( MainWindow *window )
{
// Either use the saved CWD from a previous open/save or grab it from the path
// of the current file.
QString cwd = mCwd;
if ( window->model() && !window->model()->fileName().isEmpty() )
{
QFileInfo fileInfo( window->model()->fileName() );
if ( fileInfo.isFile() )
{
cwd = fileInfo.filePath();
}
}
if ( msgBox.exec() == QMessageBox::No )
{
return saveAs( window );
}
}
model::XmlLabelCreator::writeFile( window->model(), fileName );
model::Settings::addToRecentFileList( window->model()->fileName() );
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
return true;
}
return false;
}
QString rawFileName =
QFileDialog::getSaveFileName( window,
tr("gLabels - Save Project As"),
cwd,
tr("glabels files (*.glabels);;All files (*)"),
nullptr,
QFileDialog::DontConfirmOverwrite );
if ( !rawFileName.isEmpty() )
{
QString fileName = model::FileUtil::addExtension( rawFileName, ".glabels" );
///
/// Template Designer
///
void File::templateDesigner( MainWindow *window )
{
TemplateDesigner dialog( window );
dialog.exec();
}
if ( QFileInfo::exists(fileName) )
{
QMessageBox msgBox( window );
msgBox.setWindowTitle( tr("Save Label As") );
msgBox.setIcon( QMessageBox::Warning );
msgBox.setText( tr("%1 already exists.").arg(fileName) );
msgBox.setInformativeText( tr("Do you want to replace it?") );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
msgBox.setDefaultButton( QMessageBox::No );
if ( msgBox.exec() == QMessageBox::No )
{
return saveAs( window );
}
}
model::XmlLabelCreator::writeFile( window->model(), fileName );
model::Settings::addToRecentFileList( window->model()->fileName() );
// Save CWD
mCwd = QFileInfo( fileName ).absolutePath();
return true;
}
return false;
}
///
/// Close file
///
void File::close( MainWindow *window )
{
window->close();
}
///
/// Template Designer
///
void File::templateDesigner( MainWindow *window )
{
TemplateDesigner dialog( window );
dialog.exec();
}
///
/// Exit, closing all windows
///
void File::exit()
{
for ( QWidget* qwidget : QApplication::topLevelWidgets() )
{
if ( auto* window = qobject_cast<MainWindow*>(qwidget) )
{
window->close();
}
}
}
///
/// Close file
///
void File::close( MainWindow *window )
{
window->close();
}
///
/// Exit, closing all windows
///
void File::exit()
{
for ( QWidget* qwidget : QApplication::topLevelWidgets() )
{
if ( auto* window = qobject_cast<MainWindow*>(qwidget) )
{
window->close();
}
}
}
} // namespace glabels
-62
View File
@@ -1,62 +0,0 @@
/* File.h
*
* Copyright (C) 2017 Jaye 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 File_h
#define File_h
#include <QObject>
namespace glabels
{
// Forward References
class MainWindow;
///
/// File Actions
///
/// Note: class provides a translation context for these static functions.
///
class File : public QObject
{
Q_OBJECT
public:
static bool newLabel( MainWindow *window = nullptr );
static void open( MainWindow *window );
static void open( const QString& fileName, MainWindow *window );
static bool save( MainWindow *window );
static bool saveAs( MainWindow *window );
static void templateDesigner( MainWindow *window );
static void close( MainWindow *window );
static void exit();
private:
static QString mCwd;
};
}
#endif // File_h
+62
View File
@@ -0,0 +1,62 @@
// File.hpp
//
// Copyright (C) 2017 Jaye 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 File_hpp
#define File_hpp
#include <QObject>
namespace glabels
{
// Forward References
class MainWindow;
///
/// File Actions
///
/// Note: class provides a translation context for these static functions.
///
class File : public QObject
{
Q_OBJECT
public:
static bool newLabel( MainWindow *window = nullptr );
static void open( MainWindow *window );
static void open( const QString& fileName, MainWindow *window );
static bool save( MainWindow *window );
static bool saveAs( MainWindow *window );
static void templateDesigner( MainWindow *window );
static void close( MainWindow *window );
static void exit();
private:
static QString mCwd;
};
}
#endif // File_hpp
+47 -46
View File
@@ -1,60 +1,61 @@
/* Help.cpp
*
* Copyright (C) 2013 Jaye 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/>.
*/
// Help.cpp
//
// Copyright (C) 2013 Jaye 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 "AboutDialog.h"
#include "ReportBugDialog.h"
#include "Help.hpp"
#include <QtDebug>
#include "AboutDialog.hpp"
#include "ReportBugDialog.hpp"
#include <QDebug>
namespace glabels
{
///
/// Display Help Contents
///
void Help::displayContents( QWidget *parent )
{
qDebug() << "TODO: Help::displayContents";
}
///
/// Display Help Contents
///
void Help::displayContents( QWidget *parent )
{
qDebug() << "TODO: Help::displayContents";
}
///
/// Display Help->"Report Bug" Dialog
///
void Help::displayReportBug( QWidget *parent )
{
ReportBugDialog dialog( parent );
dialog.exec();
}
///
/// Display Help->"Report Bug" Dialog
///
void Help::displayReportBug( QWidget *parent )
{
ReportBugDialog dialog( parent );
dialog.exec();
}
///
/// Display Help->About Dialog
///
void Help::displayAbout( QWidget *parent )
{
AboutDialog dialog( parent );
dialog.exec();
}
///
/// Display Help->About Dialog
///
void Help::displayAbout( QWidget *parent )
{
AboutDialog dialog( parent );
dialog.exec();
}
} // namespace glabels
-45
View File
@@ -1,45 +0,0 @@
/* Help.h
*
* Copyright (C) 2013 Jaye 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 Help_h
#define Help_h
#include <QWidget>
namespace glabels
{
///
/// Help Actions
///
namespace Help
{
void displayContents( QWidget *parent );
void displayReportBug( QWidget *parent );
void displayAbout( QWidget *parent );
}
}
#endif // Help_h
+45
View File
@@ -0,0 +1,45 @@
// Help.hpp
//
// Copyright (C) 2013 Jaye 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 Help_hpp
#define Help_hpp
#include <QWidget>
namespace glabels
{
///
/// Help Actions
///
namespace Help
{
void displayContents( QWidget *parent );
void displayReportBug( QWidget *parent );
void displayAbout( QWidget *parent );
}
}
#endif // Help_hpp
+1354 -1354
View File
File diff suppressed because it is too large Load Diff
-224
View File
@@ -1,224 +0,0 @@
/* LabelEditor.h
*
* Copyright (C) 2013-2016 Jaye 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 LabelEditor_h
#define LabelEditor_h
#include "model/Handle.h"
#include "model/Model.h"
#include "model/ModelObject.h"
#include "model/Region.h"
#include <QPainter>
#include <QScrollArea>
#include <QWidget>
namespace glabels
{
// Forward References
class UndoRedoModel;
///
/// LabelEditor Widget
///
class LabelEditor : public QWidget
{
Q_OBJECT
/////////////////////////////////////
// Lifecycle
/////////////////////////////////////
public:
LabelEditor( QScrollArea* scrollArea, QWidget* parent = nullptr );
/////////////////////////////////////
// Signals
/////////////////////////////////////
signals:
void contextMenuActivate( model::Point p );
void zoomChanged();
void pointerMoved( model::Point p );
void pointerExited();
void modeChanged();
/////////////////////////////////////
// Parameters
/////////////////////////////////////
public:
double zoom() const;
bool markupVisible() const;
bool qridVisible() const;
/////////////////////////////////////
// Model
/////////////////////////////////////
public:
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////////
// 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 );
/////////////////////////////////////
// Mode operations
/////////////////////////////////////
public:
void arrowMode();
void createBoxMode();
void createEllipseMode();
void createLineMode();
void createImageMode();
void createTextMode();
void createBarcodeMode();
/////////////////////////////////////
// Event handlers
/////////////////////////////////////
protected:
void resizeEvent( QResizeEvent* event ) override;
void mousePressEvent( QMouseEvent* event ) override;
void mouseMoveEvent( QMouseEvent* event ) override;
void mouseReleaseEvent( QMouseEvent* event ) override;
void leaveEvent( QEvent* event ) override;
void keyPressEvent( QKeyEvent* event ) override;
void paintEvent( QPaintEvent* event ) override;
void dragEnterEvent( QDragEnterEvent *event ) override;
void dragMoveEvent( QDragMoveEvent *event ) override;
void dropEvent( QDropEvent *event ) override;
/////////////////////////////////////
// Private methods
/////////////////////////////////////
private:
void handleResizeMotion( model::Distance xWorld,
model::Distance yWorld );
void drawBgLayer( QPainter* painter );
void drawGridLayer( QPainter* painter );
void drawMarkupLayer( QPainter* painter );
void drawObjectsLayer( QPainter* painter );
void drawFgLayer( QPainter* painter );
void drawHighlightLayer( QPainter* painter );
void drawSelectRegionLayer( QPainter* painter );
/////////////////////////////////////
// Private slots
/////////////////////////////////////
private slots:
void onSettingsChanged();
void onModelSizeChanged();
/////////////////////////////////////
// Private data
/////////////////////////////////////
private:
enum State {
IdleState,
ArrowSelectRegion,
ArrowMove,
ArrowResize,
CreateIdle,
CreateDrag
};
enum CreateType {
Box,
Ellipse,
Line,
Image,
Text,
Barcode
};
QScrollArea* mScrollArea;
model::Model* mModel;
UndoRedoModel* mUndoRedoModel;
double mZoom;
bool mZoomToFitFlag;
double mScale;
model::Distance mX0;
model::Distance mY0;
bool mMarkupVisible;
bool mGridVisible;
double mGridSpacing;
model::Distance mStepSize;
State mState;
/* ArrowSelectRegion state */
bool mSelectRegionVisible;
model::Region mSelectRegion;
/* ArrowMove state */
model::Distance mMoveLastX;
model::Distance mMoveLastY;
/* ArrowResize state */
model::ModelObject* mResizeObject;
model::Handle::Location mResizeHandleLocation;
bool mResizeHonorAspect;
/* CreateDrag state */
CreateType mCreateObjectType;
model::ModelObject* mCreateObject;
model::Distance mCreateX0;
model::Distance mCreateY0;
};
}
#endif // LabelEditor_h
+224
View File
@@ -0,0 +1,224 @@
// LabelEditor.hpp
//
// Copyright (C) 2013-2016 Jaye 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 LabelEditor_hpp
#define LabelEditor_hpp
#include "model/Handle.hpp"
#include "model/Model.hpp"
#include "model/ModelObject.hpp"
#include "model/Region.hpp"
#include <QPainter>
#include <QScrollArea>
#include <QWidget>
namespace glabels
{
// Forward References
class UndoRedoModel;
///
/// LabelEditor Widget
///
class LabelEditor : public QWidget
{
Q_OBJECT
/////////////////////////////////////
// Lifecycle
/////////////////////////////////////
public:
LabelEditor( QScrollArea* scrollArea, QWidget* parent = nullptr );
/////////////////////////////////////
// Signals
/////////////////////////////////////
signals:
void contextMenuActivate( model::Point p );
void zoomChanged();
void pointerMoved( model::Point p );
void pointerExited();
void modeChanged();
/////////////////////////////////////
// Parameters
/////////////////////////////////////
public:
double zoom() const;
bool markupVisible() const;
bool qridVisible() const;
/////////////////////////////////////
// Model
/////////////////////////////////////
public:
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////////
// 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 );
/////////////////////////////////////
// Mode operations
/////////////////////////////////////
public:
void arrowMode();
void createBoxMode();
void createEllipseMode();
void createLineMode();
void createImageMode();
void createTextMode();
void createBarcodeMode();
/////////////////////////////////////
// Event handlers
/////////////////////////////////////
protected:
void resizeEvent( QResizeEvent* event ) override;
void mousePressEvent( QMouseEvent* event ) override;
void mouseMoveEvent( QMouseEvent* event ) override;
void mouseReleaseEvent( QMouseEvent* event ) override;
void leaveEvent( QEvent* event ) override;
void keyPressEvent( QKeyEvent* event ) override;
void paintEvent( QPaintEvent* event ) override;
void dragEnterEvent( QDragEnterEvent *event ) override;
void dragMoveEvent( QDragMoveEvent *event ) override;
void dropEvent( QDropEvent *event ) override;
/////////////////////////////////////
// Private methods
/////////////////////////////////////
private:
void handleResizeMotion( model::Distance xWorld,
model::Distance yWorld );
void drawBgLayer( QPainter* painter );
void drawGridLayer( QPainter* painter );
void drawMarkupLayer( QPainter* painter );
void drawObjectsLayer( QPainter* painter );
void drawFgLayer( QPainter* painter );
void drawHighlightLayer( QPainter* painter );
void drawSelectRegionLayer( QPainter* painter );
/////////////////////////////////////
// Private slots
/////////////////////////////////////
private slots:
void onSettingsChanged();
void onModelSizeChanged();
/////////////////////////////////////
// Private data
/////////////////////////////////////
private:
enum State {
IdleState,
ArrowSelectRegion,
ArrowMove,
ArrowResize,
CreateIdle,
CreateDrag
};
enum CreateType {
Box,
Ellipse,
Line,
Image,
Text,
Barcode
};
QScrollArea* mScrollArea;
model::Model* mModel;
UndoRedoModel* mUndoRedoModel;
double mZoom;
bool mZoomToFitFlag;
double mScale;
model::Distance mX0;
model::Distance mY0;
bool mMarkupVisible;
bool mGridVisible;
double mGridSpacing;
model::Distance mStepSize;
State mState;
/* ArrowSelectRegion state */
bool mSelectRegionVisible;
model::Region mSelectRegion;
/* ArrowMove state */
model::Distance mMoveLastX;
model::Distance mMoveLastY;
/* ArrowResize state */
model::ModelObject* mResizeObject;
model::Handle::Location mResizeHandleLocation;
bool mResizeHonorAspect;
/* CreateDrag state */
CreateType mCreateObjectType;
model::ModelObject* mCreateObject;
model::Distance mCreateX0;
model::Distance mCreateY0;
};
}
#endif // LabelEditor_hpp
+1776 -1775
View File
File diff suppressed because it is too large Load Diff
-334
View File
@@ -1,334 +0,0 @@
/* MainWindow.h
*
* Copyright (C) 2014 Jaye 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 MainWindow_h
#define MainWindow_h
#include "UndoRedoModel.h"
#include <model/Model.h>
#include <QAction>
#include <QCloseEvent>
#include <QLabel>
#include <QListWidget>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QScrollArea>
#include <QStackedWidget>
#include <QToolBar>
#include <QToolButton>
#include <memory>
namespace glabels
{
// Forward References
class LabelEditor;
class MergeView;
class ObjectEditor;
class PrintView;
class PropertiesView;
class StartupView;
class VariablesView;
///
/// MainWindow Widget
///
class MainWindow : public QMainWindow
{
Q_OBJECT
/////////////////////////////////////
// Lifecycle
/////////////////////////////////////
public:
MainWindow();
virtual ~MainWindow() = default;
/////////////////////////////////////
// Public Methods
/////////////////////////////////////
public:
model::Model* model() const;
void setModel( model::Model* model );
bool isEmpty() const;
/////////////////////////////////////
// Events
/////////////////////////////////////
protected:
void closeEvent( QCloseEvent *event ) override;
/////////////////////////////////////
// Slots
/////////////////////////////////////
private slots:
void changePage( bool checked );
void clipboardChanged();
void fileNew();
void fileOpen();
void fileOpenRecent();
void fileSave();
void fileSaveAs();
void fileShowEditorPage();
void fileShowPropertiesPage();
void fileShowMergePage();
void fileShowVariablesPage();
void fileShowPrintPage();
void fileTemplateDesigner();
void fileClose();
void fileExit();
void editUndo();
void editRedo();
void editCut();
void editCopy();
void editPaste();
void editContextPaste();
void editDelete();
void editSelectAll();
void editUnSelectAll();
void editPreferences();
void viewFileToolBar( bool );
void viewEditorToolBar( bool );
void viewGrid( bool );
void viewMarkup( bool );
void viewZoomIn();
void viewZoomOut();
void viewZoom1To1();
void viewZoomToFit();
void objectsArrowMode();
void objectsCreateText();
void objectsCreateBox();
void objectsCreateLine();
void objectsCreateEllipse();
void objectsCreateImage();
void objectsCreateBarcode();
void objectsOrderRaise();
void objectsOrderLower();
void objectsXformRotateLeft();
void objectsXformRotateRight();
void objectsXformFlipHoriz();
void objectsXformFlipVert();
void objectsAlignLeft();
void objectsAlignHCenter();
void objectsAlignRight();
void objectsAlignTop();
void objectsAlignVCenter();
void objectsAlignBottom();
void objectsCenter();
void objectsCenterHoriz();
void objectsCenterVert();
void helpContents();
void helpReportBug();
void helpAbout();
void onContextMenuActivate( model::Point );
void onZoomChanged();
void onPointerMoved( model::Point );
void onPointerExit();
void onNameChanged();
void onModifiedChanged();
void onSelectionChanged();
void onLabelChanged();
void onUndoRedoChanged();
void onSettingsChanged();
/////////////////////////////////////
// Internal Private Methods
/////////////////////////////////////
private:
void createActions();
void createMenus();
void createToolBars();
void createStatusBar();
QWidget* createWelcomePage();
QWidget* createEditorPage();
QWidget* createPropertiesPage();
QWidget* createMergePage();
QWidget* createVariablesPage();
QWidget* createPrintPage();
void manageActions();
void setTitle();
void readSettings();
void writeSettings();
bool isOkToClose();
/////////////////////////////////////
// Private Data
// owned and managed by us
/////////////////////////////////////
private:
std::unique_ptr<model::Model> mModel;
std::unique_ptr<UndoRedoModel> mUndoRedoModel;
/////////////////////////////////////
// Private Data
// owned by QMainWindow
/////////////////////////////////////
QMenu* fileMenu;
QMenu* fileRecentMenu;
QMenu* editMenu;
QMenu* viewMenu;
QMenu* viewToolBarsMenu;
QMenu* objectsMenu;
QMenu* objectsCreateMenu;
QMenu* objectsOrderMenu;
QMenu* objectsXformMenu;
QMenu* objectsAlignMenu;
QMenu* objectsCenterMenu;
QMenu* helpMenu;
QMenu* contextMenu;
QMenu* contextOrderMenu;
QMenu* contextXformMenu;
QMenu* contextAlignMenu;
QMenu* contextCenterMenu;
QMenu* noSelectionContextMenu;
QToolBar* fileToolBar;
QToolBar* editorToolBar;
QToolBar* mContents;
QToolButton* mWelcomeButton;
QToolButton* mEditorButton;
QToolButton* mPropertiesButton;
QToolButton* mMergeButton;
QToolButton* mVariablesButton;
QToolButton* mPrintButton;
QAction* mWelcomeAction;
QAction* mEditorAction;
QAction* mPropertiesAction;
QAction* mMergeAction;
QAction* mVariablesAction;
QAction* mPrintAction;
QStackedWidget* mPages;
StartupView* mWelcomeView;
QScrollArea* mLabelEditorScrollArea;
LabelEditor* mLabelEditor;
ObjectEditor* mObjectEditor;
PropertiesView* mPropertiesView;
MergeView* mMergeView;
VariablesView* mVariablesView;
PrintView* mPrintView;
QLabel* zoomInfoLabel;
QLabel* cursorInfoLabel;
QAction* fileNewAction;
QAction* fileOpenAction;
QAction* fileSaveAction;
QAction* fileSaveAsAction;
QAction* fileShowEditorPageAction;
QAction* fileShowPropertiesPageAction;
QAction* fileShowMergePageAction;
QAction* fileShowVariablesPageAction;
QAction* fileShowPrintPageAction;
QAction* fileTemplateDesignerAction;
QAction* fileCloseAction;
QAction* fileExitAction;
QList<QAction*> fileRecentActionList;
QAction* editUndoAction;
QAction* editRedoAction;
QAction* editCutAction;
QAction* editCopyAction;
QAction* editPasteAction;
QAction* editDeleteAction;
QAction* editSelectAllAction;
QAction* editUnSelectAllAction;
QAction* editPreferencesAction;
QAction* viewFileToolBarAction;
QAction* viewEditorToolBarAction;
QAction* viewGridAction;
QAction* viewMarkupAction;
QAction* viewZoomInAction;
QAction* viewZoomOutAction;
QAction* viewZoom1To1Action;
QAction* viewZoomToFitAction;
QAction* 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* objectsCenterAction;
QAction* objectsCenterHorizAction;
QAction* objectsCenterVertAction;
QAction* helpContentsAction;
QAction* helpReportBugAction;
QAction* helpAboutAction;
QAction* contextCutAction;
QAction* contextCopyAction;
QAction* contextPasteAction;
QAction* contextDeleteAction;
};
}
#endif // MainWindow_h
+334
View File
@@ -0,0 +1,334 @@
// MainWindow.hpp
//
// Copyright (C) 2014 Jaye 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 MainWindow_hpp
#define MainWindow_hpp
#include "UndoRedoModel.hpp"
#include <model/Model.hpp>
#include <QAction>
#include <QCloseEvent>
#include <QLabel>
#include <QListWidget>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QScrollArea>
#include <QStackedWidget>
#include <QToolBar>
#include <QToolButton>
#include <memory>
namespace glabels
{
// Forward References
class LabelEditor;
class MergeView;
class ObjectEditor;
class PrintView;
class PropertiesView;
class StartupView;
class VariablesView;
///
/// MainWindow Widget
///
class MainWindow : public QMainWindow
{
Q_OBJECT
/////////////////////////////////////
// Lifecycle
/////////////////////////////////////
public:
MainWindow();
virtual ~MainWindow() = default;
/////////////////////////////////////
// Public Methods
/////////////////////////////////////
public:
model::Model* model() const;
void setModel( model::Model* model );
bool isEmpty() const;
/////////////////////////////////////
// Events
/////////////////////////////////////
protected:
void closeEvent( QCloseEvent *event ) override;
/////////////////////////////////////
// Slots
/////////////////////////////////////
private slots:
void changePage( bool checked );
void clipboardChanged();
void fileNew();
void fileOpen();
void fileOpenRecent();
void fileSave();
void fileSaveAs();
void fileShowEditorPage();
void fileShowPropertiesPage();
void fileShowMergePage();
void fileShowVariablesPage();
void fileShowPrintPage();
void fileTemplateDesigner();
void fileClose();
void fileExit();
void editUndo();
void editRedo();
void editCut();
void editCopy();
void editPaste();
void editContextPaste();
void editDelete();
void editSelectAll();
void editUnSelectAll();
void editPreferences();
void viewFileToolBar( bool );
void viewEditorToolBar( bool );
void viewGrid( bool );
void viewMarkup( bool );
void viewZoomIn();
void viewZoomOut();
void viewZoom1To1();
void viewZoomToFit();
void objectsArrowMode();
void objectsCreateText();
void objectsCreateBox();
void objectsCreateLine();
void objectsCreateEllipse();
void objectsCreateImage();
void objectsCreateBarcode();
void objectsOrderRaise();
void objectsOrderLower();
void objectsXformRotateLeft();
void objectsXformRotateRight();
void objectsXformFlipHoriz();
void objectsXformFlipVert();
void objectsAlignLeft();
void objectsAlignHCenter();
void objectsAlignRight();
void objectsAlignTop();
void objectsAlignVCenter();
void objectsAlignBottom();
void objectsCenter();
void objectsCenterHoriz();
void objectsCenterVert();
void helpContents();
void helpReportBug();
void helpAbout();
void onContextMenuActivate( model::Point );
void onZoomChanged();
void onPointerMoved( model::Point );
void onPointerExit();
void onNameChanged();
void onModifiedChanged();
void onSelectionChanged();
void onLabelChanged();
void onUndoRedoChanged();
void onSettingsChanged();
/////////////////////////////////////
// Internal Private Methods
/////////////////////////////////////
private:
void createActions();
void createMenus();
void createToolBars();
void createStatusBar();
QWidget* createWelcomePage();
QWidget* createEditorPage();
QWidget* createPropertiesPage();
QWidget* createMergePage();
QWidget* createVariablesPage();
QWidget* createPrintPage();
void manageActions();
void setTitle();
void readSettings();
void writeSettings();
bool isOkToClose();
/////////////////////////////////////
// Private Data
// owned and managed by us
/////////////////////////////////////
private:
std::unique_ptr<model::Model> mModel;
std::unique_ptr<UndoRedoModel> mUndoRedoModel;
/////////////////////////////////////
// Private Data
// owned by QMainWindow
/////////////////////////////////////
QMenu* fileMenu;
QMenu* fileRecentMenu;
QMenu* editMenu;
QMenu* viewMenu;
QMenu* viewToolBarsMenu;
QMenu* objectsMenu;
QMenu* objectsCreateMenu;
QMenu* objectsOrderMenu;
QMenu* objectsXformMenu;
QMenu* objectsAlignMenu;
QMenu* objectsCenterMenu;
QMenu* helpMenu;
QMenu* contextMenu;
QMenu* contextOrderMenu;
QMenu* contextXformMenu;
QMenu* contextAlignMenu;
QMenu* contextCenterMenu;
QMenu* noSelectionContextMenu;
QToolBar* fileToolBar;
QToolBar* editorToolBar;
QToolBar* mContents;
QToolButton* mWelcomeButton;
QToolButton* mEditorButton;
QToolButton* mPropertiesButton;
QToolButton* mMergeButton;
QToolButton* mVariablesButton;
QToolButton* mPrintButton;
QAction* mWelcomeAction;
QAction* mEditorAction;
QAction* mPropertiesAction;
QAction* mMergeAction;
QAction* mVariablesAction;
QAction* mPrintAction;
QStackedWidget* mPages;
StartupView* mWelcomeView;
QScrollArea* mLabelEditorScrollArea;
LabelEditor* mLabelEditor;
ObjectEditor* mObjectEditor;
PropertiesView* mPropertiesView;
MergeView* mMergeView;
VariablesView* mVariablesView;
PrintView* mPrintView;
QLabel* zoomInfoLabel;
QLabel* cursorInfoLabel;
QAction* fileNewAction;
QAction* fileOpenAction;
QAction* fileSaveAction;
QAction* fileSaveAsAction;
QAction* fileShowEditorPageAction;
QAction* fileShowPropertiesPageAction;
QAction* fileShowMergePageAction;
QAction* fileShowVariablesPageAction;
QAction* fileShowPrintPageAction;
QAction* fileTemplateDesignerAction;
QAction* fileCloseAction;
QAction* fileExitAction;
QList<QAction*> fileRecentActionList;
QAction* editUndoAction;
QAction* editRedoAction;
QAction* editCutAction;
QAction* editCopyAction;
QAction* editPasteAction;
QAction* editDeleteAction;
QAction* editSelectAllAction;
QAction* editUnSelectAllAction;
QAction* editPreferencesAction;
QAction* viewFileToolBarAction;
QAction* viewEditorToolBarAction;
QAction* viewGridAction;
QAction* viewMarkupAction;
QAction* viewZoomInAction;
QAction* viewZoomOutAction;
QAction* viewZoom1To1Action;
QAction* viewZoomToFitAction;
QAction* 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* objectsCenterAction;
QAction* objectsCenterHorizAction;
QAction* objectsCenterVertAction;
QAction* helpContentsAction;
QAction* helpReportBugAction;
QAction* helpAboutAction;
QAction* contextCutAction;
QAction* contextCopyAction;
QAction* contextPasteAction;
QAction* contextDeleteAction;
};
}
#endif // MainWindow_hpp
+140 -140
View File
@@ -1,25 +1,25 @@
/* MergeTableModel.cpp
*
* Copyright (C) 2025 Jaye 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/>.
*/
// MergeTableModel.cpp
//
// Copyright (C) 2025 Jaye 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 "MergeTableModel.h"
#include "MergeTableModel.hpp"
#include <QDebug>
@@ -27,152 +27,152 @@
namespace glabels
{
///
/// Constructor
///
MergeTableModel::MergeTableModel( merge::Merge* merge, QObject* parent )
: QAbstractTableModel( parent ),
mMerge( merge )
{
// Copy keys, make sure primary key is first
mDisplayKeys.push_back( mMerge->primaryKey() );
for ( auto& key : mMerge->keys() )
{
if ( key != mMerge->primaryKey() )
{
mDisplayKeys.push_back( key );
}
}
///
/// Constructor
///
MergeTableModel::MergeTableModel( merge::Merge* merge, QObject* parent )
: QAbstractTableModel( parent ),
mMerge( merge )
{
// Copy keys, make sure primary key is first
mDisplayKeys.push_back( mMerge->primaryKey() );
for ( auto& key : mMerge->keys() )
{
if ( key != mMerge->primaryKey() )
{
mDisplayKeys.push_back( key );
}
}
connect( mMerge, SIGNAL(selectionChanged()),
this, SLOT(onSelectionChanged()) );
}
connect( mMerge, SIGNAL(selectionChanged()),
this, SLOT(onSelectionChanged()) );
}
///
/// Row count
///
int MergeTableModel::rowCount( const QModelIndex& parent ) const
{
return mMerge->recordList().size();
}
///
/// Row count
///
int MergeTableModel::rowCount( const QModelIndex& parent ) const
{
return mMerge->recordList().size();
}
///
/// Column count
///
int MergeTableModel::columnCount( const QModelIndex& parent ) const
{
return mDisplayKeys.size() + 1;
}
///
/// Column count
///
int MergeTableModel::columnCount( const QModelIndex& parent ) const
{
return mDisplayKeys.size() + 1;
}
///
/// Header data
///
QVariant MergeTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( orientation == Qt::Vertical )
{
return QAbstractTableModel::headerData( section, orientation, role );
}
///
/// Header data
///
QVariant MergeTableModel::headerData( int section, Qt::Orientation orientation, int role ) const
{
if ( orientation == Qt::Vertical )
{
return QAbstractTableModel::headerData( section, orientation, role );
}
if ( (role != Qt::DisplayRole) || section >= mDisplayKeys.size() )
{
return QVariant();
}
if ( (role != Qt::DisplayRole) || section >= mDisplayKeys.size() )
{
return QVariant();
}
return mDisplayKeys[ section ];
}
return mDisplayKeys[ section ];
}
///
/// Data
///
QVariant MergeTableModel::data( const QModelIndex& index, int role ) const
{
if ( !index.isValid() )
{
return QVariant();
}
///
/// Data
///
QVariant MergeTableModel::data( const QModelIndex& index, int role ) const
{
if ( !index.isValid() )
{
return QVariant();
}
if ( (index.row() >= mMerge->recordList().size()) ||
(index.column() >= mDisplayKeys.size()) )
{
return QVariant();
}
if ( (index.row() >= mMerge->recordList().size()) ||
(index.column() >= mDisplayKeys.size()) )
{
return QVariant();
}
if ( (role == Qt::CheckStateRole) && (index.column() == 0) )
{
auto record = mMerge->recordList()[ index.row() ];
return record.isSelected() ? Qt::Checked : Qt::Unchecked;
}
if ( (role == Qt::CheckStateRole) && (index.column() == 0) )
{
auto record = mMerge->recordList()[ index.row() ];
return record.isSelected() ? Qt::Checked : Qt::Unchecked;
}
if ( role == Qt::DisplayRole )
{
auto record = mMerge->recordList()[ index.row() ];
auto key = mDisplayKeys[ index.column() ];
if ( role == Qt::DisplayRole )
{
auto record = mMerge->recordList()[ index.row() ];
auto key = mDisplayKeys[ index.column() ];
if ( record.contains( key ) )
{
return record[ key ];
}
}
if ( record.contains( key ) )
{
return record[ key ];
}
}
return QVariant();
}
return QVariant();
}
///
/// Set data
///
bool MergeTableModel::setData( const QModelIndex& index, const QVariant& value, int role )
{
if ( !index.isValid() || (index.column() != 0) || (role != Qt::CheckStateRole) )
{
return false;
}
///
/// Set data
///
bool MergeTableModel::setData( const QModelIndex& index, const QVariant& value, int role )
{
if ( !index.isValid() || (index.column() != 0) || (role != Qt::CheckStateRole) )
{
return false;
}
bool isChecked = static_cast<Qt::CheckState>(value.toInt()) != Qt::Unchecked;
mMerge->blockSignals( true );
mMerge->setSelected( index.row(), isChecked );
mMerge->blockSignals( false );
return true;
}
bool isChecked = static_cast<Qt::CheckState>(value.toInt()) != Qt::Unchecked;
mMerge->blockSignals( true );
mMerge->setSelected( index.row(), isChecked );
mMerge->blockSignals( false );
return true;
}
///
/// Flags
///
Qt::ItemFlags MergeTableModel::flags( const QModelIndex& index ) const
{
if ( !index.isValid() )
{
return Qt::NoItemFlags;
}
///
/// Flags
///
Qt::ItemFlags MergeTableModel::flags( const QModelIndex& index ) const
{
if ( !index.isValid() )
{
return Qt::NoItemFlags;
}
if ( index.column() == 0 )
{
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
}
if ( index.column() == 0 )
{
return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
}
return Qt::ItemIsEnabled;
}
return Qt::ItemIsEnabled;
}
///
/// Selection changed handler
///
void MergeTableModel::onSelectionChanged()
{
for ( int iRow = 0; iRow < mMerge->recordList().size(); iRow++ )
{
auto index = createIndex( iRow, 0 );
emit dataChanged( index, index, {Qt::CheckStateRole} );
}
}
///
/// Selection changed handler
///
void MergeTableModel::onSelectionChanged()
{
for ( int iRow = 0; iRow < mMerge->recordList().size(); iRow++ )
{
auto index = createIndex( iRow, 0 );
emit dataChanged( index, index, {Qt::CheckStateRole} );
}
}
} // namespace glabels
-80
View File
@@ -1,80 +0,0 @@
/* MergeTableModel.h
*
* Copyright (C) 2025 Jaye 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 MergeTableModel_h
#define MergeTableModel_h
#include "merge/Merge.h"
#include <QAbstractTableModel>
namespace glabels
{
///
/// MergeTable proxy model
///
class MergeTableModel : public QAbstractTableModel
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
MergeTableModel( merge::Merge* merge, QObject* parent = nullptr );
/////////////////////////////////
// Public methods
/////////////////////////////////
public:
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override;
Qt::ItemFlags flags( const QModelIndex& index ) const override;
/////////////////////////////////
// Private slots
/////////////////////////////////
private slots:
void onSelectionChanged();
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
merge::Merge* mMerge;
QStringList mDisplayKeys;
};
}
#endif // MergeTableModel_h
+80
View File
@@ -0,0 +1,80 @@
// MergeTableModel.hpp
//
// Copyright (C) 2025 Jaye 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 MergeTableModel_hpp
#define MergeTableModel_hpp
#include "merge/Merge.hpp"
#include <QAbstractTableModel>
namespace glabels
{
///
/// MergeTable proxy model
///
class MergeTableModel : public QAbstractTableModel
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
MergeTableModel( merge::Merge* merge, QObject* parent = nullptr );
/////////////////////////////////
// Public methods
/////////////////////////////////
public:
int rowCount( const QModelIndex& parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const override;
bool setData( const QModelIndex& index, const QVariant& value, int role = Qt::EditRole ) override;
Qt::ItemFlags flags( const QModelIndex& index ) const override;
/////////////////////////////////
// Private slots
/////////////////////////////////
private slots:
void onSelectionChanged();
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
merge::Merge* mMerge;
QStringList mDisplayKeys;
};
}
#endif // MergeTableModel_hpp
+152 -152
View File
@@ -1,31 +1,31 @@
/* MergeView.cpp
*
* Copyright (C) 2016 Jaye 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/>.
*/
// MergeView.cpp
//
// Copyright (C) 2016 Jaye 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 "MergeView.h"
#include "MergeView.hpp"
#include "MergeTableModel.h"
#include "MergeTableModel.hpp"
#include "merge/Factory.h"
#include "merge/Factory.hpp"
#include "model/FileUtil.h"
#include "model/FileUtil.hpp"
#include <QDebug>
#include <QFileDialog>
@@ -34,167 +34,167 @@
namespace glabels
{
const QChar NEWLINE_CHAR = QChar(0x23CE);
const QChar NEWLINE_CHAR = QChar(0x23CE);
///
/// Constructor
///
MergeView::MergeView( QWidget *parent )
: QWidget(parent), mModel(nullptr), mUndoRedoModel(nullptr), mOldFormatComboIndex(0)
{
setupUi( this );
///
/// Constructor
///
MergeView::MergeView( QWidget *parent )
: QWidget(parent), mModel(nullptr), mUndoRedoModel(nullptr), mOldFormatComboIndex(0)
{
setupUi( this );
titleLabel->setText( QString( "<span style='font-size:18pt;'>%1</span>" ).arg( tr("Merge") ) );
titleLabel->setText( QString( "<span style='font-size:18pt;'>%1</span>" ).arg( tr("Merge") ) );
mMergeFormatNames = merge::Factory::nameList();
formatCombo->addItems( mMergeFormatNames );
}
mMergeFormatNames = merge::Factory::nameList();
formatCombo->addItems( mMergeFormatNames );
}
///
/// Set Model
///
void MergeView::setModel( model::Model* model, UndoRedoModel* undoRedoModel )
{
mModel = model;
mUndoRedoModel = undoRedoModel;
///
/// Set Model
///
void MergeView::setModel( model::Model* model, UndoRedoModel* undoRedoModel )
{
mModel = model;
mUndoRedoModel = undoRedoModel;
// Initialize CWD
mCwd = mModel->dirPath();
// Initialize CWD
mCwd = mModel->dirPath();
onMergeChanged();
connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) );
}
onMergeChanged();
connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) );
}
///
/// Merge changed handler
///
void MergeView::onMergeChanged()
{
QString name = merge::Factory::idToName( mModel->merge()->id() );
int index = mMergeFormatNames.indexOf( name );
mOldFormatComboIndex = index;
formatCombo->setCurrentIndex( index );
///
/// Merge changed handler
///
void MergeView::onMergeChanged()
{
QString name = merge::Factory::idToName( mModel->merge()->id() );
int index = mMergeFormatNames.indexOf( name );
mOldFormatComboIndex = index;
formatCombo->setCurrentIndex( index );
QString fn;
switch ( merge::Factory::idToType( mModel->merge()->id() ) )
{
case merge::Factory::NONE:
case merge::Factory::FIXED:
locationLabel->setEnabled( false );
locationLineEdit->setText( "" );
locationBrowseButton->setVisible( false );
break;
QString fn;
case merge::Factory::FILE:
locationLabel->setEnabled( true );
fn = model::FileUtil::makeRelativeIfInDir( mModel->dir(), mModel->merge()->source() );
locationLineEdit->setText( fn );
locationBrowseButton->setVisible( true );
break;
switch ( merge::Factory::idToType( mModel->merge()->id() ) )
{
case merge::Factory::NONE:
case merge::Factory::FIXED:
locationLabel->setEnabled( false );
locationLineEdit->setText( "" );
locationBrowseButton->setVisible( false );
break;
default:
qWarning( "MergeView::onMergeChanged()::Should not be reached!" );
break;
}
case merge::Factory::FILE:
locationLabel->setEnabled( true );
fn = model::FileUtil::makeRelativeIfInDir( mModel->dir(), mModel->merge()->source() );
locationLineEdit->setText( fn );
locationBrowseButton->setVisible( true );
break;
recordsTableView->setModel( new MergeTableModel( mModel->merge() ) );
recordsTableView->resizeColumnsToContents();
default:
qWarning( "MergeView::onMergeChanged()::Should not be reached!" );
break;
}
connect( mModel->merge(), SIGNAL(sourceChanged()),
this, SLOT(onMergeSourceChanged()) );
}
recordsTableView->setModel( new MergeTableModel( mModel->merge() ) );
recordsTableView->resizeColumnsToContents();
connect( mModel->merge(), SIGNAL(sourceChanged()),
this, SLOT(onMergeSourceChanged()) );
}
///
/// Merge source changed handler
///
void MergeView::onMergeSourceChanged()
{
QString fn = model::FileUtil::makeRelativeIfInDir( mModel->dir(), mModel->merge()->source() );
locationLineEdit->setText( fn );
///
/// Merge source changed handler
///
void MergeView::onMergeSourceChanged()
{
QString fn = model::FileUtil::makeRelativeIfInDir( mModel->dir(), mModel->merge()->source() );
locationLineEdit->setText( fn );
recordsTableView->setModel( new MergeTableModel( mModel->merge() ) );
recordsTableView->resizeColumnsToContents();
}
recordsTableView->setModel( new MergeTableModel( mModel->merge() ) );
recordsTableView->resizeColumnsToContents();
}
///
/// Format combo changed handler
///
void MergeView::onFormatComboActivated()
{
int index = formatCombo->currentIndex();
if ( index != mOldFormatComboIndex )
{
mOldFormatComboIndex = index;
///
/// Format combo changed handler
///
void MergeView::onFormatComboActivated()
{
int index = formatCombo->currentIndex();
if ( index != mOldFormatComboIndex )
{
mOldFormatComboIndex = index;
QString id = merge::Factory::indexToId(index);
mModel->setMerge( merge::Factory::createMerge( id ) );
}
}
QString id = merge::Factory::indexToId(index);
mModel->setMerge( merge::Factory::createMerge( id ) );
}
}
///
/// Location button clicked handler
///
void MergeView::onLocationBrowseButtonClicked()
{
QString fileName =
QFileDialog::getOpenFileName( this,
tr("Select merge file"),
mCwd,
tr("All files (*)") );
if ( !fileName.isEmpty() )
{
mModel->merge()->setSource( fileName );
mCwd = QFileInfo( fileName ).absolutePath(); // Update CWD
}
}
///
/// Location button clicked handler
///
void MergeView::onLocationBrowseButtonClicked()
{
QString fileName =
QFileDialog::getOpenFileName( this,
tr("Select merge file"),
mCwd,
tr("All files (*)") );
if ( !fileName.isEmpty() )
{
mModel->merge()->setSource( fileName );
mCwd = QFileInfo( fileName ).absolutePath(); // Update CWD
}
}
///
/// Select all button clicked handler
///
void MergeView::onSelectAllButtonClicked()
{
mModel->merge()->selectAll();
}
///
/// Select all button clicked handler
///
void MergeView::onSelectAllButtonClicked()
{
mModel->merge()->selectAll();
}
///
/// Unselect all button clicked handler
///
void MergeView::onUnselectAllButtonClicked()
{
mModel->merge()->unselectAll();
}
///
/// Unselect all button clicked handler
///
void MergeView::onUnselectAllButtonClicked()
{
mModel->merge()->unselectAll();
}
///
/// Reload button clicked handler
///
void MergeView::onReloadButtonClicked()
{
mModel->merge()->reloadSource();
}
///
/// Reload button clicked handler
///
void MergeView::onReloadButtonClicked()
{
mModel->merge()->reloadSource();
}
///
/// modify text to be printable e.g. replace newlines
///
QString MergeView::printableTextForView( QString text )
{
// Replace windows style newlines
text.replace("\r\n", NEWLINE_CHAR);
///
/// modify text to be printable e.g. replace newlines
///
QString MergeView::printableTextForView( QString text )
{
// Replace windows style newlines
text.replace("\r\n", NEWLINE_CHAR);
// Replace unix style newlines
text.replace("\n", NEWLINE_CHAR);
// Replace unix style newlines
text.replace("\n", NEWLINE_CHAR);
return text;
}
return text;
}
} // namespace glabels
-103
View File
@@ -1,103 +0,0 @@
/* MergeView.h
*
* Copyright (C) 2016 Jaye 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 MergeView_h
#define MergeView_h
#include "ui_MergeView.h"
#include "model/Model.h"
#include "merge/Merge.h"
namespace glabels
{
// Forward references
class UndoRedoModel;
///
/// merge::Merge Property Editor Widget
///
class MergeView : public QWidget, public Ui_MergeView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
MergeView( QWidget *parent = nullptr );
virtual ~MergeView() = default;
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMergeChanged();
void onMergeSourceChanged();
void onFormatComboActivated();
void onLocationBrowseButtonClicked();
void onSelectAllButtonClicked();
void onUnselectAllButtonClicked();
void onReloadButtonClicked();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
static QString printableTextForView( QString text );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QStringList mMergeFormatNames;
model::Model* mModel;
UndoRedoModel* mUndoRedoModel;
QStringList mKeys;
QString mPrimaryKey;
QString mCwd;
int mOldFormatComboIndex;
};
}
#endif // MergeView_h
+103
View File
@@ -0,0 +1,103 @@
// MergeView.hpp
//
// Copyright (C) 2016 Jaye 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 MergeView_hpp
#define MergeView_hpp
#include "ui_MergeView.h"
#include "model/Model.hpp"
#include "merge/Merge.hpp"
namespace glabels
{
// Forward references
class UndoRedoModel;
///
/// merge::Merge Property Editor Widget
///
class MergeView : public QWidget, public Ui_MergeView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
MergeView( QWidget *parent = nullptr );
virtual ~MergeView() = default;
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onMergeChanged();
void onMergeSourceChanged();
void onFormatComboActivated();
void onLocationBrowseButtonClicked();
void onSelectAllButtonClicked();
void onUnselectAllButtonClicked();
void onReloadButtonClicked();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
static QString printableTextForView( QString text );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
QStringList mMergeFormatNames;
model::Model* mModel;
UndoRedoModel* mUndoRedoModel;
QStringList mKeys;
QString mPrimaryKey;
QString mCwd;
int mOldFormatComboIndex;
};
}
#endif // MergeView_hpp
+126 -131
View File
@@ -1,154 +1,149 @@
/* MiniPreviewPixmap.cpp
*
* Copyright (C) 2013-2016 Jaye 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 "MiniPreviewPixmap.h"
// MiniPreviewPixmap.cpp
//
// Copyright (C) 2013-2016 Jaye 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 "RollTemplatePath.h"
#include "model/Template.h"
#include "MiniPreviewPixmap.hpp"
#include "RollTemplatePath.hpp"
#include "model/Template.hpp"
//
// Private
//
namespace
{
const QColor paperColor( 217, 217, 217 );
const QColor paperOutlineColor( 0, 0, 0 );
const double paperOutlineWidthPixels = 1.0;
const QColor labelColor( 242, 242, 242 );
const QColor labelOutlineColor( 64, 64, 64 );
const double labelOutlineWidthPixels = 1.0;
}
namespace glabels
{
//
// Private
//
namespace
{
const QColor paperColor( 217, 217, 217 );
const QColor paperOutlineColor( 0, 0, 0 );
const double paperOutlineWidthPixels = 1.0;
const QColor labelColor( 242, 242, 242 );
const QColor labelOutlineColor( 64, 64, 64 );
const double labelOutlineWidthPixels = 1.0;
}
MiniPreviewPixmap::MiniPreviewPixmap( const model::Template& tmplate, int width, int height )
: QPixmap( width, height )
{
draw( tmplate, width, height );
}
MiniPreviewPixmap::MiniPreviewPixmap()
{
// empty
}
void MiniPreviewPixmap::draw( const model::Template& tmplate, int width, int height )
{
fill( Qt::transparent );
QPainter painter( this );
painter.setBackgroundMode( Qt::TransparentMode );
painter.setRenderHint( QPainter::Antialiasing, true );
// For "Roll" templates, allow extra room for tape width and continuation break lines
model::Distance drawWidth = tmplate.pageWidth();
model::Distance drawHeight = tmplate.pageHeight();
if ( tmplate.isRoll() )
{
drawWidth = tmplate.rollWidth();
drawHeight *= 1.2;
}
double w = width - 1;
double h = height - 1;
double scale;
if ( (w/drawWidth.pt()) > (h/drawHeight.pt()) )
{
scale = h / drawHeight.pt();
}
else
{
scale = w / drawWidth.pt();
}
painter.scale( scale, scale );
model::Distance xOffset = ( model::Distance::pt(width/scale) - tmplate.pageWidth() ) / 2;
model::Distance yOffset = ( model::Distance::pt(height/scale) - tmplate.pageHeight() ) / 2;
painter.translate( xOffset.pt(), yOffset.pt() );
drawPaper( painter, tmplate, scale );
drawLabelOutlines( painter, tmplate, scale );
}
MiniPreviewPixmap::MiniPreviewPixmap( const model::Template& tmplate, int width, int height )
: QPixmap( width, height )
{
draw( tmplate, width, height );
}
void MiniPreviewPixmap::drawPaper( QPainter& painter, const model::Template& tmplate, double scale )
{
QBrush brush( paperColor );
QPen pen( paperOutlineColor );
pen.setWidth( paperOutlineWidthPixels/scale );
painter.save();
painter.setBrush( brush );
painter.setPen( pen );
if ( !tmplate.isRoll() )
{
painter.drawRect( 0, 0, tmplate.pageWidth().pt(), tmplate.pageHeight().pt() );
}
else
{
painter.drawPath( RollTemplatePath( tmplate ) );
}
painter.restore();
}
void MiniPreviewPixmap::draw( const model::Template& tmplate, int width, int height )
{
fill( Qt::transparent );
void MiniPreviewPixmap::drawLabelOutlines( QPainter& painter, const model::Template& tmplate, double scale )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
pen.setWidth( labelOutlineWidthPixels/scale );
QPainter painter( this );
painter.save();
painter.setBackgroundMode( Qt::TransparentMode );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.setBrush( brush );
painter.setPen( pen );
// For "Roll" templates, allow extra room for tape width and continuation break lines
model::Distance drawWidth = tmplate.pageWidth();
model::Distance drawHeight = tmplate.pageHeight();
if ( tmplate.isRoll() )
{
drawWidth = tmplate.rollWidth();
drawHeight *= 1.2;
}
auto frame = tmplate.frame();
for ( model::Point p0 : frame->getOrigins() )
{
drawLabelOutline( painter, frame, p0 );
}
double w = width - 1;
double h = height - 1;
double scale;
if ( (w/drawWidth.pt()) > (h/drawHeight.pt()) )
{
scale = h / drawHeight.pt();
}
else
{
scale = w / drawWidth.pt();
}
painter.scale( scale, scale );
model::Distance xOffset = ( model::Distance::pt(width/scale) - tmplate.pageWidth() ) / 2;
model::Distance yOffset = ( model::Distance::pt(height/scale) - tmplate.pageHeight() ) / 2;
painter.translate( xOffset.pt(), yOffset.pt() );
drawPaper( painter, tmplate, scale );
drawLabelOutlines( painter, tmplate, scale );
}
painter.restore();
}
void MiniPreviewPixmap::drawPaper( QPainter& painter, const model::Template& tmplate, double scale )
{
QBrush brush( paperColor );
QPen pen( paperOutlineColor );
pen.setWidth( paperOutlineWidthPixels/scale );
void MiniPreviewPixmap::drawLabelOutline( QPainter& painter, const model::Frame* frame, const model::Point& p0 )
{
painter.save();
painter.save();
painter.translate( p0.x().pt(), p0.y().pt() );
painter.drawPath( frame->path() );
painter.setBrush( brush );
painter.setPen( pen );
if ( !tmplate.isRoll() )
{
painter.drawRect( 0, 0, tmplate.pageWidth().pt(), tmplate.pageHeight().pt() );
}
else
{
painter.drawPath( RollTemplatePath( tmplate ) );
}
painter.restore();
}
void MiniPreviewPixmap::drawLabelOutlines( QPainter& painter, const model::Template& tmplate, double scale )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
pen.setWidth( labelOutlineWidthPixels/scale );
painter.save();
painter.setBrush( brush );
painter.setPen( pen );
auto frame = tmplate.frame();
for ( model::Point p0 : frame->getOrigins() )
{
drawLabelOutline( painter, frame, p0 );
}
painter.restore();
}
void MiniPreviewPixmap::drawLabelOutline( QPainter& painter, const model::Frame* frame, const model::Point& p0 )
{
painter.save();
painter.translate( p0.x().pt(), p0.y().pt() );
painter.drawPath( frame->path() );
painter.restore();
}
painter.restore();
}
} // namespace glabels
-56
View File
@@ -1,56 +0,0 @@
/* MiniPreviewPixmap.h
*
* Copyright (C) 2013-2016 Jaye 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_MiniPreviewPixmap_h
#define glabels_MiniPreviewPixmap_h
#include "model/Frame.h"
#include "model/Point.h"
#include "model/Template.h"
#include <QPixmap>
#include <QPainter>
namespace glabels
{
class MiniPreviewPixmap : public QPixmap
{
public:
MiniPreviewPixmap();
MiniPreviewPixmap( const model::Template& tmplate, int width, int height );
private:
void draw( const model::Template& tmplate, int width, int height );
void drawPaper( QPainter& painter, const model::Template& tmplate, double scale );
void drawLabelOutlines( QPainter& painter, const model::Template& tmplate, double scale );
void drawLabelOutline( QPainter& painter, const model::Frame *frame, const model::Point& point0 );
};
}
#endif // glabels_MiniPreviewPixmap_h
+56
View File
@@ -0,0 +1,56 @@
// MiniPreviewPixmap.hpp
//
// Copyright (C) 2013-2016 Jaye 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_MiniPreviewPixmap_hpp
#define glabels_MiniPreviewPixmap_hpp
#include "model/Frame.hpp"
#include "model/Point.hpp"
#include "model/Template.hpp"
#include <QPixmap>
#include <QPainter>
namespace glabels
{
class MiniPreviewPixmap : public QPixmap
{
public:
MiniPreviewPixmap() = default;
MiniPreviewPixmap( const model::Template& tmplate, int width, int height );
private:
void draw( const model::Template& tmplate, int width, int height );
void drawPaper( QPainter& painter, const model::Template& tmplate, double scale );
void drawLabelOutlines( QPainter& painter, const model::Template& tmplate, double scale );
void drawLabelOutline( QPainter& painter, const model::Frame *frame, const model::Point& point0 );
};
}
#endif // glabels_MiniPreviewPixmap_hpp
+48 -47
View File
@@ -1,24 +1,25 @@
/* NotebookUtil.cpp
*
* Copyright (C) 2015 Jaye 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/>.
*/
// NotebookUtil.cpp
//
// Copyright (C) 2015 Jaye 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 "NotebookUtil.h"
#include "NotebookUtil.hpp"
#include <QLayout>
@@ -26,36 +27,36 @@
namespace glabels
{
///
/// Establish notebook size based on largest page
///
void NotebookUtil::establishSize( QTabWidget* notebook )
{
// Establish size of notebook size based on its largest page.
// This may not be established until runtime, due to varying
// lengths of translated strings or may even be influenced by
// the current theme and fonts. Without doing this, the
// notebook may change size as tabs are selected for the first
// time, which can be very annoying.
///
/// Establish notebook size based on largest page
///
void NotebookUtil::establishSize( QTabWidget* notebook )
{
// Establish size of notebook size based on its largest page.
// This may not be established until runtime, due to varying
// lengths of translated strings or may even be influenced by
// the current theme and fonts. Without doing this, the
// notebook may change size as tabs are selected for the first
// time, which can be very annoying.
// This hack shows the top-level window containing the notebook,
// then shows each page and invalidates the window's layout.
// Finally it re-hides the window without ever having
// relinquishing control to the Qt event loop.
// This hack shows the top-level window containing the notebook,
// then shows each page and invalidates the window's layout.
// Finally it re-hides the window without ever having
// relinquishing control to the Qt event loop.
QWidget* window = notebook->window();
int iTabSaved = notebook->currentIndex();
int nTabs = notebook->count();
QWidget* window = notebook->window();
int iTabSaved = notebook->currentIndex();
int nTabs = notebook->count();
window->show();
for ( int iTab = 0; iTab < nTabs; iTab++ )
{
notebook->setCurrentIndex( iTab );
window->layout()->invalidate();
}
window->hide();
window->show();
for ( int iTab = 0; iTab < nTabs; iTab++ )
{
notebook->setCurrentIndex( iTab );
window->layout()->invalidate();
}
window->hide();
notebook->setCurrentIndex( iTabSaved );
}
notebook->setCurrentIndex( iTabSaved );
}
}
-40
View File
@@ -1,40 +0,0 @@
/* NotebookUtil.h
*
* Copyright (C) 2015 Jaye 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 model_NotebookUtil_h
#define model_NotebookUtil_h
#include <QWidget>
#include <QTabWidget>
namespace glabels
{
namespace NotebookUtil
{
void establishSize( QTabWidget* notebook );
}
}
#endif // model_NotebookUtil_h
+40
View File
@@ -0,0 +1,40 @@
// NotebookUtil.hpp
//
// Copyright (C) 2015 Jaye 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 model_NotebookUtil_hpp
#define model_NotebookUtil_hpp
#include <QWidget>
#include <QTabWidget>
namespace glabels
{
namespace NotebookUtil
{
void establishSize( QTabWidget* notebook );
}
}
#endif // model_NotebookUtil_hpp
+817 -816
View File
File diff suppressed because it is too large Load Diff
-127
View File
@@ -1,127 +0,0 @@
/* ObjectEditor.h
*
* Copyright (C) 2013 Jaye 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 ObjectEditor_h
#define ObjectEditor_h
#include "ui_ObjectEditor.h"
#include "model/Model.h"
#include "model/ModelObject.h"
#include <QButtonGroup>
namespace glabels
{
// Forward references
class UndoRedoModel;
///
/// Object Editor Widget
///
class ObjectEditor : public QWidget, public Ui_ObjectEditor
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ObjectEditor( QWidget *parent = nullptr );
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void hidePages();
void loadImagePage();
void loadLineFillPage();
void loadPositionPage();
void loadRectSizePage();
void loadLineSizePage();
void loadTextPage();
void loadBarcodePage();
void loadShadowPage();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onSettingsChanged();
void onLabelSizeChanged();
void onSelectionChanged();
void onFieldsAvailableChanged();
void onObjectChanged();
void onObjectMoved();
void onObjectDestroyed();
void onLineControlsChanged();
void onFillControlsChanged();
void onImageFileButtonClicked();
void onImageKeySelected( QString key );
void onPositionControlsChanged();
void onRectSizeControlsChanged();
void onLineSizeControlsChanged();
void onTextControlsChanged();
void onTextInsertFieldKeySelected( QString key );
void onBarcodeControlsChanged();
void onBarcodeInsertFieldKeySelected( QString key );
void onResetImageSize();
void onShadowControlsChanged();
void onChanged();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
model::Model* mModel;
model::ModelObject* mObject;
UndoRedoModel* mUndoRedoModel;
model::Units mUnits;
int mSpinDigits;
double mSpinStep;
QButtonGroup* textHAlignGroup;
QButtonGroup* textVAlignGroup;
QString mImageCwd;
bool mBlocked;
};
}
#endif // ObjectEditor_h
+127
View File
@@ -0,0 +1,127 @@
// ObjectEditor.hpp
//
// Copyright (C) 2013 Jaye 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 ObjectEditor_hpp
#define ObjectEditor_hpp
#include "ui_ObjectEditor.h"
#include "model/Model.hpp"
#include "model/ModelObject.hpp"
#include <QButtonGroup>
namespace glabels
{
// Forward references
class UndoRedoModel;
///
/// Object Editor Widget
///
class ObjectEditor : public QWidget, public Ui_ObjectEditor
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ObjectEditor( QWidget *parent = nullptr );
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void hidePages();
void loadImagePage();
void loadLineFillPage();
void loadPositionPage();
void loadRectSizePage();
void loadLineSizePage();
void loadTextPage();
void loadBarcodePage();
void loadShadowPage();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onSettingsChanged();
void onLabelSizeChanged();
void onSelectionChanged();
void onFieldsAvailableChanged();
void onObjectChanged();
void onObjectMoved();
void onObjectDestroyed();
void onLineControlsChanged();
void onFillControlsChanged();
void onImageFileButtonClicked();
void onImageKeySelected( QString key );
void onPositionControlsChanged();
void onRectSizeControlsChanged();
void onLineSizeControlsChanged();
void onTextControlsChanged();
void onTextInsertFieldKeySelected( QString key );
void onBarcodeControlsChanged();
void onBarcodeInsertFieldKeySelected( QString key );
void onResetImageSize();
void onShadowControlsChanged();
void onChanged();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
model::Model* mModel;
model::ModelObject* mObject;
UndoRedoModel* mUndoRedoModel;
model::Units mUnits;
int mSpinDigits;
double mSpinStep;
QButtonGroup* textHAlignGroup;
QButtonGroup* textVAlignGroup;
QString mImageCwd;
bool mBlocked;
};
}
#endif // ObjectEditor_hpp
+146 -145
View File
@@ -1,172 +1,173 @@
/* PreferencesDialog.cpp
*
* Copyright (C) 2016 Jaye 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/>.
*/
// PreferencesDialog.cpp
//
// Copyright (C) 2016 Jaye 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 "PreferencesDialog.h"
#include "model/Settings.h"
#include "PreferencesDialog.hpp"
#include "model/Settings.hpp"
namespace glabels
{
///
/// Constructor
///
PreferencesDialog::PreferencesDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
auto units = model::Settings::units();
switch ( units.toEnum() )
{
case model::Units::IN:
unitsInchesRadio->setChecked( true );
break;
case model::Units::MM:
unitsMillimetersRadio->setChecked( true );
break;
case model::Units::CM:
unitsCentimetersRadio->setChecked( true );
break;
case model::Units::PC:
unitsPicasRadio->setChecked( true );
break;
default:
unitsPointsRadio->setChecked( true );
break;
}
///
/// Constructor
///
PreferencesDialog::PreferencesDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
switch ( model::Settings::gridOrigin() )
{
case model::Settings::ORIGIN_CENTER:
gridOriginCenterRadio->setChecked( true );
break;
case model::Settings::ORIGIN_TL:
gridOriginTlRadio->setChecked( true );
break;
default:
gridOriginTlRadio->setChecked( true );
break;
}
auto units = model::Settings::units();
switch ( units.toEnum() )
{
case model::Units::IN:
unitsInchesRadio->setChecked( true );
break;
case model::Units::MM:
unitsMillimetersRadio->setChecked( true );
break;
case model::Units::CM:
unitsCentimetersRadio->setChecked( true );
break;
case model::Units::PC:
unitsPicasRadio->setChecked( true );
break;
default:
unitsPointsRadio->setChecked( true );
break;
}
auto gridSpacing = model::Settings::gridSpacing();
gridSpacingSpin->setDecimals( units.resolutionDigits() );
gridSpacingSpin->setSingleStep( units.resolution() );
gridSpacingSpin->setMinimum( units.resolution() );
gridSpacingSpin->setSuffix( " " + units.toIdString() );
gridSpacingSpin->setValue( gridSpacing.inUnits( units ) );
switch ( model::Settings::gridOrigin() )
{
case model::Settings::ORIGIN_CENTER:
gridOriginCenterRadio->setChecked( true );
break;
case model::Settings::ORIGIN_TL:
gridOriginTlRadio->setChecked( true );
break;
default:
gridOriginTlRadio->setChecked( true );
break;
}
connect( model::Settings::instance(), SIGNAL(changed()),
this, SLOT(onSettingsChanged()) );
}
auto gridSpacing = model::Settings::gridSpacing();
gridSpacingSpin->setDecimals( units.resolutionDigits() );
gridSpacingSpin->setSingleStep( units.resolution() );
gridSpacingSpin->setMinimum( units.resolution() );
gridSpacingSpin->setSuffix( " " + units.toIdString() );
gridSpacingSpin->setValue( gridSpacing.inUnits( units ) );
///
/// Units Radios Changed
///
void PreferencesDialog::onUnitsRadiosChanged()
{
if ( unitsInchesRadio->isChecked() )
{
model::Settings::setUnits( model::Units::in() );
}
else if ( unitsMillimetersRadio->isChecked() )
{
model::Settings::setUnits( model::Units::mm() );
}
else if ( unitsCentimetersRadio->isChecked() )
{
model::Settings::setUnits( model::Units::cm() );
}
else if ( unitsPicasRadio->isChecked() )
{
model::Settings::setUnits( model::Units::pc() );
}
else
{
model::Settings::setUnits( model::Units::pt() );
}
}
connect( model::Settings::instance(), SIGNAL(changed()),
this, SLOT(onSettingsChanged()) );
}
///
/// Grid Origin Radios Changed
///
void PreferencesDialog::onGridOriginRadiosChanged()
{
if ( gridOriginTlRadio->isChecked() )
{
model::Settings::setGridOrigin( model::Settings::ORIGIN_TL );
}
else if ( gridOriginCenterRadio->isChecked() )
{
model::Settings::setGridOrigin( model::Settings::ORIGIN_CENTER );
}
}
///
/// Units Radios Changed
///
void PreferencesDialog::onUnitsRadiosChanged()
{
if ( unitsInchesRadio->isChecked() )
{
model::Settings::setUnits( model::Units::in() );
}
else if ( unitsMillimetersRadio->isChecked() )
{
model::Settings::setUnits( model::Units::mm() );
}
else if ( unitsCentimetersRadio->isChecked() )
{
model::Settings::setUnits( model::Units::cm() );
}
else if ( unitsPicasRadio->isChecked() )
{
model::Settings::setUnits( model::Units::pc() );
}
else
{
model::Settings::setUnits( model::Units::pt() );
}
}
///
/// Grid Spacing Spin Changed
///
void PreferencesDialog::onGridSpacingSpinChanged()
{
auto units = model::Settings::units();
auto spacing = model::Distance( gridSpacingSpin->value(), units );
model::Settings::setGridSpacing( spacing );
}
///
/// Grid Origin Radios Changed
///
void PreferencesDialog::onGridOriginRadiosChanged()
{
if ( gridOriginTlRadio->isChecked() )
{
model::Settings::setGridOrigin( model::Settings::ORIGIN_TL );
}
else if ( gridOriginCenterRadio->isChecked() )
{
model::Settings::setGridOrigin( model::Settings::ORIGIN_CENTER );
}
}
///
/// Grid Spacing Reset Button Clicked
///
void PreferencesDialog::onGridSpacingResetButtonClicked()
{
model::Settings::resetGridSpacing();
}
///
/// Grid Spacing Spin Changed
///
void PreferencesDialog::onGridSpacingSpinChanged()
{
auto units = model::Settings::units();
auto spacing = model::Distance( gridSpacingSpin->value(), units );
model::Settings::setGridSpacing( spacing );
}
///
/// Settings Changed
///
void PreferencesDialog::onSettingsChanged()
{
auto units = model::Settings::units();
auto gridSpacing = model::Settings::gridSpacing();
///
/// Grid Spacing Reset Button Clicked
///
void PreferencesDialog::onGridSpacingResetButtonClicked()
{
model::Settings::resetGridSpacing();
}
gridSpacingSpin->blockSignals( true );
gridSpacingSpin->setDecimals( units.resolutionDigits() );
gridSpacingSpin->setSingleStep( units.resolution() );
gridSpacingSpin->setMinimum( units.resolution() );
gridSpacingSpin->setSuffix( " " + units.toIdString() );
gridSpacingSpin->setValue( gridSpacing.inUnits( units ) );
gridSpacingSpin->blockSignals( false );
}
///
/// Settings Changed
///
void PreferencesDialog::onSettingsChanged()
{
auto units = model::Settings::units();
auto gridSpacing = model::Settings::gridSpacing();
gridSpacingSpin->blockSignals( true );
gridSpacingSpin->setDecimals( units.resolutionDigits() );
gridSpacingSpin->setSingleStep( units.resolution() );
gridSpacingSpin->setMinimum( units.resolution() );
gridSpacingSpin->setSuffix( " " + units.toIdString() );
gridSpacingSpin->setValue( gridSpacing.inUnits( units ) );
gridSpacingSpin->blockSignals( false );
}
} // namespace glabels
-60
View File
@@ -1,60 +0,0 @@
/* PreferencesDialog.h
*
* Copyright (C) 2016 Jaye 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 PreferencesDialog_h
#define PreferencesDialog_h
#include "ui_PreferencesDialog.h"
namespace glabels
{
///
/// New Label Dialog Widget
///
class PreferencesDialog : public QDialog, public Ui_PreferencesDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
PreferencesDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onUnitsRadiosChanged();
void onGridOriginRadiosChanged();
void onGridSpacingSpinChanged();
void onGridSpacingResetButtonClicked();
void onSettingsChanged();
};
}
#endif // PreferencesDialog_h
+60
View File
@@ -0,0 +1,60 @@
// PreferencesDialog.hpp
//
// Copyright (C) 2016 Jaye 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 PreferencesDialog_hpp
#define PreferencesDialog_hpp
#include "ui_PreferencesDialog.h"
namespace glabels
{
///
/// New Label Dialog Widget
///
class PreferencesDialog : public QDialog, public Ui_PreferencesDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
PreferencesDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onUnitsRadiosChanged();
void onGridOriginRadiosChanged();
void onGridSpacingSpinChanged();
void onGridSpacingResetButtonClicked();
void onSettingsChanged();
};
}
#endif // PreferencesDialog_hpp
+209 -208
View File
@@ -1,253 +1,254 @@
/* Preview.cpp
*
* Copyright (C) 2013-2016 Jaye 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/>.
*/
// Preview.cpp
//
// Copyright (C) 2013-2016 Jaye 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 "Preview.h"
#include "PreviewOverlayItem.h"
#include "RollTemplatePath.h"
#include "Preview.hpp"
#include "PreviewOverlayItem.hpp"
#include "RollTemplatePath.hpp"
#include <QDebug>
#include <QGraphicsDropShadowEffect>
#include <QGraphicsRectItem>
#include <QtDebug>
//
// Private
//
namespace
{
const QColor paperColor( 242, 242, 242 );
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( 192, 192, 192 );
const double labelOutlineWidthPixels = 1;
const QColor labelNumberColor( 192, 192, 255, 128 );
const QString labelNumberFontFamily( "Sans" );
const double labelNumberScale = 0.5;
}
namespace glabels
{
//
// Private
//
namespace
{
const QColor paperColor( 242, 242, 242 );
const QColor paperOutlineColor( 0, 0, 0 );
const double paperOutlineWidthPixels = 1;
///
/// Constructor
///
Preview::Preview( QWidget *parent )
: QGraphicsView(parent), mModel(nullptr), mRenderer(nullptr)
{
mScene = new QGraphicsScene();
setScene( mScene );
const QColor shadowColor( 64, 64, 64 );
const double shadowOffsetPixels = 3;
const double shadowRadiusPixels = 12;
setAttribute(Qt::WA_TranslucentBackground);
viewport()->setAutoFillBackground(false);
const QColor labelColor( 255, 255, 255 );
const QColor labelOutlineColor( 192, 192, 192 );
const double labelOutlineWidthPixels = 1;
const QColor labelNumberColor( 192, 192, 255, 128 );
const QString labelNumberFontFamily( "Sans" );
const double labelNumberScale = 0.5;
}
setFrameStyle( QFrame::NoFrame );
setRenderHints( QPainter::Antialiasing );
}
///
/// Constructor
///
Preview::Preview( QWidget *parent )
: QGraphicsView(parent), mModel(nullptr), mRenderer(nullptr)
{
mScene = new QGraphicsScene();
setScene( mScene );
///
/// Set renderer
///
void Preview::setRenderer( const model::PageRenderer* renderer )
{
mRenderer = renderer;
setAttribute(Qt::WA_TranslucentBackground);
viewport()->setAutoFillBackground(false);
setFrameStyle( QFrame::NoFrame );
setRenderHints( QPainter::Antialiasing );
}
connect( mRenderer, SIGNAL(changed()), this, SLOT(onRendererChanged()) );
onRendererChanged();
}
///
/// Set renderer
///
void Preview::setRenderer( const model::PageRenderer* renderer )
{
mRenderer = renderer;
///
/// Renderer changed handler
///
void Preview::onRendererChanged()
{
mModel = mRenderer->model();
connect( mRenderer, SIGNAL(changed()), this, SLOT(onRendererChanged()) );
onRendererChanged();
}
mScene->clear();
if ( mModel != nullptr )
{
auto tmplate = mModel->tmplate();
// For "Roll" templates, allow extra room to draw continuation break lines.
model::Distance drawHeight = mModel->tmplate().pageHeight();
model::Distance drawOffset = 0;
if ( tmplate.isRoll() )
{
drawHeight = 1.2 * tmplate.pageHeight();
drawOffset = 0.1 * tmplate.pageHeight();
}
// Set scene up with a 5% margin around paper
model::Distance x = -0.05 * tmplate.pageWidth();
model::Distance y = -0.05 * drawHeight - drawOffset;
model::Distance w = 1.10 * tmplate.pageWidth();
model::Distance h = 1.10 * drawHeight;
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
drawPaper();
drawLabels();
drawPreviewOverlay();
drawLabelNumberOverlay();
}
}
///
/// Renderer changed handler
///
void Preview::onRendererChanged()
{
mModel = mRenderer->model();
void Preview::drawLabelNumberOverlaySingle( model::Distance x,
model::Distance y,
const QPainterPath& path,
uint32_t labelInstance)
{
QBrush brush( labelNumberColor );
mScene->clear();
auto frame = mModel->tmplate().frame();
if ( mModel != nullptr )
{
auto tmplate = mModel->tmplate();
model::Distance w = frame->w();
model::Distance h = frame->h();
// For "Roll" templates, allow extra room to draw continuation break lines.
model::Distance drawHeight = mModel->tmplate().pageHeight();
model::Distance drawOffset = 0;
if ( tmplate.isRoll() )
{
drawHeight = 1.2 * tmplate.pageHeight();
drawOffset = 0.1 * tmplate.pageHeight();
}
// Set scene up with a 5% margin around paper
model::Distance x = -0.05 * tmplate.pageWidth();
model::Distance y = -0.05 * drawHeight - drawOffset;
model::Distance w = 1.10 * tmplate.pageWidth();
model::Distance h = 1.10 * drawHeight;
model::Distance minWH = min( w, h );
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
auto labelText = QString::number(labelInstance);
QGraphicsSimpleTextItem *labelNumberItem = new QGraphicsSimpleTextItem( labelText );
labelNumberItem->setBrush( brush );
labelNumberItem->setFont( QFont( labelNumberFontFamily, minWH.pt()*labelNumberScale, QFont::Bold ) );
labelNumberItem->setPos( (x+w/2).pt(), (y+h/2).pt() );
QRectF rect = labelNumberItem->boundingRect();
labelNumberItem->setPos(labelNumberItem->x() - (rect.width() / 2), labelNumberItem->y() - (rect.height() / 2));
drawPaper();
drawLabels();
drawPreviewOverlay();
drawLabelNumberOverlay();
}
}
mScene->addItem( labelNumberItem );
}
void Preview::drawLabelNumberOverlaySingle( model::Distance x,
model::Distance y,
const QPainterPath& path,
uint32_t labelInstance)
{
QBrush brush( labelNumberColor );
void Preview::drawLabelNumberOverlay()
{
auto frame = mModel->tmplate().frame();
auto i = 0;
auto frame = mModel->tmplate().frame();
model::Distance w = frame->w();
model::Distance h = frame->h();
model::Distance minWH = min( w, h );
auto labelText = QString::number(labelInstance);
QGraphicsSimpleTextItem *labelNumberItem = new QGraphicsSimpleTextItem( labelText );
labelNumberItem->setBrush( brush );
labelNumberItem->setFont( QFont( labelNumberFontFamily, minWH.pt()*labelNumberScale, QFont::Bold ) );
labelNumberItem->setPos( (x+w/2).pt(), (y+h/2).pt() );
QRectF rect = labelNumberItem->boundingRect();
labelNumberItem->setPos(labelNumberItem->x() - (rect.width() / 2), labelNumberItem->y() - (rect.height() / 2));
mScene->addItem( labelNumberItem );
}
for ( model::Point origin : frame->getOrigins() )
{
i++;
drawLabelNumberOverlaySingle( origin.x(), origin.y(), frame->path(), i);
}
}
void Preview::drawLabelNumberOverlay()
{
auto frame = mModel->tmplate().frame();
auto i = 0;
for ( model::Point origin : frame->getOrigins() )
{
i++;
drawLabelNumberOverlaySingle( origin.x(), origin.y(), frame->path(), i);
}
}
///
/// Resize Event Handler
///
void Preview::resizeEvent( QResizeEvent* event )
{
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
}
///
/// Resize Event Handler
///
void Preview::resizeEvent( QResizeEvent* event )
{
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
}
///
/// Draw Paper
///
void Preview::drawPaper()
{
auto *shadowEffect = new QGraphicsDropShadowEffect();
shadowEffect->setColor( shadowColor );
shadowEffect->setOffset( shadowOffsetPixels );
shadowEffect->setBlurRadius( shadowRadiusPixels );
///
/// Draw Paper
///
void Preview::drawPaper()
{
auto *shadowEffect = new QGraphicsDropShadowEffect();
shadowEffect->setColor( shadowColor );
shadowEffect->setOffset( shadowOffsetPixels );
shadowEffect->setBlurRadius( shadowRadiusPixels );
QBrush brush( paperColor );
QPen pen( paperOutlineColor );
pen.setCosmetic( true );
pen.setWidthF( paperOutlineWidthPixels );
QBrush brush( paperColor );
QPen pen( paperOutlineColor );
pen.setCosmetic( true );
pen.setWidthF( paperOutlineWidthPixels );
QAbstractGraphicsShapeItem* pageItem;
auto tmplate = mModel->tmplate();
if ( !tmplate.isRoll() )
{
pageItem = new QGraphicsRectItem( 0, 0, tmplate.pageWidth().pt(), tmplate.pageHeight().pt() );
}
else
{
pageItem = new QGraphicsPathItem( RollTemplatePath( tmplate ) );
}
pageItem->setBrush( brush );
pageItem->setPen( pen );
pageItem->setGraphicsEffect( shadowEffect );
mScene->addItem( pageItem );
}
QAbstractGraphicsShapeItem* pageItem;
auto tmplate = mModel->tmplate();
if ( !tmplate.isRoll() )
{
pageItem = new QGraphicsRectItem( 0, 0, tmplate.pageWidth().pt(), tmplate.pageHeight().pt() );
}
else
{
pageItem = new QGraphicsPathItem( RollTemplatePath( tmplate ) );
}
pageItem->setBrush( brush );
pageItem->setPen( pen );
pageItem->setGraphicsEffect( shadowEffect );
mScene->addItem( pageItem );
}
///
/// Draw Labels on Paper
///
void Preview::drawLabels()
{
auto frame = mModel->tmplate().frame();
///
/// Draw Labels on Paper
///
void Preview::drawLabels()
{
auto frame = mModel->tmplate().frame();
for ( model::Point origin : frame->getOrigins() )
{
drawLabel( origin.x(), origin.y(), frame->path() );
}
}
for ( model::Point origin : frame->getOrigins() )
{
drawLabel( origin.x(), origin.y(), frame->path() );
}
}
///
/// Draw a Single Label at x,y
///
void Preview::drawLabel( model::Distance x,
model::Distance y,
const QPainterPath& path )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
pen.setCosmetic( true );
pen.setWidthF( labelOutlineWidthPixels );
///
/// Draw a Single Label at x,y
///
void Preview::drawLabel( model::Distance x,
model::Distance y,
const QPainterPath& path )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
pen.setCosmetic( true );
pen.setWidthF( labelOutlineWidthPixels );
auto *labelOutlineItem = new QGraphicsPathItem( path );
labelOutlineItem->setBrush( brush );
labelOutlineItem->setPen( pen );
labelOutlineItem->setPos( x.pt(), y.pt() );
auto *labelOutlineItem = new QGraphicsPathItem( path );
labelOutlineItem->setBrush( brush );
labelOutlineItem->setPen( pen );
labelOutlineItem->setPos( x.pt(), y.pt() );
mScene->addItem( labelOutlineItem );
}
mScene->addItem( labelOutlineItem );
}
///
/// Draw Preview Overlay
///
void Preview::drawPreviewOverlay()
{
if ( mRenderer )
{
auto* overlayItem = new PreviewOverlayItem( mRenderer );
mScene->addItem( overlayItem );
}
}
///
/// Draw Preview Overlay
///
void Preview::drawPreviewOverlay()
{
if ( mRenderer )
{
auto* overlayItem = new PreviewOverlayItem( mRenderer );
mScene->addItem( overlayItem );
}
}
} // namespace glabels
-99
View File
@@ -1,99 +0,0 @@
/* Preview.h
*
* Copyright (C) 2013-2016 Jaye 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 Preview_h
#define Preview_h
#include "model/Distance.h"
#include "model/Model.h"
#include "model/PageRenderer.h"
#include <QGraphicsView>
#include <QGraphicsScene>
namespace glabels
{
///
/// Preview Widget
///
class Preview : public QGraphicsView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
Preview( QWidget *parent = nullptr );
/////////////////////////////////
// Renderer
/////////////////////////////////
public:
void setRenderer( const model::PageRenderer* renderer );
private slots:
void onRendererChanged();
/////////////////////////////////////
// Event handlers
/////////////////////////////////////
protected:
void resizeEvent( QResizeEvent* event ) override;
/////////////////////////////////
// Internal Methods
/////////////////////////////////
private:
void drawPaper();
void drawLabels();
void drawLabel( model::Distance x,
model::Distance y,
const QPainterPath& path );
void drawPreviewOverlay();
void drawLabelNumberOverlaySingle( model::Distance x,
model::Distance y,
const QPainterPath& path,
uint32_t labelInstance);
void drawLabelNumberOverlay();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
const model::Model* mModel;
const model::PageRenderer* mRenderer;
QGraphicsScene* mScene;
};
}
#endif // Preview_h
+99
View File
@@ -0,0 +1,99 @@
// Preview.hpp
//
// Copyright (C) 2013-2016 Jaye 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 Preview_hpp
#define Preview_hpp
#include "model/Distance.hpp"
#include "model/Model.hpp"
#include "model/PageRenderer.hpp"
#include <QGraphicsView>
#include <QGraphicsScene>
namespace glabels
{
///
/// Preview Widget
///
class Preview : public QGraphicsView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
Preview( QWidget *parent = nullptr );
/////////////////////////////////
// Renderer
/////////////////////////////////
public:
void setRenderer( const model::PageRenderer* renderer );
private slots:
void onRendererChanged();
/////////////////////////////////////
// Event handlers
/////////////////////////////////////
protected:
void resizeEvent( QResizeEvent* event ) override;
/////////////////////////////////
// Internal Methods
/////////////////////////////////
private:
void drawPaper();
void drawLabels();
void drawLabel( model::Distance x,
model::Distance y,
const QPainterPath& path );
void drawPreviewOverlay();
void drawLabelNumberOverlaySingle( model::Distance x,
model::Distance y,
const QPainterPath& path,
uint32_t labelInstance);
void drawLabelNumberOverlay();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
const model::Model* mModel;
const model::PageRenderer* mRenderer;
QGraphicsScene* mScene;
};
}
#endif // Preview_hpp
+36 -35
View File
@@ -1,49 +1,50 @@
/* PreviewOverlayItem.cpp
*
* Copyright (C) 2013 Jaye 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/>.
*/
// PreviewOverlayItem.cpp
//
// Copyright (C) 2013 Jaye 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 "PreviewOverlayItem.h"
#include "model/PageRenderer.h"
#include "PreviewOverlayItem.hpp"
#include <QtDebug>
#include "model/PageRenderer.hpp"
#include <QDebug>
namespace glabels
{
PreviewOverlayItem::PreviewOverlayItem( const model::PageRenderer* renderer, QGraphicsItem* parent )
: QGraphicsItem(parent), mRenderer(renderer)
{
// empty
}
PreviewOverlayItem::PreviewOverlayItem( const model::PageRenderer* renderer, QGraphicsItem* parent )
: QGraphicsItem(parent), mRenderer(renderer)
{
// empty
}
QRectF PreviewOverlayItem::boundingRect() const
{
return mRenderer->pageRect();
}
QRectF PreviewOverlayItem::boundingRect() const
{
return mRenderer->pageRect();
}
void PreviewOverlayItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
mRenderer->printPage( painter );
}
void PreviewOverlayItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget )
{
mRenderer->printPage( painter );
}
} // namespace glabels
-65
View File
@@ -1,65 +0,0 @@
/* PreviewOverlayItem.h
*
* Copyright (C) 2013 Jaye 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 PreviewOverlayItem_h
#define PreviewOverlayItem_h
#include "model/PageRenderer.h"
#include <QGraphicsItem>
namespace glabels
{
///
/// PreviewOverlayItem Widget
///
class PreviewOverlayItem : public QGraphicsItem
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
PreviewOverlayItem( const model::PageRenderer* renderer, QGraphicsItem* parent = nullptr );
/////////////////////////////////////
// Virtual method implementations
/////////////////////////////////////
public:
QRectF boundingRect() const override;
void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) override;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
const model::PageRenderer* mRenderer;
};
}
#endif // PreviewOverlayItem_h
+65
View File
@@ -0,0 +1,65 @@
// PreviewOverlayItem.hpp
//
// Copyright (C) 2013 Jaye 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 PreviewOverlayItem_hpp
#define PreviewOverlayItem_hpp
#include "model/PageRenderer.hpp"
#include <QGraphicsItem>
namespace glabels
{
///
/// PreviewOverlayItem Widget
///
class PreviewOverlayItem : public QGraphicsItem
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
PreviewOverlayItem( const model::PageRenderer* renderer, QGraphicsItem* parent = nullptr );
/////////////////////////////////////
// Virtual method implementations
/////////////////////////////////////
public:
QRectF boundingRect() const override;
void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) override;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
const model::PageRenderer* mRenderer;
};
}
#endif // PreviewOverlayItem_hpp
+289 -289
View File
@@ -1,29 +1,29 @@
/* PrintView.cpp
*
* Copyright (C) 2013-2016 Jaye 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/>.
*/
// PrintView.cpp
//
// Copyright (C) 2013-2016 Jaye 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 "PrintView.h"
#include "PrintView.hpp"
#include "PrinterMonitor.h"
#include "PrinterMonitor.hpp"
#include "model/Settings.h"
#include "model/Settings.hpp"
#include <QDebug>
#include <QFileDialog>
@@ -36,323 +36,323 @@
namespace glabels
{
///
/// Constructor
///
PrintView::PrintView( QWidget *parent )
: QWidget(parent), mModel(nullptr), mBlocked(false)
{
setupUi( this );
///
/// Constructor
///
PrintView::PrintView( QWidget *parent )
: QWidget(parent), mModel(nullptr), mBlocked(false)
{
setupUi( this );
titleLabel->setText( QString( "<span style='font-size:18pt;'>%1</span>" ).arg( tr("Print") ) );
auto* printerMonitor = PrinterMonitor::instance();
loadDestinations( printerMonitor->availablePrinters() );
connect( printerMonitor, SIGNAL(availablePrintersChanged(QStringList)),
this, SLOT(onAvailablePrintersChanged(QStringList)) );
setDestination( model::Settings::recentPrinter() );
titleLabel->setText( QString( "<span style='font-size:18pt;'>%1</span>" ).arg( tr("Print") ) );
preview->setRenderer( &mRenderer );
}
auto* printerMonitor = PrinterMonitor::instance();
loadDestinations( printerMonitor->availablePrinters() );
connect( printerMonitor, SIGNAL(availablePrintersChanged(QStringList)),
this, SLOT(onAvailablePrintersChanged(QStringList)) );
setDestination( model::Settings::recentPrinter() );
preview->setRenderer( &mRenderer );
}
///
/// Set Model
///
void PrintView::setModel( model::Model* model )
{
mModel = model;
mRenderer.setModel( mModel );
///
/// Set Model
///
void PrintView::setModel( model::Model* model )
{
mModel = model;
mRenderer.setModel( mModel );
connect( mModel, SIGNAL(changed()), this, SLOT(onModelChanged()) );
connect( mModel, SIGNAL(changed()), this, SLOT(onModelChanged()) );
onModelChanged();
}
onModelChanged();
}
///
/// Available printers changed handler
///
void PrintView::onAvailablePrintersChanged( QStringList printers )
{
auto savedSelection = destinationCombo->currentText();
loadDestinations( printers );
setDestination( savedSelection );
}
///
/// Available printers changed handler
///
void PrintView::onAvailablePrintersChanged( QStringList printers )
{
auto savedSelection = destinationCombo->currentText();
loadDestinations( printers );
setDestination( savedSelection );
}
///
/// Model changed handler
///
void PrintView::onModelChanged()
{
printRangeStartPositionSpin->setRange( 1, mModel->frame()->nLabels() );
printRangeLastPositionSpin->setRange( 1, mModel->frame()->nLabels() );
mergeStartPositionSpin->setRange( 1, mModel->frame()->nLabels() );
///
/// Model changed handler
///
void PrintView::onModelChanged()
{
printRangeStartPositionSpin->setRange( 1, mModel->frame()->nLabels() );
printRangeLastPositionSpin->setRange( 1, mModel->frame()->nLabels() );
mergeStartPositionSpin->setRange( 1, mModel->frame()->nLabels() );
printRangeBox->setVisible( mModel->merge()->keys().empty() );
mergeBox->setVisible( !mModel->merge()->keys().empty() );
mergeOnlyOptions->setVisible( !mModel->merge()->keys().empty() );
printRangeBox->setVisible( mModel->merge()->keys().empty() );
mergeBox->setVisible( !mModel->merge()->keys().empty() );
mergeOnlyOptions->setVisible( !mModel->merge()->keys().empty() );
onFormChanged();
}
onFormChanged();
}
///
/// Update view
///
void PrintView::updateView()
{
if ( mRenderer.nPages() == 1 )
{
if ( mRenderer.nItems() == 1 )
{
printDescriptionLabel->setText( tr("(Will print a total of 1 item on 1 page.)") );
}
else
{
printDescriptionLabel->setText( tr("(Will print a total of %1 items on 1 page.)")
.arg(mRenderer.nItems()) );
}
}
else
{
printDescriptionLabel->setText( tr("(Will print a total of %1 items on %2 pages.)")
.arg(mRenderer.nItems()).arg(mRenderer.nPages()) );
}
///
/// Update view
///
void PrintView::updateView()
{
if ( mRenderer.nPages() == 1 )
{
if ( mRenderer.nItems() == 1 )
{
printDescriptionLabel->setText( tr("(Will print a total of 1 item on 1 page.)") );
}
else
{
printDescriptionLabel->setText( tr("(Will print a total of %1 items on 1 page.)")
.arg(mRenderer.nItems()) );
}
}
else
{
printDescriptionLabel->setText( tr("(Will print a total of %1 items on %2 pages.)")
.arg(mRenderer.nItems()).arg(mRenderer.nPages()) );
}
pageSpin->setRange( 1, mRenderer.nPages() );
nPagesLabel->setText( QString::number( mRenderer.nPages() ) );
pageSpin->setRange( 1, mRenderer.nPages() );
nPagesLabel->setText( QString::number( mRenderer.nPages() ) );
mRenderer.setIPage( pageSpin->value() - 1 ); // Update preview
}
mRenderer.setIPage( pageSpin->value() - 1 ); // Update preview
}
///
/// Form changed handler
///
void PrintView::onFormChanged()
{
if ( !mBlocked )
{
mBlocked = true;
if ( mModel->merge()->keys().empty() )
{
// Simple project (no merge)
if ( printRangePagesRadio->isChecked() )
{
// Print full sheets of labels
int nItemsPerPage = mModel->frame()->nLabels();
///
/// Form changed handler
///
void PrintView::onFormChanged()
{
if ( !mBlocked )
{
mBlocked = true;
printRangePagesSpin->setEnabled( true );
if ( mModel->merge()->keys().empty() )
{
// Simple project (no merge)
if ( printRangePagesRadio->isChecked() )
{
// Print full sheets of labels
int nItemsPerPage = mModel->frame()->nLabels();
printRangeStartPositionSpin->setEnabled( false );
printRangeLastPositionSpin->setEnabled( false );
printRangePagesSpin->setEnabled( true );
printRangeStartPositionSpin->setMaximum( nItemsPerPage );
printRangeLastPositionSpin->setMinimum( 1 );
printRangeStartPositionSpin->setEnabled( false );
printRangeLastPositionSpin->setEnabled( false );
printRangeStartPositionSpin->setValue( 1 );
printRangeLastPositionSpin->setValue( nItemsPerPage );
printRangeStartPositionSpin->setMaximum( nItemsPerPage );
printRangeLastPositionSpin->setMinimum( 1 );
mRenderer.setNCopies( printRangePagesSpin->value()*nItemsPerPage );
mRenderer.setStartItem( 0 );
}
else
{
// Print a partial sheet of labels
int iStart = printRangeStartPositionSpin->value();
int iLast = printRangeLastPositionSpin->value();
printRangeStartPositionSpin->setValue( 1 );
printRangeLastPositionSpin->setValue( nItemsPerPage );
printRangePagesSpin->setEnabled( false );
mRenderer.setNCopies( printRangePagesSpin->value()*nItemsPerPage );
mRenderer.setStartItem( 0 );
}
else
{
// Print a partial sheet of labels
int iStart = printRangeStartPositionSpin->value();
int iLast = printRangeLastPositionSpin->value();
printRangeStartPositionSpin->setEnabled( true );
printRangeLastPositionSpin->setEnabled( true );
printRangePagesSpin->setEnabled( false );
printRangeStartPositionSpin->setMaximum( iLast );
printRangeLastPositionSpin->setMinimum( iStart );
printRangeStartPositionSpin->setEnabled( true );
printRangeLastPositionSpin->setEnabled( true );
mRenderer.setNCopies( iLast - iStart + 1 );
mRenderer.setStartItem( iStart - 1 );
}
}
else
{
// Project with merge
bool isMultipleCopies = mergeCopiesSpin->value() > 1;
printRangeStartPositionSpin->setMaximum( iLast );
printRangeLastPositionSpin->setMinimum( iStart );
mergeCollateCombo->setEnabled ( isMultipleCopies );
mergeGroupCombo->setEnabled ( isMultipleCopies );
mRenderer.setNCopies( mergeCopiesSpin->value() );
mRenderer.setIsCollated( mergeCollateCombo->currentIndex() == 1 );
mRenderer.setAreGroupsContiguous( mergeGroupCombo->currentIndex() == 0 );
mRenderer.setStartItem( mergeStartPositionSpin->value() - 1 );
}
mRenderer.setNCopies( iLast - iStart + 1 );
mRenderer.setStartItem( iStart - 1 );
}
}
else
{
// Project with merge
bool isMultipleCopies = mergeCopiesSpin->value() > 1;
mRenderer.setPrintOutlines( printOutlinesCheck->isChecked() );
mRenderer.setPrintCropMarks( printCropMarksCheck->isChecked() );
mRenderer.setPrintReverse( printReverseCheck->isChecked() );
mergeCollateCombo->setEnabled ( isMultipleCopies );
mergeGroupCombo->setEnabled ( isMultipleCopies );
updateView();
mBlocked = false;
}
}
mRenderer.setNCopies( mergeCopiesSpin->value() );
mRenderer.setIsCollated( mergeCollateCombo->currentIndex() == 1 );
mRenderer.setAreGroupsContiguous( mergeGroupCombo->currentIndex() == 0 );
mRenderer.setStartItem( mergeStartPositionSpin->value() - 1 );
}
mRenderer.setPrintOutlines( printOutlinesCheck->isChecked() );
mRenderer.setPrintCropMarks( printCropMarksCheck->isChecked() );
mRenderer.setPrintReverse( printReverseCheck->isChecked() );
updateView();
mBlocked = false;
}
}
///
/// Print Button Clicked handler
///
void PrintView::onPrintButtonClicked()
{
auto printerName = destinationCombo->currentText();
auto printerInfo = QPrinterInfo::printerInfo( printerName );
bool isPrinter = !printerInfo.isNull();
///
/// Print Button Clicked handler
///
void PrintView::onPrintButtonClicked()
{
auto printerName = destinationCombo->currentText();
auto printerInfo = QPrinterInfo::printerInfo( printerName );
bool isPrinter = !printerInfo.isNull();
QPrinter printer( QPrinter::HighResolution );
printer.setColorMode( QPrinter::Color );
QPrinter printer( QPrinter::HighResolution );
printer.setColorMode( QPrinter::Color );
if ( isPrinter )
{
printer.setPrinterName( printerName );
mRenderer.print( &printer );
model::Settings::setRecentPrinter( printerName );
}
else
{
QString fileName =
QFileDialog::getSaveFileName( this,
tr("Print to file (PDF)"),
defaultPdf(),
tr("PDF files (*.pdf);;All files (*)"),
nullptr,
QFileDialog::DontConfirmOverwrite );
if ( !fileName.isEmpty() )
{
if ( QFileInfo::exists(fileName) )
{
QMessageBox msgBox( this );
msgBox.setWindowTitle( tr("Print to file (PDF)") );
msgBox.setIcon( QMessageBox::Warning );
msgBox.setText( tr("%1 already exists.").arg(fileName) );
msgBox.setInformativeText( tr("Do you want to overwrite it?") );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
msgBox.setDefaultButton( QMessageBox::No );
if ( isPrinter )
{
printer.setPrinterName( printerName );
mRenderer.print( &printer );
model::Settings::setRecentPrinter( printerName );
}
else
{
QString fileName =
QFileDialog::getSaveFileName( this,
tr("Print to file (PDF)"),
defaultPdf(),
tr("PDF files (*.pdf);;All files (*)"),
nullptr,
QFileDialog::DontConfirmOverwrite );
if ( !fileName.isEmpty() )
{
if ( QFileInfo::exists(fileName) )
{
QMessageBox msgBox( this );
msgBox.setWindowTitle( tr("Print to file (PDF)") );
msgBox.setIcon( QMessageBox::Warning );
msgBox.setText( tr("%1 already exists.").arg(fileName) );
msgBox.setInformativeText( tr("Do you want to overwrite it?") );
msgBox.setStandardButtons( QMessageBox::Yes | QMessageBox::No );
msgBox.setDefaultButton( QMessageBox::No );
if ( msgBox.exec() == QMessageBox::No )
{
return;
}
}
printer.setOutputFileName( fileName );
printer.setOutputFormat( QPrinter::PdfFormat );
mRenderer.print( &printer );
}
}
}
if ( msgBox.exec() == QMessageBox::No )
{
return;
}
}
printer.setOutputFileName( fileName );
printer.setOutputFormat( QPrinter::PdfFormat );
mRenderer.print( &printer );
}
}
}
///
/// System Dialog Button Clicked handler
///
void PrintView::onSystemDialogButtonClicked()
{
QPrinter printer( QPrinter::HighResolution );
printer.setColorMode( QPrinter::Color );
printer.setPrinterName( destinationCombo->currentText() );
///
/// System Dialog Button Clicked handler
///
void PrintView::onSystemDialogButtonClicked()
{
QPrinter printer( QPrinter::HighResolution );
printer.setColorMode( QPrinter::Color );
printer.setPrinterName( destinationCombo->currentText() );
QPrintDialog printDialog( &printer, this );
printDialog.setOption( QAbstractPrintDialog::PrintToFile, true );
printDialog.setOption( QAbstractPrintDialog::PrintSelection, false );
printDialog.setOption( QAbstractPrintDialog::PrintPageRange, false );
printDialog.setOption( QAbstractPrintDialog::PrintShowPageSize, true );
printDialog.setOption( QAbstractPrintDialog::PrintCollateCopies, false );
printDialog.setOption( QAbstractPrintDialog::PrintCurrentPage, false );
QPrintDialog printDialog( &printer, this );
printDialog.setOption( QAbstractPrintDialog::PrintToFile, true );
printDialog.setOption( QAbstractPrintDialog::PrintSelection, false );
printDialog.setOption( QAbstractPrintDialog::PrintPageRange, false );
printDialog.setOption( QAbstractPrintDialog::PrintShowPageSize, true );
printDialog.setOption( QAbstractPrintDialog::PrintCollateCopies, false );
printDialog.setOption( QAbstractPrintDialog::PrintCurrentPage, false );
if ( printDialog.exec() == QDialog::Accepted )
{
mRenderer.print( &printer );
if ( printDialog.exec() == QDialog::Accepted )
{
mRenderer.print( &printer );
if ( !printer.printerName().isEmpty() )
{
model::Settings::setRecentPrinter( printer.printerName() );
}
}
}
if ( !printer.printerName().isEmpty() )
{
model::Settings::setRecentPrinter( printer.printerName() );
}
}
}
///
/// Load available printers
///
void PrintView::loadDestinations( const QStringList& printers )
{
destinationCombo->blockSignals( true );
destinationCombo->clear();
for ( auto& printerName : printers )
{
destinationCombo->addItem( QIcon::fromTheme( "glabels-print" ), printerName );
}
///
/// Load available printers
///
void PrintView::loadDestinations( const QStringList& printers )
{
destinationCombo->blockSignals( true );
if ( destinationCombo->count() )
{
destinationCombo->insertSeparator( destinationCombo->count() );
}
destinationCombo->addItem( QIcon::fromTheme( "glabels-file-new" ), tr( "Print to file (PDF)" ) );
destinationCombo->blockSignals( false );
}
destinationCombo->clear();
for ( auto& printerName : printers )
{
destinationCombo->addItem( QIcon::fromTheme( "glabels-print" ), printerName );
}
if ( destinationCombo->count() )
{
destinationCombo->insertSeparator( destinationCombo->count() );
}
destinationCombo->addItem( QIcon::fromTheme( "glabels-file-new" ), tr( "Print to file (PDF)" ) );
destinationCombo->blockSignals( false );
}
///
/// Generate default PDF filename
///
QString PrintView::defaultPdf()
{
if ( !mModel )
{
return "output.pdf";
}
return mModel->dirPath() + "/" + mModel->shortName() + ".pdf";
}
///
/// Generate default PDF filename
///
QString PrintView::defaultPdf()
{
if ( !mModel )
{
return "output.pdf";
}
return mModel->dirPath() + "/" + mModel->shortName() + ".pdf";
}
///
/// Set destination to printerName if valid, or to a fallback value
///
void PrintView::setDestination( const QString& printerName )
{
destinationCombo->blockSignals( true );
///
/// Set destination to printerName if valid, or to a fallback value
///
void PrintView::setDestination( const QString& printerName )
{
destinationCombo->blockSignals( true );
auto printerInfo = QPrinterInfo::printerInfo( printerName );
auto printerInfo = QPrinterInfo::printerInfo( printerName );
if ( !printerInfo.isNull() )
{
// printerName is a valid printer
destinationCombo->setCurrentText( printerName );
}
else
{
auto defaultPrinterName = QPrinterInfo::defaultPrinterName();
auto defaultPrinterInfo = QPrinterInfo::printerInfo( defaultPrinterName );
if ( !defaultPrinterInfo.isNull() )
{
// defaultPinterName is a valid printer
destinationCombo->setCurrentText( defaultPrinterName );
}
else
{
// No default printer available, set to first item in combo (probably "print to file")
destinationCombo->setCurrentIndex( 0 );
}
}
if ( !printerInfo.isNull() )
{
// printerName is a valid printer
destinationCombo->setCurrentText( printerName );
}
else
{
auto defaultPrinterName = QPrinterInfo::defaultPrinterName();
auto defaultPrinterInfo = QPrinterInfo::printerInfo( defaultPrinterName );
if ( !defaultPrinterInfo.isNull() )
{
// defaultPinterName is a valid printer
destinationCombo->setCurrentText( defaultPrinterName );
}
else
{
// No default printer available, set to first item in combo (probably "print to file")
destinationCombo->setCurrentIndex( 0 );
}
}
destinationCombo->blockSignals( false );
}
destinationCombo->blockSignals( false );
}
} // namespace glabels
-91
View File
@@ -1,91 +0,0 @@
/* PrintView.h
*
* Copyright (C) 2013-2016 Jaye 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 PrintView_h
#define PrintView_h
#include "ui_PrintView.h"
#include "model/Model.h"
#include "model/PageRenderer.h"
namespace glabels
{
///
/// Print View Widget
///
class PrintView : public QWidget, public Ui_PrintView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
PrintView( QWidget *parent = nullptr );
virtual ~PrintView() = default;
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( model::Model* model );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onAvailablePrintersChanged( QStringList printers );
void onModelChanged();
void updateView();
void onFormChanged();
void onPrintButtonClicked();
void onSystemDialogButtonClicked();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadDestinations( const QStringList& printers );
QString defaultPdf();
void setDestination( const QString& printerName );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
model::Model* mModel;
model::PageRenderer mRenderer;
bool mBlocked;
};
}
#endif // PrintView_h
+91
View File
@@ -0,0 +1,91 @@
// PrintView.hpp
//
// Copyright (C) 2013-2016 Jaye 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 PrintView_hpp
#define PrintView_hpp
#include "ui_PrintView.h"
#include "model/Model.hpp"
#include "model/PageRenderer.hpp"
namespace glabels
{
///
/// Print View Widget
///
class PrintView : public QWidget, public Ui_PrintView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
PrintView( QWidget *parent = nullptr );
virtual ~PrintView() = default;
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( model::Model* model );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onAvailablePrintersChanged( QStringList printers );
void onModelChanged();
void updateView();
void onFormChanged();
void onPrintButtonClicked();
void onSystemDialogButtonClicked();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadDestinations( const QStringList& printers );
QString defaultPdf();
void setDestination( const QString& printerName );
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
model::Model* mModel;
model::PageRenderer mRenderer;
bool mBlocked;
};
}
#endif // PrintView_hpp
+80 -80
View File
@@ -1,25 +1,25 @@
/* PrinterMonitor.cpp
*
* Copyright (C) 2025 Jaye 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/>.
*/
// PrinterMonitor.cpp
//
// Copyright (C) 2025 Jaye 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 "PrinterMonitor.h"
#include "PrinterMonitor.hpp"
#include <QDebug>
#include <QMutexLocker>
@@ -30,79 +30,79 @@
namespace glabels
{
///
/// Static data
///
std::unique_ptr<PrinterMonitor> PrinterMonitor::mInstance;
///
/// Static data
///
std::unique_ptr<PrinterMonitor> PrinterMonitor::mInstance;
///
/// Constructor
///
PrinterMonitor::PrinterMonitor()
{
using namespace std::chrono_literals;
///
/// Constructor
///
PrinterMonitor::PrinterMonitor()
{
using namespace std::chrono_literals;
mCurrentAvailablePrinters = QPrinterInfo::availablePrinterNames();
mCurrentAvailablePrinters = QPrinterInfo::availablePrinterNames();
mTimer.reset( new QTimer( this ) );
connect( mTimer.get(), SIGNAL(timeout()), this, SLOT(onTimerTimeout()) );
mTimer->start( 10s );
}
mTimer.reset( new QTimer( this ) );
connect( mTimer.get(), SIGNAL(timeout()), this, SLOT(onTimerTimeout()) );
mTimer->start( 10s );
}
///
/// Get singleton instance
///
PrinterMonitor* PrinterMonitor::instance()
{
if ( !mInstance )
{
mInstance.reset( new PrinterMonitor() );
}
///
/// Get singleton instance
///
PrinterMonitor* PrinterMonitor::instance()
{
if ( !mInstance )
{
mInstance.reset( new PrinterMonitor() );
}
return mInstance.get();
}
return mInstance.get();
}
///
/// Get available printers
///
QStringList PrinterMonitor::availablePrinters()
{
QMutexLocker mutex( &mCurrentAvailablePrintersMutex );
return mCurrentAvailablePrinters;
}
///
/// Get available printers
///
QStringList PrinterMonitor::availablePrinters()
{
QMutexLocker mutex( &mCurrentAvailablePrintersMutex );
return mCurrentAvailablePrinters;
}
///
/// On timer timeout
///
void PrinterMonitor::onTimerTimeout()
{
// Make sure previous poll is complete before starting a new one
if ( mPollStatus.isFinished() )
{
mPollStatus = QtConcurrent::run( &PrinterMonitor::asyncPoll, this );
}
}
///
/// On timer timeout
///
void PrinterMonitor::onTimerTimeout()
{
// Make sure previous poll is complete before starting a new one
if ( mPollStatus.isFinished() )
{
mPollStatus = QtConcurrent::run( &PrinterMonitor::asyncPoll, this );
}
}
///
/// Asynchronous poll
///
void PrinterMonitor::asyncPoll()
{
auto newAvailablePrinters = QPrinterInfo::availablePrinterNames();
if ( newAvailablePrinters != mCurrentAvailablePrinters )
{
QMutexLocker mutex( &mCurrentAvailablePrintersMutex );
mCurrentAvailablePrinters = newAvailablePrinters;
///
/// Asynchronous poll
///
void PrinterMonitor::asyncPoll()
{
auto newAvailablePrinters = QPrinterInfo::availablePrinterNames();
if ( newAvailablePrinters != mCurrentAvailablePrinters )
{
QMutexLocker mutex( &mCurrentAvailablePrintersMutex );
mCurrentAvailablePrinters = newAvailablePrinters;
emit availablePrintersChanged( mCurrentAvailablePrinters );
}
}
emit availablePrintersChanged( mCurrentAvailablePrinters );
}
}
} // namespace glabels
-99
View File
@@ -1,99 +0,0 @@
/* PrinterMonitor.h
*
* Copyright (C) 2025 Jaye 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 PrinterMonitor_h
#define PrinterMonitor_h
#include <QFuture>
#include <QMutex>
#include <QObject>
#include <QStringList>
#include <QTimer>
#include <memory>
namespace glabels
{
///
/// Printer Monitor
///
class PrinterMonitor : public QObject
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
PrinterMonitor();
public:
static PrinterMonitor* instance();
/////////////////////////////////
// Public methods
/////////////////////////////////
public:
QStringList availablePrinters();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onTimerTimeout();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void availablePrintersChanged( QStringList availablePrinters );
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void asyncPoll();
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
static std::unique_ptr<PrinterMonitor> mInstance;
std::unique_ptr<QTimer> mTimer;
QStringList mCurrentAvailablePrinters;
QMutex mCurrentAvailablePrintersMutex;
QFuture<void> mPollStatus;
};
}
#endif // PrinterMonitor_h
+99
View File
@@ -0,0 +1,99 @@
// PrinterMonitor.hpp
//
// Copyright (C) 2025 Jaye 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 PrinterMonitor_hpp
#define PrinterMonitor_hpp
#include <QFuture>
#include <QMutex>
#include <QObject>
#include <QStringList>
#include <QTimer>
#include <memory>
namespace glabels
{
///
/// Printer Monitor
///
class PrinterMonitor : public QObject
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
private:
PrinterMonitor();
public:
static PrinterMonitor* instance();
/////////////////////////////////
// Public methods
/////////////////////////////////
public:
QStringList availablePrinters();
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onTimerTimeout();
/////////////////////////////////
// Signals
/////////////////////////////////
signals:
void availablePrintersChanged( QStringList availablePrinters );
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void asyncPoll();
/////////////////////////////////
// Private Members
/////////////////////////////////
private:
static std::unique_ptr<PrinterMonitor> mInstance;
std::unique_ptr<QTimer> mTimer;
QStringList mCurrentAvailablePrinters;
QMutex mCurrentAvailablePrintersMutex;
QFuture<void> mPollStatus;
};
}
#endif // PrinterMonitor_hpp
+206 -206
View File
@@ -1,253 +1,253 @@
/* PropertiesView.cpp
*
* Copyright (C) 2016 Jaye 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/>.
*/
// PropertiesView.cpp
//
// Copyright (C) 2016 Jaye 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 "PropertiesView.h"
#include "PropertiesView.hpp"
#include "SelectProductDialog.h"
#include "UndoRedoModel.h"
#include "SelectProductDialog.hpp"
#include "UndoRedoModel.hpp"
#include "model/Db.h"
#include "model/FrameContinuous.h"
#include "model/Settings.h"
#include "model/Db.hpp"
#include "model/FrameContinuous.hpp"
#include "model/Settings.hpp"
#include <QDebug>
#include <QStyledItemDelegate>
#include <QtDebug>
namespace glabels
{
///
/// Constructor
///
PropertiesView::PropertiesView( QWidget *parent )
: QWidget(parent), mModel(nullptr), mUndoRedoModel(nullptr)
{
setupUi( this );
///
/// Constructor
///
PropertiesView::PropertiesView( QWidget *parent )
: QWidget(parent), mModel(nullptr), mUndoRedoModel(nullptr)
{
setupUi( this );
titleLabel->setText( QString( "<span style='font-size:18pt;'>%1</span>" ).arg( tr("Properties") ) );
titleLabel->setText( QString( "<span style='font-size:18pt;'>%1</span>" ).arg( tr("Properties") ) );
// Hack to get orientationCombo item height to follow icon size plus padding
auto* itemDelegate = new QStyledItemDelegate();
orientationCombo->setItemDelegate( itemDelegate );
orientationCombo->setStyleSheet( "* QAbstractItemView::item { padding: 8px; }" );
// Hack to get orientationCombo item height to follow icon size plus padding
auto* itemDelegate = new QStyledItemDelegate();
orientationCombo->setItemDelegate( itemDelegate );
orientationCombo->setStyleSheet( "* QAbstractItemView::item { padding: 8px; }" );
similarBrowser->setAttribute(Qt::WA_TranslucentBackground);
similarBrowser->viewport()->setAutoFillBackground(false);
similarBrowser->setAttribute(Qt::WA_TranslucentBackground);
similarBrowser->viewport()->setAutoFillBackground(false);
connect( model::Settings::instance(), SIGNAL(changed()),
this, SLOT(onSettingsChanged()) );
onSettingsChanged();
}
connect( model::Settings::instance(), SIGNAL(changed()),
this, SLOT(onSettingsChanged()) );
onSettingsChanged();
}
///
/// Set Model
///
void PropertiesView::setModel( model::Model* model, UndoRedoModel* undoRedoModel )
{
mModel = model;
mUndoRedoModel = undoRedoModel;
///
/// Set Model
///
void PropertiesView::setModel( model::Model* model, UndoRedoModel* undoRedoModel )
{
mModel = model;
mUndoRedoModel = undoRedoModel;
connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) );
connect( mModel, SIGNAL(sizeChanged()), this, SLOT(onLabelSizeChanged()) );
onLabelSizeChanged();
}
onLabelSizeChanged();
}
///
/// Settings changed handler
///
void PropertiesView::onSettingsChanged()
{
mUnits = model::Settings::units();
if (mModel)
{
onLabelSizeChanged();
}
}
///
/// Settings changed handler
///
void PropertiesView::onSettingsChanged()
{
mUnits = model::Settings::units();
if (mModel)
{
onLabelSizeChanged();
}
}
///
/// Label size changed handler
///
void PropertiesView::onLabelSizeChanged()
{
auto tmplate = mModel->tmplate();
auto frame = tmplate.frame();
bool isRotated = mModel->rotate();
///
/// Label size changed handler
///
void PropertiesView::onLabelSizeChanged()
{
auto tmplate = mModel->tmplate();
auto frame = tmplate.frame();
bool isRotated = mModel->rotate();
preview->setTemplate( tmplate );
preview->setShowArrow( true );
preview->setRotate( isRotated );
preview->setTemplate( tmplate );
preview->setShowArrow( true );
preview->setRotate( isRotated );
vendorLabel->setText( tmplate.brand() );
if ( model::Db::isVendorNameKnown( tmplate.brand() ) )
{
auto vendor = model::Db::lookupVendorFromName( tmplate.brand() );
if ( !vendor.url().isEmpty() )
{
QString markup = QString( "<a href='%1'>%2</a>" ).arg( vendor.url(), vendor.name() );
vendorLabel->setText( markup );
}
}
vendorLabel->setText( tmplate.brand() );
if ( model::Db::isVendorNameKnown( tmplate.brand() ) )
{
auto vendor = model::Db::lookupVendorFromName( tmplate.brand() );
if ( !vendor.url().isEmpty() )
{
QString markup = QString( "<a href='%1'>%2</a>" ).arg( vendor.url(), vendor.name() );
vendorLabel->setText( markup );
}
}
if ( !tmplate.productUrl().isEmpty() )
{
QString markup = QString( "<a href='%1'>%2</a>" ).arg( tmplate.productUrl(), tmplate.part() );
partLabel->setText( markup );
}
else
{
partLabel->setText( tmplate.part() );
}
if ( !tmplate.productUrl().isEmpty() )
{
QString markup = QString( "<a href='%1'>%2</a>" ).arg( tmplate.productUrl(), tmplate.part() );
partLabel->setText( markup );
}
else
{
partLabel->setText( tmplate.part() );
}
descriptionLabel->setText( tmplate.description() );
pageSizeLabel->setText( tmplate.paperDescription( mUnits ) );
labelSizeLabel->setText( frame->sizeDescription( mUnits ) );
layoutLabel->setText( frame->layoutDescription() );
descriptionLabel->setText( tmplate.description() );
pageSizeLabel->setText( tmplate.paperDescription( mUnits ) );
labelSizeLabel->setText( frame->sizeDescription( mUnits ) );
layoutLabel->setText( frame->layoutDescription() );
QStringList list = model::Db::getNameListOfSimilarTemplates( tmplate.name() );
if ( list.isEmpty() )
{
similarProductsGroupBox->hide();
similarProductsNullBox->show();
}
else
{
similarProductsGroupBox->show();
similarProductsNullBox->hide();
QStringList list = model::Db::getNameListOfSimilarTemplates( tmplate.name() );
if ( list.isEmpty() )
{
similarProductsGroupBox->hide();
similarProductsNullBox->show();
}
else
{
similarProductsGroupBox->show();
similarProductsNullBox->hide();
QString similarListString;
for ( QString name : list )
{
similarListString += name + "\n";
}
similarBrowser->setText( similarListString );
}
QString similarListString;
for ( QString name : list )
{
similarListString += name + "\n";
}
similarBrowser->setText( similarListString );
}
orientationCombo->setEnabled( frame->w() != frame->h() );
if ( frame->w() == frame->h() )
{
orientationCombo->setCurrentIndex(0);
}
else if ( frame->w() > frame->h() )
{
orientationCombo->setCurrentIndex( isRotated ? 1 : 0 );
}
else
{
orientationCombo->setCurrentIndex( isRotated ? 0 : 1 );
}
mOldOrientationIndex = orientationCombo->currentIndex();
orientationCombo->setEnabled( frame->w() != frame->h() );
if ( frame->w() == frame->h() )
{
orientationCombo->setCurrentIndex(0);
}
else if ( frame->w() > frame->h() )
{
orientationCombo->setCurrentIndex( isRotated ? 1 : 0 );
}
else
{
orientationCombo->setCurrentIndex( isRotated ? 0 : 1 );
}
mOldOrientationIndex = orientationCombo->currentIndex();
if ( auto* continuousFrame = dynamic_cast<const model::FrameContinuous*>( frame ) )
{
if (!mInLengthSpinChanged)
{
const QSignalBlocker blocker( lengthSpin );
if ( auto* continuousFrame = dynamic_cast<const model::FrameContinuous*>( frame ) )
{
if (!mInLengthSpinChanged)
{
const QSignalBlocker blocker( lengthSpin );
lengthSpin->setSuffix( " " + mUnits.toTrName() );
lengthSpin->setDecimals( mUnits.resolutionDigits() );
lengthSpin->setSingleStep( mUnits.resolution() );
lengthSpin->setMinimum( continuousFrame->hMin().inUnits( mUnits ) );
lengthSpin->setMaximum( continuousFrame->hMax().inUnits( mUnits ) );
lengthSpin->setValue( continuousFrame->h().inUnits( mUnits ) );
}
lengthSpin->setSuffix( " " + mUnits.toTrName() );
lengthSpin->setDecimals( mUnits.resolutionDigits() );
lengthSpin->setSingleStep( mUnits.resolution() );
lengthSpin->setMinimum( continuousFrame->hMin().inUnits( mUnits ) );
lengthSpin->setMaximum( continuousFrame->hMax().inUnits( mUnits ) );
lengthSpin->setValue( continuousFrame->h().inUnits( mUnits ) );
}
parametersGroupBox->setVisible( true );
}
else
{
parametersGroupBox->setVisible( false );
}
}
parametersGroupBox->setVisible( true );
}
else
{
parametersGroupBox->setVisible( false );
}
}
///
/// Length spin changed handler
///
void PropertiesView::onLengthSpinChanged()
{
mInLengthSpinChanged = true;
mModel->setH( model::Distance( lengthSpin->value(), mUnits ) );
mInLengthSpinChanged = false;
}
///
/// Length spin changed handler
///
void PropertiesView::onLengthSpinChanged()
{
mInLengthSpinChanged = true;
mModel->setH( model::Distance( lengthSpin->value(), mUnits ) );
mInLengthSpinChanged = false;
}
///
/// Orientation combo box changed handler
///
void PropertiesView::onOrientationActivated()
{
auto tmplate = mModel->tmplate();
auto frame = tmplate.frame();
///
/// Orientation combo box changed handler
///
void PropertiesView::onOrientationActivated()
{
auto tmplate = mModel->tmplate();
auto frame = tmplate.frame();
// Make sure index actually changed.
int index = orientationCombo->currentIndex();
if ( index != mOldOrientationIndex )
{
mOldOrientationIndex = index;
// Make sure index actually changed.
int index = orientationCombo->currentIndex();
if ( index != mOldOrientationIndex )
{
mOldOrientationIndex = index;
mUndoRedoModel->checkpoint( tr("Product Rotate") );
mUndoRedoModel->checkpoint( tr("Product Rotate") );
if ( frame->w() == frame->h() )
{
mModel->setRotate( false );
}
else if ( frame->w() > frame->h() )
{
mModel->setRotate( index == 1 );
}
else
{
mModel->setRotate( index == 0 );
}
}
}
if ( frame->w() == frame->h() )
{
mModel->setRotate( false );
}
else if ( frame->w() > frame->h() )
{
mModel->setRotate( index == 1 );
}
else
{
mModel->setRotate( index == 0 );
}
}
}
///
/// Change Product Button Clicked handler
///
void PropertiesView::onChangeProductButtonClicked()
{
SelectProductDialog selectProductDialog( this );
selectProductDialog.exec();
///
/// Change Product Button Clicked handler
///
void PropertiesView::onChangeProductButtonClicked()
{
SelectProductDialog selectProductDialog( this );
selectProductDialog.exec();
auto tmplate = selectProductDialog.tmplate();
if ( !tmplate.isNull() )
{
mUndoRedoModel->checkpoint( tr("Change Product") );
auto tmplate = selectProductDialog.tmplate();
if ( !tmplate.isNull() )
{
mUndoRedoModel->checkpoint( tr("Change Product") );
mModel->setTmplate( tmplate );
mModel->setTmplate( tmplate );
// Don't rotate circular or round labels
auto frame = tmplate.frame();
if ( frame->w() == frame->h() )
{
mModel->setRotate( false );
}
}
}
// Don't rotate circular or round labels
auto frame = tmplate.frame();
if ( frame->w() == frame->h() )
{
mModel->setRotate( false );
}
}
}
} // namespace glabels
-86
View File
@@ -1,86 +0,0 @@
/* PropertiesView.h
*
* Copyright (C) 2016 Jaye 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 PropertiesView_h
#define PropertiesView_h
#include "ui_PropertiesView.h"
#include "model/Model.h"
#include "model/Units.h"
namespace glabels
{
// Forward references
class UndoRedoModel;
///
/// Properties View Widget
///
class PropertiesView : public QWidget, public Ui_PropertiesView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
PropertiesView( QWidget *parent = nullptr );
virtual ~PropertiesView() = default;
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onSettingsChanged();
void onLabelSizeChanged();
void onLengthSpinChanged();
void onOrientationActivated();
void onChangeProductButtonClicked();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
bool mInLengthSpinChanged{ false };
model::Model* mModel;
UndoRedoModel* mUndoRedoModel;
model::Units mUnits;
int mOldOrientationIndex;
};
}
#endif // PropertiesView_h
+86
View File
@@ -0,0 +1,86 @@
// PropertiesView.hpp
//
// Copyright (C) 2016 Jaye 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 PropertiesView_hpp
#define PropertiesView_hpp
#include "ui_PropertiesView.h"
#include "model/Model.hpp"
#include "model/Units.hpp"
namespace glabels
{
// Forward references
class UndoRedoModel;
///
/// Properties View Widget
///
class PropertiesView : public QWidget, public Ui_PropertiesView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
PropertiesView( QWidget *parent = nullptr );
virtual ~PropertiesView() = default;
/////////////////////////////////
// Public methods
/////////////////////////////////
void setModel( model::Model* model, UndoRedoModel* undoRedoModel );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onSettingsChanged();
void onLabelSizeChanged();
void onLengthSpinChanged();
void onOrientationActivated();
void onChangeProductButtonClicked();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
bool mInLengthSpinChanged{ false };
model::Model* mModel;
UndoRedoModel* mUndoRedoModel;
model::Units mUnits;
int mOldOrientationIndex;
};
}
#endif // PropertiesView_hpp
+65 -64
View File
@@ -1,88 +1,89 @@
/* ReportBugDialog.cpp
*
* Copyright (C) 2019 Jaye 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/>.
*/
// ReportBugDialog.cpp
//
// Copyright (C) 2019 Jaye 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 "ReportBugDialog.h"
#include "model/Version.h"
#include "ReportBugDialog.hpp"
#include "model/Version.hpp"
#include <QDebug>
#include <QDesktopServices>
#include <QUrl>
#include <QtDebug>
namespace glabels
{
///
/// Constructor
///
ReportBugDialog::ReportBugDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
///
/// Constructor
///
ReportBugDialog::ReportBugDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
QString title = tr("How to Report a Bug");
titleLabel->setText( QString( "<span style='font-size:14pt;font-weight:bold;'>%1</span>" ).arg( title ) );
QString directionsP1 =
tr( "To submit a bug report, click on the button below. This will open a "
"web browser to the gLabels github issue tracking page." );
QString title = tr("How to Report a Bug");
titleLabel->setText( QString( "<span style='font-size:14pt;font-weight:bold;'>%1</span>" ).arg( title ) );
p1Label->setText( QString( "<p>%1</p>" ).arg( directionsP1 ) );
QString directionsP1 =
tr( "To submit a bug report, click on the button below. This will open a "
"web browser to the gLabels github issue tracking page." );
QString directionsP2 =
tr( "Before submitting a report, look through the existing issues for similar "
"or related bugs. If the issue has already been reported, please consider "
"contributing to its report instead. Otherwise, create a new issue report. "
"Please paste the following information into the issue description." );
p1Label->setText( QString( "<p>%1</p>" ).arg( directionsP1 ) );
p2Label->setText( QString( "<p>%1</p>" ).arg( directionsP2 ) );
QString directionsP2 =
tr( "Before submitting a report, look through the existing issues for similar "
"or related bugs. If the issue has already been reported, please consider "
"contributing to its report instead. Otherwise, create a new issue report. "
"Please paste the following information into the issue description." );
infoText->append( model::Version::details() );
p2Label->setText( QString( "<p>%1</p>" ).arg( directionsP2 ) );
QString directionsP3 =
tr( "Be sure to include a detailed description of the problem and how to "
"recreate it. Attach any screenshots and/or example glabels project "
"files that may illustrate the problem." );
infoText->append( model::Version::details() );
p3Label->setText( QString( "<p>%1</p>" ).arg( directionsP3 ) );
QString directionsP3 =
tr( "Be sure to include a detailed description of the problem and how to "
"recreate it. Attach any screenshots and/or example glabels project "
"files that may illustrate the problem." );
}
p3Label->setText( QString( "<p>%1</p>" ).arg( directionsP3 ) );
}
///
/// "Copy" Button Clicked Slot
///
void ReportBugDialog::onCopyButtonClicked()
{
infoText->selectAll();
infoText->copy();
}
///
/// "Copy" Button Clicked Slot
///
void ReportBugDialog::onCopyButtonClicked()
{
infoText->selectAll();
infoText->copy();
}
///
/// "Website" Button Clicked Slot
///
void ReportBugDialog::onWebsiteButtonClicked()
{
QDesktopServices::openUrl( QUrl(model::Version::BUG_WEBSITE) );
}
///
/// "Website" Button Clicked Slot
///
void ReportBugDialog::onWebsiteButtonClicked()
{
QDesktopServices::openUrl( QUrl(model::Version::BUG_WEBSITE) );
}
} // namespace glabels
-58
View File
@@ -1,58 +0,0 @@
/* ReportBugDialog.h
*
* Copyright (C) 2019 Jaye 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 ReportBugDialog_h
#define ReportBugDialog_h
#include "ui_ReportBugDialog.h"
namespace glabels
{
///
/// "Report Bug" Dialog Widget
///
class ReportBugDialog : public QDialog, public Ui_ReportBugDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ReportBugDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onCopyButtonClicked();
void onWebsiteButtonClicked();
};
}
#endif // ReportBugDialog_h
+58
View File
@@ -0,0 +1,58 @@
// ReportBugDialog.hpp
//
// Copyright (C) 2019 Jaye 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 ReportBugDialog_hpp
#define ReportBugDialog_hpp
#include "ui_ReportBugDialog.h"
namespace glabels
{
///
/// "Report Bug" Dialog Widget
///
class ReportBugDialog : public QDialog, public Ui_ReportBugDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
ReportBugDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onCopyButtonClicked();
void onWebsiteButtonClicked();
};
}
#endif // ReportBugDialog_hpp
+56 -55
View File
@@ -1,71 +1,72 @@
/* RollTemplatePath.cpp
*
* Copyright (C) 2014 Jaye 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/>.
*/
// RollTemplatePath.cpp
//
// Copyright (C) 2014 Jaye 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 "RollTemplatePath.h"
#include <QtDebug>
#include "RollTemplatePath.hpp"
#include <QDebug>
namespace glabels
{
///
/// Constructor
///
RollTemplatePath::RollTemplatePath( const model::Template& tmplate )
{
if ( !tmplate.isRoll() )
{
qWarning() << "Not a \"Roll\" template type.";
}
///
/// Constructor
///
RollTemplatePath::RollTemplatePath( const model::Template& tmplate )
{
if ( !tmplate.isRoll() )
{
qWarning() << "Not a \"Roll\" template type.";
}
model::Distance x0 = (tmplate.pageWidth() - tmplate.rollWidth()) / 2.0;
model::Distance w = tmplate.rollWidth();
model::Distance h = tmplate.pageHeight();
model::Distance c = 0.07*h;
model::Distance b = 0.03*h;
model::Distance x0 = (tmplate.pageWidth() - tmplate.rollWidth()) / 2.0;
model::Distance w = tmplate.rollWidth();
model::Distance h = tmplate.pageHeight();
model::Distance c = 0.07*h;
model::Distance b = 0.03*h;
const int nx = 18;
const int nx = 18;
// Upper break line
moveTo( x0.pt(), -c.pt() );
for ( int ix = 1; ix <= nx; ix++ )
{
model::Distance x = ix * (w/double(nx)) + x0;
double a = ix * (2*M_PI/double(nx));
// Upper break line
moveTo( x0.pt(), -c.pt() );
for ( int ix = 1; ix <= nx; ix++ )
{
model::Distance x = ix * (w/double(nx)) + x0;
double a = ix * (2*M_PI/double(nx));
lineTo( x.pt(), b.pt()*sin(a) - c.pt() );
}
lineTo( x.pt(), b.pt()*sin(a) - c.pt() );
}
// Lower break line
lineTo( (x0+w).pt(), (h+c).pt() );
for ( int ix = nx-1; ix >= 0; ix-- )
{
model::Distance x = ix * (w/double(nx)) + x0;
double a = ix * (2*M_PI/double(nx));
// Lower break line
lineTo( (x0+w).pt(), (h+c).pt() );
for ( int ix = nx-1; ix >= 0; ix-- )
{
model::Distance x = ix * (w/double(nx)) + x0;
double a = ix * (2*M_PI/double(nx));
lineTo( x.pt(), b.pt()*sin(a) + h.pt() + c.pt() );
}
lineTo( x.pt(), b.pt()*sin(a) + h.pt() + c.pt() );
}
// Close path
closeSubpath();
}
// Close path
closeSubpath();
}
} // namespace glabels
-49
View File
@@ -1,49 +0,0 @@
/* RollTemplatePath.h
*
* Copyright (C) 2018 Jaye 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 RollTemplatePath_h
#define RollTemplatePath_h
#include "model/Template.h"
#include <QPainterPath>
namespace glabels
{
///
/// Painter path for "Roll" templates
///
class RollTemplatePath : public QPainterPath
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
RollTemplatePath( const model::Template& tmplate );
};
}
#endif // RollTemplatePath_h
+49
View File
@@ -0,0 +1,49 @@
// RollTemplatePath.hpp
//
// Copyright (C) 2018 Jaye 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 RollTemplatePath_hpp
#define RollTemplatePath_hpp
#include "model/Template.hpp"
#include <QPainterPath>
namespace glabels
{
///
/// Painter path for "Roll" templates
///
class RollTemplatePath : public QPainterPath
{
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
RollTemplatePath( const model::Template& tmplate );
};
}
#endif // RollTemplatePath_hpp
+262 -262
View File
@@ -1,310 +1,310 @@
/* SelectProductDialog.cpp
*
* Copyright (C) 2013-2016 Jaye 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/>.
*/
// SelectProductDialog.cpp
//
// Copyright (C) 2013-2016 Jaye 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 "SelectProductDialog.h"
#include "SelectProductDialog.hpp"
#include "NotebookUtil.h"
#include "TemplatePickerItem.h"
#include "NotebookUtil.hpp"
#include "TemplatePickerItem.hpp"
#include "model/Db.h"
#include "model/Settings.h"
#include "model/Db.hpp"
#include "model/Settings.hpp"
#include <QtDebug>
#include <QDebug>
namespace glabels
{
///
/// Constructor
///
SelectProductDialog::SelectProductDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
productInfoWidget->setVisible( false );
pageSizeIsoCheck->setChecked( model::Settings::searchIsoPaperSizes() );
pageSizeUsCheck->setChecked( model::Settings::searchUsPaperSizes() );
pageSizeOtherCheck->setChecked( model::Settings::searchOtherPaperSizes() );
///
/// Constructor
///
SelectProductDialog::SelectProductDialog( QWidget *parent )
: QDialog(parent)
{
setupUi( this );
productInfoWidget->setVisible( false );
allCategoriesRadio->setChecked( model::Settings::searchAllCategories() );
selectedCategoriesRadio->setChecked( !model::Settings::searchAllCategories() );
pageSizeIsoCheck->setChecked( model::Settings::searchIsoPaperSizes() );
pageSizeUsCheck->setChecked( model::Settings::searchUsPaperSizes() );
pageSizeOtherCheck->setChecked( model::Settings::searchOtherPaperSizes() );
categoriesCheckContainer->setEnabled( !model::Settings::searchAllCategories() );
mCategoryIdList = model::Settings::searchCategoryList();
auto categories = model::Db::categories();
for ( auto& category : categories )
{
QCheckBox* check = new QCheckBox( category.name() );
check->setChecked( mCategoryIdList.contains( category.id() ) );
categoriesLayout->addWidget( check );
allCategoriesRadio->setChecked( model::Settings::searchAllCategories() );
selectedCategoriesRadio->setChecked( !model::Settings::searchAllCategories() );
mCheckList.append( check );
mCheckToCategoryMap[check] = category.id();
categoriesCheckContainer->setEnabled( !model::Settings::searchAllCategories() );
mCategoryIdList = model::Settings::searchCategoryList();
connect( check, SIGNAL(clicked()), this, SLOT(onCategoryCheckClicked()) );
}
auto categories = model::Db::categories();
for ( auto& category : categories )
{
QCheckBox* check = new QCheckBox( category.name() );
check->setChecked( mCategoryIdList.contains( category.id() ) );
categoriesLayout->addWidget( check );
NotebookUtil::establishSize( modeNotebook );
mCheckList.append( check );
mCheckToCategoryMap[check] = category.id();
if ( templatePicker->mode() == QListView::IconMode )
{
viewModeButton->setIcon( QIcon::fromTheme( "glabels-view-list" ) );
viewModeButton->setToolTip( tr( "List View" ) );
}
else
{
viewModeButton->setIcon( QIcon::fromTheme( "glabels-view-grid" ) );
viewModeButton->setToolTip( tr( "Grid View" ) );
}
auto tmplates = model::Db::templates();
templatePicker->setTemplates( tmplates );
connect( check, SIGNAL(clicked()), this, SLOT(onCategoryCheckClicked()) );
}
if ( model::Settings::recentTemplateList().count() > 0 )
{
modeNotebook->setCurrentIndex(1);
}
NotebookUtil::establishSize( modeNotebook );
onModeTabChanged();
}
if ( templatePicker->mode() == QListView::IconMode )
{
viewModeButton->setIcon( QIcon::fromTheme( "glabels-view-list" ) );
viewModeButton->setToolTip( tr( "List View" ) );
}
else
{
viewModeButton->setIcon( QIcon::fromTheme( "glabels-view-grid" ) );
viewModeButton->setToolTip( tr( "Grid View" ) );
}
///
/// Get selected template
///
model::Template SelectProductDialog::tmplate() const
{
if ( mHasSelection )
{
return templatePicker->selectedTemplate();
}
else
{
return model::Template();
}
}
auto tmplates = model::Db::templates();
templatePicker->setTemplates( tmplates );
if ( model::Settings::recentTemplateList().count() > 0 )
{
modeNotebook->setCurrentIndex(1);
}
onModeTabChanged();
}
///
/// Mode Notebook Tab Changed Slot
///
void SelectProductDialog::onModeTabChanged()
{
switch (modeNotebook->currentIndex())
{
case 0:
// Search Tab
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
break;
case 1:
// Recent Tab
templatePicker->applyFilter( model::Settings::recentTemplateList() );
break;
default:
qDebug() << "onModeTabChanged(): unknown tab!";
}
}
///
/// Get selected template
///
model::Template SelectProductDialog::tmplate() const
{
if ( mHasSelection )
{
return templatePicker->selectedTemplate();
}
else
{
return model::Template();
}
}
///
/// Search Entry Text Changed Slot
///
void SelectProductDialog::onSearchEntryTextChanged()
{
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
}
///
/// Mode Notebook Tab Changed Slot
///
void SelectProductDialog::onModeTabChanged()
{
switch (modeNotebook->currentIndex())
{
case 0:
// Search Tab
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
break;
case 1:
// Recent Tab
templatePicker->applyFilter( model::Settings::recentTemplateList() );
break;
default:
qDebug() << "onModeTabChanged(): unknown tab!";
}
}
///
/// Page Size Check Clicked Slot
///
void SelectProductDialog::onPageSizeCheckClicked()
{
model::Settings::setSearchIsoPaperSizes( pageSizeIsoCheck->isChecked() );
model::Settings::setSearchUsPaperSizes( pageSizeUsCheck->isChecked() );
model::Settings::setSearchOtherPaperSizes( pageSizeOtherCheck->isChecked() );
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
}
///
/// Search Entry Text Changed Slot
///
void SelectProductDialog::onSearchEntryTextChanged()
{
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
}
///
/// Category Radio Clicked Slot
///
void SelectProductDialog::onCategoryRadioClicked()
{
categoriesCheckContainer->setEnabled( selectedCategoriesRadio->isChecked() );
loadCategoryList();
///
/// Page Size Check Clicked Slot
///
void SelectProductDialog::onPageSizeCheckClicked()
{
model::Settings::setSearchIsoPaperSizes( pageSizeIsoCheck->isChecked() );
model::Settings::setSearchUsPaperSizes( pageSizeUsCheck->isChecked() );
model::Settings::setSearchOtherPaperSizes( pageSizeOtherCheck->isChecked() );
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
model::Settings::setSearchAllCategories( allCategoriesRadio->isChecked() );
}
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
}
///
/// Category Check Clicked Slot
///
void SelectProductDialog::onCategoryCheckClicked()
{
loadCategoryList();
///
/// Category Radio Clicked Slot
///
void SelectProductDialog::onCategoryRadioClicked()
{
categoriesCheckContainer->setEnabled( selectedCategoriesRadio->isChecked() );
loadCategoryList();
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
model::Settings::setSearchAllCategories( allCategoriesRadio->isChecked() );
}
model::Settings::setSearchCategoryList( mCategoryIdList );
}
///
/// Category Check Clicked Slot
///
void SelectProductDialog::onCategoryCheckClicked()
{
loadCategoryList();
templatePicker->applyFilter( searchEntry->text(),
pageSizeIsoCheck->isChecked(),
pageSizeUsCheck->isChecked(),
pageSizeOtherCheck->isChecked(),
allCategoriesRadio->isChecked(),
mCategoryIdList );
///
/// View Mode Button Clicked Slot
///
void SelectProductDialog::onViewModeButtonClicked()
{
if ( templatePicker->mode() == QListView::IconMode )
{
templatePicker->setMode( QListView::ListMode );
viewModeButton->setIcon( QIcon::fromTheme( "glabels-view-list" ) );
viewModeButton->setToolTip( tr( "List View" ) );
}
else
{
templatePicker->setMode( QListView::IconMode );
viewModeButton->setIcon( QIcon::fromTheme( "glabels-view-grid" ) );
viewModeButton->setToolTip( tr( "Grid View" ) );
}
}
model::Settings::setSearchCategoryList( mCategoryIdList );
}
///
/// Template Picker Selection Changed Slot
///
void SelectProductDialog::onTemplatePickerSelectionChanged()
{
auto tmplate = templatePicker->selectedTemplate();
if ( tmplate.isNull() )
{
productInfoWidget->setVisible( false );
selectButton->setEnabled( false );
return;
}
auto frame = tmplate.frame();
///
/// View Mode Button Clicked Slot
///
void SelectProductDialog::onViewModeButtonClicked()
{
if ( templatePicker->mode() == QListView::IconMode )
{
templatePicker->setMode( QListView::ListMode );
preview->setTemplate( tmplate );
viewModeButton->setIcon( QIcon::fromTheme( "glabels-view-list" ) );
viewModeButton->setToolTip( tr( "List View" ) );
}
else
{
templatePicker->setMode( QListView::IconMode );
vendorLabel->setText( tmplate.brand() );
if ( model::Db::isVendorNameKnown( tmplate.brand() ) )
{
auto vendor = model::Db::lookupVendorFromName( tmplate.brand() );
if ( !vendor.url().isEmpty() )
{
QString markup = QString( "<a href='%1'>%2</a>" ).arg( vendor.url(), vendor.name() );
vendorLabel->setText( markup );
}
}
if ( !tmplate.productUrl().isEmpty() )
{
QString markup = QString( "<a href='%1'>%2</a>" ).arg( tmplate.productUrl(), tmplate.part() );
partLabel->setText( markup );
}
else
{
partLabel->setText( tmplate.part() );
}
descriptionLabel->setText( tmplate.description() );
pageSizeLabel->setText( tmplate.paperDescription( model::Settings::units() ) );
labelSizeLabel->setText( frame->sizeDescription( model::Settings::units() ) );
layoutLabel->setText( frame->layoutDescription() );
productInfoWidget->setVisible( true );
selectButton->setEnabled( true );
}
viewModeButton->setIcon( QIcon::fromTheme( "glabels-view-grid" ) );
viewModeButton->setToolTip( tr( "Grid View" ) );
}
}
///
/// Select Button Clicked Slot
///
void SelectProductDialog::onSelectButtonClicked()
{
mHasSelection = true;
close();
}
///
/// Template Picker Selection Changed Slot
///
void SelectProductDialog::onTemplatePickerSelectionChanged()
{
auto tmplate = templatePicker->selectedTemplate();
if ( tmplate.isNull() )
{
productInfoWidget->setVisible( false );
selectButton->setEnabled( false );
return;
}
auto frame = tmplate.frame();
preview->setTemplate( tmplate );
vendorLabel->setText( tmplate.brand() );
if ( model::Db::isVendorNameKnown( tmplate.brand() ) )
{
auto vendor = model::Db::lookupVendorFromName( tmplate.brand() );
if ( !vendor.url().isEmpty() )
{
QString markup = QString( "<a href='%1'>%2</a>" ).arg( vendor.url(), vendor.name() );
vendorLabel->setText( markup );
}
}
if ( !tmplate.productUrl().isEmpty() )
{
QString markup = QString( "<a href='%1'>%2</a>" ).arg( tmplate.productUrl(), tmplate.part() );
partLabel->setText( markup );
}
else
{
partLabel->setText( tmplate.part() );
}
descriptionLabel->setText( tmplate.description() );
pageSizeLabel->setText( tmplate.paperDescription( model::Settings::units() ) );
labelSizeLabel->setText( frame->sizeDescription( model::Settings::units() ) );
layoutLabel->setText( frame->layoutDescription() );
productInfoWidget->setVisible( true );
selectButton->setEnabled( true );
}
///
/// Cancel Button Clicked Slot
///
void SelectProductDialog::onCancelButtonClicked()
{
close();
}
///
/// Select Button Clicked Slot
///
void SelectProductDialog::onSelectButtonClicked()
{
mHasSelection = true;
close();
}
///
/// Load category list
///
void SelectProductDialog::loadCategoryList()
{
mCategoryIdList.clear();
///
/// Cancel Button Clicked Slot
///
void SelectProductDialog::onCancelButtonClicked()
{
close();
}
for ( QCheckBox* check : mCheckList )
{
if ( check->isChecked() )
{
mCategoryIdList.append( mCheckToCategoryMap[check] );
}
}
}
///
/// Load category list
///
void SelectProductDialog::loadCategoryList()
{
mCategoryIdList.clear();
for ( QCheckBox* check : mCheckList )
{
if ( check->isChecked() )
{
mCategoryIdList.append( mCheckToCategoryMap[check] );
}
}
}
} // namespace glabels
-89
View File
@@ -1,89 +0,0 @@
/* SelectProductDialog.h
*
* Copyright (C) 2013-2016 Jaye 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 SelectProductDialog_h
#define SelectProductDialog_h
#include "ui_SelectProductDialog.h"
namespace glabels
{
///
/// New Label Dialog Widget
///
class SelectProductDialog : public QDialog, public Ui_SelectProductDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
SelectProductDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Accessors
/////////////////////////////////
model::Template tmplate() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onModeTabChanged();
void onSearchEntryTextChanged();
void onPageSizeCheckClicked();
void onCategoryRadioClicked();
void onCategoryCheckClicked();
void onViewModeButtonClicked();
void onTemplatePickerSelectionChanged();
void onSelectButtonClicked();
void onCancelButtonClicked();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadCategoryList();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
QMap<QCheckBox*,QString> mCheckToCategoryMap;
QList<QCheckBox*> mCheckList;
QStringList mCategoryIdList;
bool mHasSelection { false };
};
}
#endif // SelectProductDialog_h
+89
View File
@@ -0,0 +1,89 @@
// SelectProductDialog.hpp
//
// Copyright (C) 2013-2016 Jaye 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 SelectProductDialog_hpp
#define SelectProductDialog_hpp
#include "ui_SelectProductDialog.h"
namespace glabels
{
///
/// New Label Dialog Widget
///
class SelectProductDialog : public QDialog, public Ui_SelectProductDialog
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
SelectProductDialog( QWidget *parent = nullptr );
/////////////////////////////////
// Accessors
/////////////////////////////////
model::Template tmplate() const;
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onModeTabChanged();
void onSearchEntryTextChanged();
void onPageSizeCheckClicked();
void onCategoryRadioClicked();
void onCategoryCheckClicked();
void onViewModeButtonClicked();
void onTemplatePickerSelectionChanged();
void onSelectButtonClicked();
void onCancelButtonClicked();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadCategoryList();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
QMap<QCheckBox*,QString> mCheckToCategoryMap;
QList<QCheckBox*> mCheckList;
QStringList mCategoryIdList;
bool mHasSelection { false };
};
}
#endif // SelectProductDialog_hpp
+230 -230
View File
@@ -1,278 +1,278 @@
/* SimplePreview.cpp
*
* Copyright (C) 2013-2016 Jaye 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/>.
*/
// SimplePreview.cpp
//
// Copyright (C) 2013-2016 Jaye 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 "SimplePreview.hpp"
#include "RollTemplatePath.h"
#include "RollTemplatePath.hpp"
#include <QDebug>
#include <QGraphicsPathItem>
#include <QGraphicsRectItem>
#include <QGraphicsDropShadowEffect>
#include <QtDebug>
//
// Private
//
namespace
{
const QColor paperColor( 242, 242, 242 );
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
{
//
// Private
//
namespace
{
const QColor paperColor( 242, 242, 242 );
const QColor paperOutlineColor( 0, 0, 0 );
const double paperOutlineWidthPixels = 1;
///
/// Constructor
///
SimplePreview::SimplePreview( QWidget *parent )
: QGraphicsView(parent)
{
mScene = new QGraphicsScene();
setScene( mScene );
const QColor shadowColor( 64, 64, 64 );
const double shadowOffsetPixels = 3;
const double shadowRadiusPixels = 12;
setAttribute(Qt::WA_TranslucentBackground);
viewport()->setAutoFillBackground(false);
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" );
}
setFrameStyle( QFrame::NoFrame );
setRenderHints( QPainter::Antialiasing );
}
///
/// Constructor
///
SimplePreview::SimplePreview( QWidget *parent )
: 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 model::Template& tmplate )
{
mTmplate = tmplate;
update();
}
///
/// Template Property Setter
///
void SimplePreview::setTemplate( const model::Template& tmplate )
{
mTmplate = tmplate;
update();
}
///
/// Show Arrow Property Setter
///
void SimplePreview::setShowArrow( bool showArrow )
{
mShowArrow = showArrow;
update();
}
///
/// Show Arrow Property Setter
///
void SimplePreview::setShowArrow( bool showArrow )
{
mShowArrow = showArrow;
update();
}
///
/// Rotate Property Setter
///
void SimplePreview::setRotate( bool rotateFlag )
{
mRotateFlag = rotateFlag;
update();
}
///
/// Rotate Property Setter
///
void SimplePreview::setRotate( bool rotateFlag )
{
mRotateFlag = rotateFlag;
update();
}
///
/// Resize Event Handler
///
void SimplePreview::resizeEvent( QResizeEvent* event )
{
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
}
///
/// Resize Event Handler
///
void SimplePreview::resizeEvent( QResizeEvent* event )
{
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
}
///
/// Update View
///
void SimplePreview::update()
{
mScene->clear();
if ( !mTmplate.isNull() )
{
// For "Roll" templates, allow extra room to draw continuation break lines.
model::Distance drawHeight = mTmplate.pageHeight();
model::Distance drawOffset = 0;
if ( mTmplate.isRoll() )
{
drawHeight = 1.2 * mTmplate.pageHeight();
drawOffset = 0.1 * mTmplate.pageHeight();
}
// Set scene up with a 5% margin around paper
model::Distance x = -0.05 * mTmplate.pageWidth();
model::Distance y = -0.05 * drawHeight - drawOffset;
model::Distance w = 1.10 * mTmplate.pageWidth();
model::Distance h = 1.10 * drawHeight;
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
drawPaper();
drawLabels();
if ( mShowArrow )
{
drawArrow();
}
}
}
///
/// Update View
///
void SimplePreview::update()
{
mScene->clear();
///
/// Draw Paper
///
void SimplePreview::drawPaper()
{
auto *shadowEffect = new QGraphicsDropShadowEffect();
shadowEffect->setColor( shadowColor );
shadowEffect->setOffset( shadowOffsetPixels );
shadowEffect->setBlurRadius( shadowRadiusPixels );
if ( !mTmplate.isNull() )
{
// For "Roll" templates, allow extra room to draw continuation break lines.
model::Distance drawHeight = mTmplate.pageHeight();
model::Distance drawOffset = 0;
if ( mTmplate.isRoll() )
{
drawHeight = 1.2 * mTmplate.pageHeight();
drawOffset = 0.1 * mTmplate.pageHeight();
}
// Set scene up with a 5% margin around paper
model::Distance x = -0.05 * mTmplate.pageWidth();
model::Distance y = -0.05 * drawHeight - drawOffset;
model::Distance w = 1.10 * mTmplate.pageWidth();
model::Distance h = 1.10 * drawHeight;
QBrush brush( paperColor );
QPen pen( paperOutlineColor );
pen.setCosmetic( true );
pen.setWidthF( paperOutlineWidthPixels );
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
fitInView( mScene->sceneRect(), Qt::KeepAspectRatio );
QAbstractGraphicsShapeItem* pageItem;
if ( !mTmplate.isRoll() )
{
pageItem = new QGraphicsRectItem( 0, 0, mTmplate.pageWidth().pt(), mTmplate.pageHeight().pt() );
}
else
{
pageItem = new QGraphicsPathItem( RollTemplatePath( mTmplate ) );
}
pageItem->setBrush( brush );
pageItem->setPen( pen );
pageItem->setGraphicsEffect( shadowEffect );
drawPaper();
drawLabels();
if ( mShowArrow )
{
drawArrow();
}
}
}
mScene->addItem( pageItem );
}
///
/// Draw Paper
///
void SimplePreview::drawPaper()
{
auto *shadowEffect = new QGraphicsDropShadowEffect();
shadowEffect->setColor( shadowColor );
shadowEffect->setOffset( shadowOffsetPixels );
shadowEffect->setBlurRadius( shadowRadiusPixels );
///
/// Draw Labels on Paper
///
void SimplePreview::drawLabels()
{
auto frame = mTmplate.frame();
QBrush brush( paperColor );
QPen pen( paperOutlineColor );
pen.setCosmetic( true );
pen.setWidthF( paperOutlineWidthPixels );
QAbstractGraphicsShapeItem* pageItem;
if ( !mTmplate.isRoll() )
{
pageItem = new QGraphicsRectItem( 0, 0, mTmplate.pageWidth().pt(), mTmplate.pageHeight().pt() );
}
else
{
pageItem = new QGraphicsPathItem( RollTemplatePath( mTmplate ) );
}
pageItem->setBrush( brush );
pageItem->setPen( pen );
pageItem->setGraphicsEffect( shadowEffect );
mScene->addItem( pageItem );
}
for ( model::Point origin : frame->getOrigins() )
{
drawLabel( origin.x(), origin.y(), frame->path() );
}
}
///
/// Draw Labels on Paper
///
void SimplePreview::drawLabels()
{
auto frame = mTmplate.frame();
///
/// Draw a Single Label at x,y
///
void SimplePreview::drawLabel( model::Distance x,
model::Distance y,
const QPainterPath& path )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
pen.setCosmetic( true );
pen.setWidthF( labelOutlineWidthPixels );
for ( model::Point origin : frame->getOrigins() )
{
drawLabel( origin.x(), origin.y(), frame->path() );
}
}
auto *labelItem = new QGraphicsPathItem( path );
labelItem->setBrush( brush );
labelItem->setPen( pen );
labelItem->setPos( x.pt(), y.pt() );
mScene->addItem( labelItem );
}
///
/// Draw a Single Label at x,y
///
void SimplePreview::drawLabel( model::Distance x,
model::Distance y,
const QPainterPath& path )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
pen.setCosmetic( true );
pen.setWidthF( labelOutlineWidthPixels );
///
/// Draw Arrow Indicating Top of First Label
///
void SimplePreview::drawArrow()
{
auto frame = mTmplate.frame();
auto *labelItem = new QGraphicsPathItem( path );
labelItem->setBrush( brush );
labelItem->setPen( pen );
labelItem->setPos( x.pt(), y.pt() );
model::Distance w = frame->w();
model::Distance h = frame->h();
mScene->addItem( labelItem );
}
model::Distance minWH = min( w, h );
QPen pen( arrowColor );
pen.setWidthF( 0.25*minWH.pt()*arrowScale );
pen.setCapStyle( Qt::FlatCap );
pen.setJoinStyle( Qt::MiterJoin );
///
/// Draw Arrow Indicating Top of First Label
///
void SimplePreview::drawArrow()
{
auto frame = mTmplate.frame();
QBrush brush( upColor );
model::Distance w = frame->w();
model::Distance h = frame->h();
model::Point origin = frame->getOrigins().constFirst();
model::Distance x0 = origin.x();
model::Distance y0 = origin.y();
model::Distance minWH = min( w, h );
QPainterPath path;
path.moveTo( 0, minWH.pt()*arrowScale/3 );
path.lineTo( 0, -minWH.pt()*arrowScale );
path.moveTo( -minWH.pt()*arrowScale/2, -minWH.pt()*arrowScale/2 );
path.lineTo( 0, -minWH.pt()*arrowScale );
path.lineTo( minWH.pt()*arrowScale/2, -minWH.pt()*arrowScale/2 );
QPen pen( arrowColor );
pen.setWidthF( 0.25*minWH.pt()*arrowScale );
pen.setCapStyle( Qt::FlatCap );
pen.setJoinStyle( Qt::MiterJoin );
auto *arrowItem = new QGraphicsPathItem( path );
arrowItem->setPen( pen );
arrowItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() );
if ( mRotateFlag )
{
arrowItem->setRotation( -90 );
}
QBrush brush( upColor );
QGraphicsSimpleTextItem *upItem = new QGraphicsSimpleTextItem( tr("Up") );
upItem->setBrush( brush );
upItem->setFont( QFont( upFontFamily, minWH.pt()*upScale, QFont::Bold ) );
upItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() );
QRectF rect = upItem->boundingRect();
if ( mRotateFlag )
{
upItem->setPos( upItem->x()+minWH.pt()/8, upItem->y()+rect.width()/2 );
upItem->setRotation( -90 );
}
else
{
upItem->setPos( upItem->x()-rect.width()/2, upItem->y()+minWH.pt()/8 );
}
model::Point origin = frame->getOrigins().constFirst();
model::Distance x0 = origin.x();
model::Distance y0 = origin.y();
QPainterPath path;
path.moveTo( 0, minWH.pt()*arrowScale/3 );
path.lineTo( 0, -minWH.pt()*arrowScale );
path.moveTo( -minWH.pt()*arrowScale/2, -minWH.pt()*arrowScale/2 );
path.lineTo( 0, -minWH.pt()*arrowScale );
path.lineTo( minWH.pt()*arrowScale/2, -minWH.pt()*arrowScale/2 );
auto *arrowItem = new QGraphicsPathItem( path );
arrowItem->setPen( pen );
arrowItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() );
if ( mRotateFlag )
{
arrowItem->setRotation( -90 );
}
QGraphicsSimpleTextItem *upItem = new QGraphicsSimpleTextItem( tr("Up") );
upItem->setBrush( brush );
upItem->setFont( QFont( upFontFamily, minWH.pt()*upScale, QFont::Bold ) );
upItem->setPos( (x0+w/2).pt(), (y0+h/2).pt() );
QRectF rect = upItem->boundingRect();
if ( mRotateFlag )
{
upItem->setPos( upItem->x()+minWH.pt()/8, upItem->y()+rect.width()/2 );
upItem->setRotation( -90 );
}
else
{
upItem->setPos( upItem->x()-rect.width()/2, upItem->y()+minWH.pt()/8 );
}
mScene->addItem( arrowItem );
mScene->addItem( upItem );
}
mScene->addItem( arrowItem );
mScene->addItem( upItem );
}
} // namespace glabels
-94
View File
@@ -1,94 +0,0 @@
/* SimplePreview.h
*
* Copyright (C) 2013-2016 Jaye 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 SimplePreview_h
#define SimplePreview_h
#include "model/Template.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QList>
namespace glabels
{
///
/// Simple Preview Widget
///
class SimplePreview : public QGraphicsView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
SimplePreview( QWidget *parent = nullptr );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
void setTemplate( const model::Template& tmplate );
void setShowArrow( bool showArrow );
void setRotate( bool rotateFlag );
/////////////////////////////////////
// Event handlers
/////////////////////////////////////
protected:
void resizeEvent( QResizeEvent* event ) override;
/////////////////////////////////
// Internal Methods
/////////////////////////////////
private:
void update();
void drawPaper();
void drawLabels();
void drawLabel( model::Distance x,
model::Distance y,
const QPainterPath& path );
void drawArrow();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
model::Template mTmplate;
bool mShowArrow { false };
bool mRotateFlag { false };
QGraphicsScene* mScene { nullptr };
};
}
#endif // SimplePreview_h
+94
View File
@@ -0,0 +1,94 @@
// SimplePreview.hpp
//
// Copyright (C) 2013-2016 Jaye 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 SimplePreview_hpp
#define SimplePreview_hpp
#include "model/Template.hpp"
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QList>
namespace glabels
{
///
/// Simple Preview Widget
///
class SimplePreview : public QGraphicsView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
SimplePreview( QWidget *parent = nullptr );
/////////////////////////////////
// Properties
/////////////////////////////////
public:
void setTemplate( const model::Template& tmplate );
void setShowArrow( bool showArrow );
void setRotate( bool rotateFlag );
/////////////////////////////////////
// Event handlers
/////////////////////////////////////
protected:
void resizeEvent( QResizeEvent* event ) override;
/////////////////////////////////
// Internal Methods
/////////////////////////////////
private:
void update();
void drawPaper();
void drawLabels();
void drawLabel( model::Distance x,
model::Distance y,
const QPainterPath& path );
void drawArrow();
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
model::Template mTmplate;
bool mShowArrow { false };
bool mRotateFlag { false };
QGraphicsScene* mScene { nullptr };
};
}
#endif // SimplePreview_hpp
+92 -91
View File
@@ -1,122 +1,123 @@
/* StartupView.cpp
*
* Copyright (C) 2016 Jaye 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/>.
*/
// StartupView.cpp
//
// Copyright (C) 2016 Jaye 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 "StartupView.h"
#include "File.h"
#include "MainWindow.h"
#include "StartupView.hpp"
#include "model/Settings.h"
#include "File.hpp"
#include "MainWindow.hpp"
#include "model/Settings.hpp"
#include <QAction>
#include <QDebug>
#include <QFileInfo>
#include <QMenu>
#include <QtDebug>
namespace glabels
{
///
/// Constructor
///
StartupView::StartupView( MainWindow* window )
: QWidget(window), mWindow(window)
{
setupUi( this );
///
/// Constructor
///
StartupView::StartupView( MainWindow* window )
: QWidget(window), mWindow(window)
{
setupUi( this );
QString titleImage = ":images/glabels-label-designer.png";
titleLabel->setPixmap( QPixmap( titleImage ) );
QString titleImage = ":images/glabels-label-designer.png";
titleLabel->setPixmap( QPixmap( titleImage ) );
recentProjectButton->setEnabled( model::Settings::recentFileList().size() > 0 );
recentProjectButton->setEnabled( model::Settings::recentFileList().size() > 0 );
loadRecentsMenu();
loadRecentsMenu();
connect( model::Settings::instance(), SIGNAL(changed()), this, SLOT(onSettingsChanged()) );
}
connect( model::Settings::instance(), SIGNAL(changed()), this, SLOT(onSettingsChanged()) );
}
///
/// "New Project" Button Clicked Slot
///
void StartupView::onNewProjectButtonClicked()
{
File::newLabel( mWindow );
}
///
/// "New Project" Button Clicked Slot
///
void StartupView::onNewProjectButtonClicked()
{
File::newLabel( mWindow );
}
///
/// "Open Project" Button Clicked Slot
///
void StartupView::onOpenProjectButtonClicked()
{
File::open( mWindow );
}
///
/// "Open Project" Button Clicked Slot
///
void StartupView::onOpenProjectButtonClicked()
{
File::open( mWindow );
}
///
/// "Open Recent" Action Activated Slot
///
void StartupView::onOpenRecentAction()
{
QAction* action = qobject_cast<QAction*>( sender() );
if ( action )
{
File::open( action->data().toString(), mWindow );
}
}
///
/// "Open Recent" Action Activated Slot
///
void StartupView::onOpenRecentAction()
{
QAction* action = qobject_cast<QAction*>( sender() );
if ( action )
{
File::open( action->data().toString(), mWindow );
}
}
///
/// Settings changed Slot
///
void StartupView::onSettingsChanged()
{
// reload recents menu
loadRecentsMenu();
}
///
/// Settings changed Slot
///
void StartupView::onSettingsChanged()
{
// reload recents menu
loadRecentsMenu();
}
///
/// Create recents menu
///
void StartupView::loadRecentsMenu()
{
auto fileList = model::Settings::recentFileList();
auto* recentMenu = new QMenu();
///
/// Create recents menu
///
void StartupView::loadRecentsMenu()
{
auto fileList = model::Settings::recentFileList();
for ( auto& filename : fileList )
{
QString basename = QFileInfo( filename ).completeBaseName();
auto* action = new QAction( basename, this );
action->setIcon( QIcon::fromTheme( "glabels" ) );
action->setData( filename );
connect( action, SIGNAL(triggered()), this, SLOT(onOpenRecentAction()) );
recentMenu->addAction( action );
}
recentMenu->setMinimumWidth( recentProjectButton->minimumWidth() );
auto* recentMenu = new QMenu();
recentProjectButton->setMenu( recentMenu );
recentProjectButton->setEnabled( fileList.size() != 0 );
}
for ( auto& filename : fileList )
{
QString basename = QFileInfo( filename ).completeBaseName();
auto* action = new QAction( basename, this );
action->setIcon( QIcon::fromTheme( "glabels" ) );
action->setData( filename );
connect( action, SIGNAL(triggered()), this, SLOT(onOpenRecentAction()) );
recentMenu->addAction( action );
}
recentMenu->setMinimumWidth( recentProjectButton->minimumWidth() );
recentProjectButton->setMenu( recentMenu );
recentProjectButton->setEnabled( fileList.size() != 0 );
}
} // namespace glabels
-78
View File
@@ -1,78 +0,0 @@
/* StartupView.h
*
* Copyright (C) 2016 Jaye 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 StartupView_h
#define StartupView_h
#include "ui_StartupView.h"
namespace glabels
{
// Forward references
class MainWindow;
///
/// Startup View Widget
///
class StartupView : public QWidget, public Ui_StartupView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
StartupView( MainWindow* window );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onNewProjectButtonClicked();
void onOpenProjectButtonClicked();
void onOpenRecentAction();
void onSettingsChanged();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadRecentsMenu();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
MainWindow* mWindow;
};
}
#endif // StartupView_h
+78
View File
@@ -0,0 +1,78 @@
// StartupView.hpp
//
// Copyright (C) 2016 Jaye 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 StartupView_hpp
#define StartupView_hpp
#include "ui_StartupView.h"
namespace glabels
{
// Forward references
class MainWindow;
///
/// Startup View Widget
///
class StartupView : public QWidget, public Ui_StartupView
{
Q_OBJECT
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
StartupView( MainWindow* window );
/////////////////////////////////
// Slots
/////////////////////////////////
private slots:
void onNewProjectButtonClicked();
void onOpenProjectButtonClicked();
void onOpenRecentAction();
void onSettingsChanged();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
void loadRecentsMenu();
/////////////////////////////////
// Private data
/////////////////////////////////
private:
MainWindow* mWindow;
};
}
#endif // StartupView_hpp
+1548 -1547
View File
File diff suppressed because it is too large Load Diff
-322
View File
@@ -1,322 +0,0 @@
/* TemplateDesigner.h
*
* Copyright (C) 2018 Jaye 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 TemplateDesigner_h
#define TemplateDesigner_h
#include "ui_TemplateDesignerIntroPage.h"
#include "ui_TemplateDesignerNamePage.h"
#include "ui_TemplateDesignerPageSizePage.h"
#include "ui_TemplateDesignerShapePage.h"
#include "ui_TemplateDesignerRectPage.h"
#include "ui_TemplateDesignerRoundPage.h"
#include "ui_TemplateDesignerEllipsePage.h"
#include "ui_TemplateDesignerCdPage.h"
#include "ui_TemplateDesignerPathPage.h"
#include "ui_TemplateDesignerContinuousPage.h"
#include "ui_TemplateDesignerNLayoutsPage.h"
#include "ui_TemplateDesignerOneLayoutPage.h"
#include "ui_TemplateDesignerTwoLayoutPage.h"
#include "ui_TemplateDesignerApplyPage.h"
#include "model/Template.h"
#include <QWizard>
#include <QWizardPage>
namespace glabels
{
///
/// About Dialog Widget
///
class TemplateDesigner : public QWizard
{
Q_OBJECT
// My subpages are my friends :-)
friend class TemplateDesignerIntroPage;
friend class TemplateDesignerNamePage;
friend class TemplateDesignerPageSizePage;
friend class TemplateDesignerShapePage;
friend class TemplateDesignerRectPage;
friend class TemplateDesignerRoundPage;
friend class TemplateDesignerEllipsePage;
friend class TemplateDesignerCdPage;
friend class TemplateDesignerPathPage;
friend class TemplateDesignerContinuousPage;
friend class TemplateDesignerNLayoutsPage;
friend class TemplateDesignerOneLayoutPage;
friend class TemplateDesignerTwoLayoutPage;
friend class TemplateDesignerApplyPage;
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
TemplateDesigner( QWidget *parent = nullptr );
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
int nextId() const override;
double itemWidth();
double itemHeight();
double itemXWaste();
double itemYWaste();
model::Template buildTemplate();
void addLayouts( model::Frame& frame );
void printTestSheet();
void loadFromTemplate( const model::Template& tmplate );
bool isBasedOnCopy();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
bool mIsBasedOnCopy{false};
bool mIsTemplatePathBased{false};
bool mIsTemplateContinuousBased{false};
};
//
// Intro Page
//
class TemplateDesignerIntroPage : public QWizardPage, public Ui::TemplateDesignerIntroPage
{
Q_OBJECT
public:
TemplateDesignerIntroPage( QWidget* parent = nullptr );
bool isComplete() const override;
private slots:
void onCopyButtonClicked();
void onNewButtonClicked();
};
//
// Name Page
//
class TemplateDesignerNamePage : public QWizardPage, public Ui::TemplateDesignerNamePage
{
Q_OBJECT
public:
TemplateDesignerNamePage( QWidget* parent = nullptr );
bool isComplete() const override;
private slots:
void onChanged();
private:
bool mCanContinue = false;
};
//
// Page Size Page
//
class TemplateDesignerPageSizePage : public QWizardPage, public Ui::TemplateDesignerPageSizePage
{
Q_OBJECT
public:
TemplateDesignerPageSizePage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
private slots:
void onComboChanged();
};
//
// Shape Page
//
class TemplateDesignerShapePage : public QWizardPage, public Ui::TemplateDesignerShapePage
{
Q_OBJECT
public:
TemplateDesignerShapePage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Rect Page
//
class TemplateDesignerRectPage : public QWizardPage, public Ui::TemplateDesignerRectPage
{
Q_OBJECT
public:
TemplateDesignerRectPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Round Page
//
class TemplateDesignerRoundPage : public QWizardPage, public Ui::TemplateDesignerRoundPage
{
Q_OBJECT
public:
TemplateDesignerRoundPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Ellipse Page
//
class TemplateDesignerEllipsePage : public QWizardPage, public Ui::TemplateDesignerEllipsePage
{
Q_OBJECT
public:
TemplateDesignerEllipsePage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Cd Page
//
class TemplateDesignerCdPage : public QWizardPage, public Ui::TemplateDesignerCdPage
{
Q_OBJECT
public:
TemplateDesignerCdPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Path Page
//
class TemplateDesignerPathPage : public QWizardPage, public Ui::TemplateDesignerPathPage
{
Q_OBJECT
public:
TemplateDesignerPathPage( QWidget* parent = nullptr );
bool isComplete() const override;
};
//
// Continuous Page
//
class TemplateDesignerContinuousPage : public QWizardPage, public Ui::TemplateDesignerContinuousPage
{
Q_OBJECT
public:
TemplateDesignerContinuousPage( QWidget* parent = nullptr );
bool isComplete() const override;
};
//
// NLayouts Page
//
class TemplateDesignerNLayoutsPage : public QWizardPage, public Ui::TemplateDesignerNLayoutsPage
{
Q_OBJECT
public:
TemplateDesignerNLayoutsPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// OneLayout Page
//
class TemplateDesignerOneLayoutPage : public QWizardPage, public Ui::TemplateDesignerOneLayoutPage
{
Q_OBJECT
public:
TemplateDesignerOneLayoutPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
private slots:
void onChanged();
void onPrintButtonClicked();
};
//
// TwoLayout Page
//
class TemplateDesignerTwoLayoutPage : public QWizardPage, public Ui::TemplateDesignerTwoLayoutPage
{
Q_OBJECT
public:
TemplateDesignerTwoLayoutPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
private slots:
void onChanged();
void onPrintButtonClicked();
};
//
// Apply Page
//
class TemplateDesignerApplyPage : public QWizardPage, public Ui::TemplateDesignerApplyPage
{
Q_OBJECT
public:
TemplateDesignerApplyPage( QWidget* parent = nullptr );
bool validatePage();
};
}
#endif // TemplateDesigner_h
+322
View File
@@ -0,0 +1,322 @@
// TemplateDesigner.hpp
//
// Copyright (C) 2018 Jaye 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 TemplateDesigner_hpp
#define TemplateDesigner_hpp
#include "ui_TemplateDesignerIntroPage.h"
#include "ui_TemplateDesignerNamePage.h"
#include "ui_TemplateDesignerPageSizePage.h"
#include "ui_TemplateDesignerShapePage.h"
#include "ui_TemplateDesignerRectPage.h"
#include "ui_TemplateDesignerRoundPage.h"
#include "ui_TemplateDesignerEllipsePage.h"
#include "ui_TemplateDesignerCdPage.h"
#include "ui_TemplateDesignerPathPage.h"
#include "ui_TemplateDesignerContinuousPage.h"
#include "ui_TemplateDesignerNLayoutsPage.h"
#include "ui_TemplateDesignerOneLayoutPage.h"
#include "ui_TemplateDesignerTwoLayoutPage.h"
#include "ui_TemplateDesignerApplyPage.h"
#include "model/Template.hpp"
#include <QWizard>
#include <QWizardPage>
namespace glabels
{
///
/// About Dialog Widget
///
class TemplateDesigner : public QWizard
{
Q_OBJECT
// My subpages are my friends :-)
friend class TemplateDesignerIntroPage;
friend class TemplateDesignerNamePage;
friend class TemplateDesignerPageSizePage;
friend class TemplateDesignerShapePage;
friend class TemplateDesignerRectPage;
friend class TemplateDesignerRoundPage;
friend class TemplateDesignerEllipsePage;
friend class TemplateDesignerCdPage;
friend class TemplateDesignerPathPage;
friend class TemplateDesignerContinuousPage;
friend class TemplateDesignerNLayoutsPage;
friend class TemplateDesignerOneLayoutPage;
friend class TemplateDesignerTwoLayoutPage;
friend class TemplateDesignerApplyPage;
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
TemplateDesigner( QWidget *parent = nullptr );
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
int nextId() const override;
double itemWidth();
double itemHeight();
double itemXWaste();
double itemYWaste();
model::Template buildTemplate();
void addLayouts( model::Frame& frame );
void printTestSheet();
void loadFromTemplate( const model::Template& tmplate );
bool isBasedOnCopy();
/////////////////////////////////
// Private methods
/////////////////////////////////
private:
bool mIsBasedOnCopy{false};
bool mIsTemplatePathBased{false};
bool mIsTemplateContinuousBased{false};
};
//
// Intro Page
//
class TemplateDesignerIntroPage : public QWizardPage, public Ui::TemplateDesignerIntroPage
{
Q_OBJECT
public:
TemplateDesignerIntroPage( QWidget* parent = nullptr );
bool isComplete() const override;
private slots:
void onCopyButtonClicked();
void onNewButtonClicked();
};
//
// Name Page
//
class TemplateDesignerNamePage : public QWizardPage, public Ui::TemplateDesignerNamePage
{
Q_OBJECT
public:
TemplateDesignerNamePage( QWidget* parent = nullptr );
bool isComplete() const override;
private slots:
void onChanged();
private:
bool mCanContinue = false;
};
//
// Page Size Page
//
class TemplateDesignerPageSizePage : public QWizardPage, public Ui::TemplateDesignerPageSizePage
{
Q_OBJECT
public:
TemplateDesignerPageSizePage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
private slots:
void onComboChanged();
};
//
// Shape Page
//
class TemplateDesignerShapePage : public QWizardPage, public Ui::TemplateDesignerShapePage
{
Q_OBJECT
public:
TemplateDesignerShapePage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Rect Page
//
class TemplateDesignerRectPage : public QWizardPage, public Ui::TemplateDesignerRectPage
{
Q_OBJECT
public:
TemplateDesignerRectPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Round Page
//
class TemplateDesignerRoundPage : public QWizardPage, public Ui::TemplateDesignerRoundPage
{
Q_OBJECT
public:
TemplateDesignerRoundPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Ellipse Page
//
class TemplateDesignerEllipsePage : public QWizardPage, public Ui::TemplateDesignerEllipsePage
{
Q_OBJECT
public:
TemplateDesignerEllipsePage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Cd Page
//
class TemplateDesignerCdPage : public QWizardPage, public Ui::TemplateDesignerCdPage
{
Q_OBJECT
public:
TemplateDesignerCdPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// Path Page
//
class TemplateDesignerPathPage : public QWizardPage, public Ui::TemplateDesignerPathPage
{
Q_OBJECT
public:
TemplateDesignerPathPage( QWidget* parent = nullptr );
bool isComplete() const override;
};
//
// Continuous Page
//
class TemplateDesignerContinuousPage : public QWizardPage, public Ui::TemplateDesignerContinuousPage
{
Q_OBJECT
public:
TemplateDesignerContinuousPage( QWidget* parent = nullptr );
bool isComplete() const override;
};
//
// NLayouts Page
//
class TemplateDesignerNLayoutsPage : public QWizardPage, public Ui::TemplateDesignerNLayoutsPage
{
Q_OBJECT
public:
TemplateDesignerNLayoutsPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
};
//
// OneLayout Page
//
class TemplateDesignerOneLayoutPage : public QWizardPage, public Ui::TemplateDesignerOneLayoutPage
{
Q_OBJECT
public:
TemplateDesignerOneLayoutPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
private slots:
void onChanged();
void onPrintButtonClicked();
};
//
// TwoLayout Page
//
class TemplateDesignerTwoLayoutPage : public QWizardPage, public Ui::TemplateDesignerTwoLayoutPage
{
Q_OBJECT
public:
TemplateDesignerTwoLayoutPage( QWidget* parent = nullptr );
void initializePage() override;
void cleanupPage() override;
private slots:
void onChanged();
void onPrintButtonClicked();
};
//
// Apply Page
//
class TemplateDesignerApplyPage : public QWizardPage, public Ui::TemplateDesignerApplyPage
{
Q_OBJECT
public:
TemplateDesignerApplyPage( QWidget* parent = nullptr );
bool validatePage();
};
}
#endif // TemplateDesigner_hpp

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