From ba832044456305cc551d1ae781905ca1a69a69ea Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Tue, 5 Nov 2013 23:51:48 -0500 Subject: [PATCH] Initial implementation of TemplatePicker. Debugged mini previews. --- app/CMakeLists.txt | 2 ++ app/MainWindow.cpp | 13 +++++++- app/TemplatePicker.cpp | 50 +++++++++++++++++++++++++++++++ app/TemplatePicker.h | 51 ++++++++++++++++++++++++++++++++ libglabels/Db.h | 16 +++++++++- libglabels/Frame.cpp | 3 +- libglabels/FrameCd.cpp | 17 ++++++----- libglabels/MiniPreviewPixmap.cpp | 4 ++- libglabels/Template.cpp | 5 +--- libglabels/Template.h | 4 +++ libglabels/privateConstants.h | 2 -- 11 files changed, 149 insertions(+), 18 deletions(-) create mode 100644 app/TemplatePicker.cpp create mode 100644 app/TemplatePicker.h diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index f5bc55f..a8464c3 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -13,6 +13,7 @@ set (glabels_sources MainWindow.cpp MergeField.cpp MergeRecord.cpp + TemplatePicker.cpp TextNode.cpp ) @@ -20,6 +21,7 @@ set (glabels_qobject_headers LabelModel.h LabelModelItem.h MainWindow.h + TemplatePicker.h ) set (glabels_resource_files diff --git a/app/MainWindow.cpp b/app/MainWindow.cpp index 99930eb..640c9dd 100644 --- a/app/MainWindow.cpp +++ b/app/MainWindow.cpp @@ -28,15 +28,26 @@ #include "Icons.h" #include "Help.h" - +///// TEMPORARY TESTING ///// +#include "TemplatePicker.h" +#include "libglabels/Db.h" +///////////////////////////// namespace gLabels { MainWindow::MainWindow() { +/////////////// TEMPORARY TESTING /////////////// +#if 0 QLabel *tmp = new QLabel( "Coming Soon..." ); +#else + TemplatePicker *tmp = new TemplatePicker(); + QList tmplates = libglabels::Db::templates(); + tmp->setTemplates( tmplates ); +#endif setCentralWidget( tmp ); +///////////////////////////////////////////////// createActions(); createMenus(); diff --git a/app/TemplatePicker.cpp b/app/TemplatePicker.cpp new file mode 100644 index 0000000..ef2ac86 --- /dev/null +++ b/app/TemplatePicker.cpp @@ -0,0 +1,50 @@ +/* TemplatePicker.cpp + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#include "TemplatePicker.h" + +#include +#include + + +namespace gLabels +{ + + TemplatePicker::TemplatePicker( QWidget *parent ) : QListWidget(parent) + { + setViewMode( QListView::IconMode ); + setResizeMode( QListView::Adjust ); + setSpacing( 24 ); + setWordWrap( true ); + setUniformItemSizes( true ); + setIconSize( QSize(libglabels::TEMPLATE_PREVIEW_SIZE, libglabels::TEMPLATE_PREVIEW_SIZE) ); + } + + + void TemplatePicker::setTemplates( const QList &tmplates ) + { + foreach (libglabels::Template *tmplate, tmplates) + { + QListWidgetItem *item = new QListWidgetItem( tmplate->name(), this ); + item->setIcon( QIcon(tmplate->preview()) ); + } + } +} + diff --git a/app/TemplatePicker.h b/app/TemplatePicker.h new file mode 100644 index 0000000..75762f7 --- /dev/null +++ b/app/TemplatePicker.h @@ -0,0 +1,51 @@ +/* TemplatePicker.h + * + * Copyright (C) 2013 Jim Evins + * + * 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 . + */ + +#ifndef glabels_TemplatePicker_h +#define glabels_TemplatePicker_h + +#include + +#include + +#include "libglabels/Template.h" + + +namespace gLabels +{ + + class TemplatePicker : public QListWidget + { + Q_OBJECT + + public: + TemplatePicker( QWidget *parent = 0 ); + + void setTemplates( const QList &tmplates ); + + + private: + + + }; + +} + +#endif // glabels_TemplatePicker_h diff --git a/libglabels/Db.h b/libglabels/Db.h index 7af28d0..11d1f6b 100644 --- a/libglabels/Db.h +++ b/libglabels/Db.h @@ -43,11 +43,25 @@ namespace libglabels private: Db(); - public: static void init() { instance(); } static Db *instance() { static Db *db = new Db(); return db; } + + static const QList &papers() { return mPapers; } + static const QStringList &paperIds() { return mPaperIds; } + static const QStringList &paperNames() { return mPaperNames; } + + static const QList &categories() { return mCategories; } + static const QStringList &categoryIds() { return mCategoryIds; } + static const QStringList &categoryNames() { return mCategoryNames; } + + static const QList &vendors() { return mVendors; } + static const QStringList &vendorNames() { return mVendorNames; } + + static const QList &templates() { return mTemplates; } + + static void registerPaper( Paper *paper ); static const Paper *lookupPaperFromName( const QString &name ); static const Paper *lookupPaperFromId( const QString &id ); diff --git a/libglabels/Frame.cpp b/libglabels/Frame.cpp index dd16f0f..2cfaa4d 100644 --- a/libglabels/Frame.cpp +++ b/libglabels/Frame.cpp @@ -45,13 +45,14 @@ namespace libglabels { QVector origins( nLabels() ); + int i = 0; foreach ( Layout *layout, mLayouts ) { for ( int iy = 0; iy < layout->ny(); iy++ ) { for ( int ix = 0; ix < layout->nx(); ix++ ) { - origins << Point( ix*layout->dx() + layout->x0(), iy*layout->dy() + layout->y0() ); + origins[i++] = Point( ix*layout->dx() + layout->x0(), iy*layout->dy() + layout->y0() ); } } } diff --git a/libglabels/FrameCd.cpp b/libglabels/FrameCd.cpp index 2760207..7108964 100644 --- a/libglabels/FrameCd.cpp +++ b/libglabels/FrameCd.cpp @@ -70,21 +70,22 @@ namespace libglabels void FrameCd::initPath() { - double xc = w()/2; - double yc = h()/2; - // Outer path (may be clipped in the case business card type CD) double theta1 = acos( w() / (2*mR1) ) * 180/M_PI; double theta2 = asin( h() / (2*mR1) ) * 180/M_PI; - mPath.arcTo( 0, 0, 2*mR1, 2*mR1, theta1, theta2 ); - mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180-theta2, 180-theta1 ); - mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180+theta1, 180+theta2 ); - mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, 360-theta1 ); + mPath.arcMoveTo( 0, 0, 2*mR1, 2*mR1, theta1 ); + mPath.arcTo( 0, 0, 2*mR1, 2*mR1, theta1, theta2-theta1 ); + mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180-theta2, theta2-theta1 ); + mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 180+theta1, theta2-theta1 ); + mPath.arcTo( 0, 0, 2*mR1, 2*mR1, 360-theta2, theta2-theta1 ); mPath.closeSubpath(); // Inner path (hole) - mPath.addEllipse( xc-mR2, yc-mR2, 2*mR2, 2*mR2 ); + mPath.addEllipse( mR1-mR2, mR1-mR2, 2*mR2, 2*mR2 ); + + // Translate to account for offset with clipped business card CDs (applies to element already drawn) + mPath.translate( w()/2 - mR1, h()/2 - mR1 ); } } diff --git a/libglabels/MiniPreviewPixmap.cpp b/libglabels/MiniPreviewPixmap.cpp index fe0f5d3..5dcea5b 100644 --- a/libglabels/MiniPreviewPixmap.cpp +++ b/libglabels/MiniPreviewPixmap.cpp @@ -40,10 +40,12 @@ namespace libglabels void MiniPreviewPixmap::draw( const Template *tmplate, int width, int height ) { + fill( Qt::transparent ); + QPainter painter( this ); painter.setBackgroundMode( Qt::TransparentMode ); - painter.setRenderHint( QPainter::Antialiasing ); + painter.setRenderHint( QPainter::Antialiasing, true ); double w = width - 1; double h = height - 1; diff --git a/libglabels/Template.cpp b/libglabels/Template.cpp index bfcbcb2..3562efa 100644 --- a/libglabels/Template.cpp +++ b/libglabels/Template.cpp @@ -23,9 +23,6 @@ #include #include "Db.h" -#include "privateConstants.h" - -using namespace libglabels::Constants; namespace libglabels @@ -103,7 +100,7 @@ namespace libglabels void Template::initPreview() { - mPreview = MiniPreviewPixmap( this, PREVIEW_PIXMAP_SIZE, PREVIEW_PIXMAP_SIZE ); + mPreview = MiniPreviewPixmap( this, TEMPLATE_PREVIEW_SIZE, TEMPLATE_PREVIEW_SIZE ); } diff --git a/libglabels/Template.h b/libglabels/Template.h index b000afd..910bd67 100644 --- a/libglabels/Template.h +++ b/libglabels/Template.h @@ -37,11 +37,15 @@ namespace libglabels { + const int TEMPLATE_PREVIEW_SIZE = 80; + + class Template { Q_DECLARE_TR_FUNCTIONS(Template) public: + Template( const QString &brand, const QString &part, const QString &description, diff --git a/libglabels/privateConstants.h b/libglabels/privateConstants.h index acf3763..1eb5874 100644 --- a/libglabels/privateConstants.h +++ b/libglabels/privateConstants.h @@ -32,8 +32,6 @@ namespace libglabels { const double EPSILON = 0.5; /* Allowed error when comparing dimensions. (0.5pts ~= .007in ~= .2mm) */ - - const int PREVIEW_PIXMAP_SIZE = 72; } }