From 0b80340d5e88121d3a21e90ca69aa2be6f27a151 Mon Sep 17 00:00:00 2001 From: ruglory Date: Wed, 4 Feb 2009 19:32:39 +0000 Subject: [PATCH] Label mode in background color is added to cd scene Menu item new replaced with new lables with subitems cd view shows cd scene mode and color print dialog gets cd scene mode git-svn-id: https://svn.code.sf.net/p/qlscribe/svn/trunk@52 cac9541e-1b8d-4bfa-827e-589bba606050 --- src/mainwindow.cpp | 28 +++++++++++++++++++++++----- src/mainwindow.h | 3 ++- src/qcdscene.cpp | 24 +++++++++++++++++++++++- src/qcdscene.h | 19 +++++++++++++++---- src/qcdview.cpp | 41 +++++++++++++++++++++++++++++++++++++---- src/qdialogprint.cpp | 10 ++++++++-- src/qdialogprogress.cpp | 1 + src/qlightscribe.h | 11 ++--------- src/qlscribe.pro | 3 ++- 9 files changed, 113 insertions(+), 27 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d7362cf..b472965 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -42,15 +42,31 @@ MainWindow::MainWindow( bool enablePrint ) : QMainWindow( 0 ), m_mdiArea( new QMdiArea( this ) ), m_menuFile( 0 ), m_menuInsert( 0 ), - m_insertMapper( new QSignalMapper( this ) ) + m_insertMapper( new QSignalMapper( this ) ), + m_newLabelMapper( new QSignalMapper( this ) ) { setCentralWidget( m_mdiArea ); m_menuFile = menuBar()->addMenu( tr( "File", "Menu item \"File\"" ) ); - m_menuFile->addAction( tr( "New", "Menu item \"New\"" ), - this, - SLOT(onMenuNew()) ); + { + QMenu *newSubMenu = m_menuFile->addMenu( tr( "New label", "Menu item \"New lable\"" ) ); + QAction *action = newSubMenu->addAction( tr( "Full", "Menu item \"Full\"" ), + m_newLabelMapper, + SLOT(map()) ); + m_newLabelMapper->setMapping( action, modeFull ); + + action = newSubMenu->addAction( tr( "Content", "Menu item \"Content\"" ), + m_newLabelMapper, + SLOT(map()) ); + m_newLabelMapper->setMapping( action, modeContent ); + + action = newSubMenu->addAction( tr( "Title", "Menu item \"Title\"" ), + m_newLabelMapper, + SLOT(map()) ); + m_newLabelMapper->setMapping( action, modeTitle ); + } + connect( m_newLabelMapper, SIGNAL(mapped(int)), this, SLOT(onMenuNewLabel(int)) ); m_menuFile->addAction( tr( "Open...", "Menu item \"Open\"" ), this, @@ -174,10 +190,11 @@ bool MainWindow::saveScene( QCDScene *scene ) event->accept(); } -void MainWindow::onMenuNew() +void MainWindow::onMenuNewLabel( int mode ) { QCDView *newView = new QCDView; QCDScene *scene = new QCDScene( newView ); + scene->setLabelMode( LabelMode( mode ) ); newView->setScene( scene ); scene->setName(); @@ -268,6 +285,7 @@ void MainWindow::onMenuPrintPreview() return; QLightScribe::PrintParameters params; + params.m_labelMode = cdscene->labelMode(); QLightDrive *drive = QDialogPrint::exec( this, params ); if( !drive ) return; diff --git a/src/mainwindow.h b/src/mainwindow.h index 263dd95..965785b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -39,7 +39,7 @@ protected: virtual void closeEvent( QCloseEvent *event ); private slots: - void onMenuNew(); + void onMenuNewLabel( int mode ); void onMenuOpen(); void onMenuSave(); void onMenuSaveAs(); @@ -59,6 +59,7 @@ private: QMenu *m_menuHelp; QSignalMapper *m_insertMapper; + QSignalMapper *m_newLabelMapper; }; #endif // MAINWINDOW_H diff --git a/src/qcdscene.cpp b/src/qcdscene.cpp index 50422e4..5486a06 100644 --- a/src/qcdscene.cpp +++ b/src/qcdscene.cpp @@ -35,7 +35,9 @@ QCDScene::QCDScene( QObject * parent ) : QGraphicsScene( parent ), m_index( 0 ), - m_saved( true ) + m_saved( true ), + m_labelMode( modeFull ), + m_cdColor( Qt::white ) { setSceneRect( -60.0, -60.0, 60.0 * 2, 60.0 * 2 ); } @@ -82,6 +84,18 @@ bool QCDScene::save() return true; } +void QCDScene::setLabelMode( LabelMode mode ) +{ + m_labelMode = mode; + update(); +} + +void QCDScene::setCDColor( const QColor &color ) +{ + m_cdColor = color; + update(); +} + void QCDScene::setName() { if( m_fileName.isEmpty() ) { @@ -117,6 +131,10 @@ void QCDScene::updateTitles() const } } +void QCDScene::redrawViews() const +{ +} + bool QCDScene::saveAs( const QString &fileName ) { QFile file( fileName ); @@ -137,6 +155,8 @@ void QCDScene::write( QXmlStreamWriter &writer ) { writer.writeStartDocument(); writer.writeStartElement( "scene" ); + writer.writeAttribute( QXmlStreamAttribute( "mode", QString::number( m_labelMode ) ) ); + writer.writeAttribute( QXmlStreamAttribute( "color", m_cdColor.name() ) ); QShapeFactory &sfactory = QShapeFactory::instance(); QList list = items(); @@ -170,6 +190,8 @@ void QCDScene::read( QXmlStreamReader &reader ) throw QString( "QCDScene: missing expected root element \"scene\", got \"" ) + elementName + "\" intead"; + m_labelMode = LabelMode( reader.attributes().value( "mode" ).toString().toInt() ); + m_cdColor = QColor( reader.attributes().value( "color" ).toString() ); gotScene = true; continue; } diff --git a/src/qcdscene.h b/src/qcdscene.h index f4787d0..b239e91 100644 --- a/src/qcdscene.h +++ b/src/qcdscene.h @@ -21,6 +21,8 @@ #ifndef QCDSCENE_H #define QCDSCENE_H +#include "qlscribe.h" + #include class QXmlStreamWriter; @@ -32,6 +34,12 @@ public: QCDScene( QObject * parent = 0 ); virtual ~QCDScene(); + LabelMode labelMode() const { return m_labelMode; } + void setLabelMode( LabelMode mode ); + + QColor cdColor() const { return m_cdColor; } + void setCDColor( const QColor &color ); + bool isSaved() const { return m_saved; } bool isUnnamed() const { return m_fileName.isEmpty(); } @@ -42,6 +50,7 @@ public: bool saveAs( const QString &fileName ); void updateTitles() const; + void redrawViews() const; QString name() const { return m_name; } protected: @@ -59,10 +68,12 @@ private: void sendItemTo( bool front ); private: - QString m_name; - QString m_fileName; - int m_index; - bool m_saved; + QString m_name; + QString m_fileName; + int m_index; + bool m_saved; + LabelMode m_labelMode; + QColor m_cdColor; }; #endif //QCDSCENE_H diff --git a/src/qcdview.cpp b/src/qcdview.cpp index 8c95858..126524d 100644 --- a/src/qcdview.cpp +++ b/src/qcdview.cpp @@ -92,11 +92,44 @@ void QCDView::drawCD( QPainter *painter, const QRectF & rect, bool alpha ) painter->setBrush( alpha ? Qt::lightGray : Qt::gray ); painter->drawRect( rect ); - painter->setBrush( alpha ? Qt::black : Qt::white ); - drawCircle( painter, 59.0 ); + QCDScene *cdscene = scene(); + if( cdscene ) { + double inner = 25.0, outer = 59.0; + switch( cdscene->labelMode() ) { + case modeTitle : inner = 30.0; outer = 40.0; break; + case modeContent : inner = 30.0; outer = 50.0; break; + } + if( alpha ) { + painter->setBrush( Qt::black ); + drawCircle( painter, outer ); - painter->setBrush( alpha ? Qt::lightGray : Qt::darkGray ); - drawCircle( painter, 25.0 ); + painter->setBrush( Qt::lightGray ); + drawCircle( painter, inner ); + } else { + QColor darker( cdscene->cdColor().darker( 150 ) ); + if( outer < 59.0 ) { + painter->setBrush( darker ); + drawCircle( painter, 59.0 ); + } + + painter->setBrush( cdscene->cdColor() ); + drawCircle( painter, outer ); + + if( inner > 25.0 ) { + painter->setBrush( darker ); + drawCircle( painter, inner ); + } + + painter->setBrush( Qt::darkGray ); + drawCircle( painter, 25.0 ); + } + } else { + painter->setBrush( alpha ? Qt::black : Qt::white ); + drawCircle( painter, 59.0 ); + + painter->setBrush( alpha ? Qt::lightGray : Qt::darkGray ); + drawCircle( painter, 25.0 ); + } painter->setBrush( alpha ? Qt::white : Qt::gray ); drawCircle( painter, 10.7 ); diff --git a/src/qdialogprint.cpp b/src/qdialogprint.cpp index 9d030e4..6df3c3e 100644 --- a/src/qdialogprint.cpp +++ b/src/qdialogprint.cpp @@ -54,6 +54,12 @@ QLightDrive *QDialogPrint::exec( QWidget *parent, QLightScribe::PrintParameters return 0; } QDialogPrint dialog( parent ); + switch( params.m_labelMode ) { + case modeFull : dialog.m_ui->radioModeFull->setChecked( true ); break; + case modeContent : dialog.m_ui->radioModeContent->setChecked( true ); break; + case modeTitle : dialog.m_ui->radioModeTitle->setChecked( true ); break; + } + int index = 0; foreach( QLightDrive *drv, drives ) { dialog.m_ui->comboDrive->insertItem( index++, drv->displayName() ); @@ -64,10 +70,10 @@ QLightDrive *QDialogPrint::exec( QWidget *parent, QLightScribe::PrintParameters params = QLightScribe::PrintParameters(); // reset to default if( dialog.m_ui->radioModeTitle->isChecked() ) - params.m_labelMode = QLightScribe::modeTitle; + params.m_labelMode = modeTitle; if( dialog.m_ui->radioModeContent->isChecked() ) - params.m_labelMode = QLightScribe::modeContent; + params.m_labelMode = modeContent; if( dialog.m_ui->radioQualityNormal->isChecked() ) params.m_printQuality = QLightScribe::qualityNormal; diff --git a/src/qdialogprogress.cpp b/src/qdialogprogress.cpp index 3ff6148..0e50f35 100644 --- a/src/qdialogprogress.cpp +++ b/src/qdialogprogress.cpp @@ -62,6 +62,7 @@ void QDialogProgress::changeEvent(QEvent *e) bool QDialogProgress::exec( QWidget *parent, QCDScene *scene ) { QLightScribe::PrintParameters params; + params.m_labelMode = scene->labelMode(); QLightDrive *drive = QDialogPrint::exec( parent, params ); if( !drive ) return false; diff --git a/src/qlightscribe.h b/src/qlightscribe.h index f3f9f1f..d123929 100644 --- a/src/qlightscribe.h +++ b/src/qlightscribe.h @@ -21,6 +21,8 @@ #ifndef QLIGHTSCRIBE_H #define QLIGHTSCRIBE_H +#include "qlscribe.h" + #include #include @@ -37,15 +39,6 @@ class QLightDrive; class QLightScribe : public QThread { Q_OBJECT public: - enum LabelMode { - /** label the entire disc */ - modeFull=0, - /** label within the title mode constraints */ - modeTitle=1, - /** label within the content mode constraints */ - modeContent=2 - }; - enum DrawOptions { /** disable scaling of bitmaps; they will be cropped if needed */ drawDefault=0, diff --git a/src/qlscribe.pro b/src/qlscribe.pro index 7c53e0e..adb2e2b 100644 --- a/src/qlscribe.pro +++ b/src/qlscribe.pro @@ -32,7 +32,8 @@ HEADERS += mainwindow.h \ qdialogprint.h \ qdialogprogress.h \ qlighttextitem.h \ - qlightpixmapitem.h + qlightpixmapitem.h \ + qlscribe.h FORMS += qdialogtext.ui \ qdialogroundtext.ui \ qdialogpixmap.ui \