Initial implementation of TemplatePicker. Debugged mini previews.

This commit is contained in:
Jim Evins
2013-11-05 23:51:48 -05:00
parent fe4595bde0
commit ba83204445
11 changed files with 149 additions and 18 deletions
+2
View File
@@ -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
+12 -1
View File
@@ -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<libglabels::Template*> tmplates = libglabels::Db::templates();
tmp->setTemplates( tmplates );
#endif
setCentralWidget( tmp );
/////////////////////////////////////////////////
createActions();
createMenus();
+50
View File
@@ -0,0 +1,50 @@
/* TemplatePicker.cpp
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "TemplatePicker.h"
#include <QListWidgetItem>
#include <QIcon>
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 <libglabels::Template*> &tmplates )
{
foreach (libglabels::Template *tmplate, tmplates)
{
QListWidgetItem *item = new QListWidgetItem( tmplate->name(), this );
item->setIcon( QIcon(tmplate->preview()) );
}
}
}
+51
View File
@@ -0,0 +1,51 @@
/* TemplatePicker.h
*
* Copyright (C) 2013 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_TemplatePicker_h
#define glabels_TemplatePicker_h
#include <QListWidget>
#include <QList>
#include "libglabels/Template.h"
namespace gLabels
{
class TemplatePicker : public QListWidget
{
Q_OBJECT
public:
TemplatePicker( QWidget *parent = 0 );
void setTemplates( const QList <libglabels::Template*> &tmplates );
private:
};
}
#endif // glabels_TemplatePicker_h
+15 -1
View File
@@ -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<Paper*> &papers() { return mPapers; }
static const QStringList &paperIds() { return mPaperIds; }
static const QStringList &paperNames() { return mPaperNames; }
static const QList<Category*> &categories() { return mCategories; }
static const QStringList &categoryIds() { return mCategoryIds; }
static const QStringList &categoryNames() { return mCategoryNames; }
static const QList<Vendor*> &vendors() { return mVendors; }
static const QStringList &vendorNames() { return mVendorNames; }
static const QList<Template*> &templates() { return mTemplates; }
static void registerPaper( Paper *paper );
static const Paper *lookupPaperFromName( const QString &name );
static const Paper *lookupPaperFromId( const QString &id );
+2 -1
View File
@@ -45,13 +45,14 @@ namespace libglabels
{
QVector<Point> 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() );
}
}
}
+9 -8
View File
@@ -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 );
}
}
+3 -1
View File
@@ -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;
+1 -4
View File
@@ -23,9 +23,6 @@
#include <iostream>
#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 );
}
+4
View File
@@ -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,
-2
View File
@@ -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;
}
}