Skip to content
Permalink
Browse files

Moved copyright label plugin to app

  • Loading branch information
wonder-sk committed Aug 21, 2011
1 parent 92e57da commit 20958725309440e347f0e9e82769f2862a54842f
@@ -350,6 +350,7 @@
<file>north_arrows/default.png</file>
<file>themes/default/locked.png</file>
<file>themes/default/unlocked.png</file>
<file>themes/default/plugins/copyright_label.png</file>
</qresource>
<qresource prefix="/images/tips">
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>
@@ -21,6 +21,8 @@ SET(QGIS_APP_SRCS
qgscustomprojectiondialog.cpp
qgsdbfilterproxymodel.cpp
qgsdbtablemodel.cpp
qgsdecorationcopyright.cpp
qgsdecorationcopyrightdialog.cpp
qgsembedlayerdialog.cpp
qgsformannotationdialog.cpp
qgsdelattrdialog.cpp
@@ -153,6 +155,8 @@ SET (QGIS_APP_MOC_HDRS
qgscustomization.h
qgscustomprojectiondialog.h
qgsdbtablemodel.h
qgsdecorationcopyright.h
qgsdecorationcopyrightdialog.h
qgsdelattrdialog.h
qgsdisplayangle.h
qgsembedlayerdialog.h
@@ -114,6 +114,7 @@
#include "qgscustomization.h"
#include "qgscustomprojectiondialog.h"
#include "qgsdatasourceuri.h"
#include "qgsdecorationcopyright.h"
#include "qgsembedlayerdialog.h"
#include "qgsencodingfiledialog.h"
#include "qgsexception.h"
@@ -437,6 +438,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
initLegend();
createOverview();
createMapTips();
createDecorations();
readSettings();
updateRecentProjectPaths();
activateDeactivateLayerRelatedActions( NULL );
@@ -1470,6 +1472,7 @@ void QgisApp::setTheme( QString theThemeName )
mActionMoveLabel->setIcon( getThemeIcon( "/mActionMoveLabel.png" ) );
mActionRotateLabel->setIcon( getThemeIcon( "/mActionRotateLabel.png" ) );
mActionChangeLabelProperties->setIcon( getThemeIcon( "/mActionChangeLabelProperties.png" ) );
mActionDecorationCopyright->setIcon( getThemeIcon( "/plugins/copyright_label.png" ) );

//change themes of all composers
QSet<QgsComposer*>::iterator composerIt = mPrintComposers.begin();
@@ -1803,6 +1806,14 @@ void QgisApp::createMapTips()
mpMaptip = new QgsMapTip();
}

void QgisApp::createDecorations()
{
mDecorationCopyright = new QgsDecorationCopyright(this);
connect( mActionDecorationCopyright, SIGNAL( triggered() ), mDecorationCopyright, SLOT( run() ) );
connect( mMapCanvas, SIGNAL( renderComplete( QPainter * ) ), mDecorationCopyright, SLOT( renderLabel( QPainter * ) ) );
connect( this, SIGNAL( projectRead() ), mDecorationCopyright, SLOT( projectRead() ) );
}

// Update file menu with the current list of recently accessed projects
void QgisApp::updateRecentProjectPaths()
{
@@ -69,6 +69,8 @@ class QgsBrowserDockWidget;
class QgsSnappingDialog;
class QgsGPSInformationWidget;

class QgsDecorationCopyright;

#include <QMainWindow>
#include <QToolBar>
#include <QAbstractSocket>
@@ -864,6 +866,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
bool createDB();
void createMapTips();
void updateCRSStatusBar();
void createDecorations();

// actions for menus and toolbars -----------------

@@ -1051,6 +1054,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! Persistent tile scale slider
QgsTileScaleWidget * mpTileScaleWidget;

QgsDecorationCopyright* mDecorationCopyright;

int mLastComposerId;

#ifdef Q_OS_WIN
@@ -0,0 +1,152 @@
/***************************************************************************
plugin.cpp
Import tool for various worldmap analysis output files
Functions:
-------------------
begin : Jan 21, 2004
copyright : (C) 2004 by Tim Sutton
email : tim@linfiniti.com
***************************************************************************/

/***************************************************************************
* *
* This program 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 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

// includes

#include "qgsdecorationcopyright.h"
#include "qgsdecorationcopyrightdialog.h"

#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgisapp.h"

#include <QPainter>
#include <QMenu>
#include <QDate>
#include <QTextDocument>
#include <QMatrix>
#include <QFile>

//non qt includes
#include <cmath>


QgsDecorationCopyright::QgsDecorationCopyright( QObject* parent )
: QObject(parent)
{
mPlacementLabels << tr( "Bottom Left" ) << tr( "Top Left" )
<< tr( "Top Right" ) << tr( "Bottom Right" );

// initialise default values in the gui
projectRead();
}

QgsDecorationCopyright::~QgsDecorationCopyright()
{}

void QgsDecorationCopyright::projectRead()
{
QDate now;
QString defString;

now = QDate::currentDate();
defString = "&copy; QGIS " + now.toString( "yyyy" );

// there is no font setting in the UI, so just use the Qt/QGIS default font (what mQFont gets when created)
// mQFont.setFamily( QgsProject::instance()->readEntry( "CopyrightLabel", "/FontName", "Sans Serif" ) );
// mQFont.setPointSize( QgsProject::instance()->readNumEntry( "CopyrightLabel", "/FontSize", 9 ) );
QgsProject* prj = QgsProject::instance();
mLabelQString = prj->readEntry( "CopyrightLabel", "/Label", defString );
mPlacementIndex = prj->readNumEntry( "CopyrightLabel", "/Placement", 3 );
mEnable = prj->readBoolEntry( "CopyrightLabel", "/Enabled", true );
mLabelQColor.setNamedColor( prj->readEntry( "CopyrightLabel", "/Color", "#000000" ) ); // default color is black
}

// Slot called when the buffer menu item is activated
void QgsDecorationCopyright::run()
{
QgsDecorationCopyrightDialog dlg( *this, QgisApp::instance() );

if (dlg.exec())
{
saveToProject();
QgisApp::instance()->mapCanvas()->refresh();
}
}


void QgsDecorationCopyright::renderLabel( QPainter * theQPainter )
{
//Large IF statement to enable/disable copyright label
if ( mEnable )
{
// need width/height of paint device
int myHeight = theQPainter->device()->height();
int myWidth = theQPainter->device()->width();

QTextDocument text;
text.setDefaultFont( mQFont );
// To set the text color in a QTextDocument we use a CSS style
QString style = "<style type=\"text/css\"> p {color: " +
mLabelQColor.name() + "}</style>";
text.setHtml( style + "<p>" + mLabelQString + "</p>" );
QSizeF size = text.size();

float myXOffset( 0 ), myYOffset( 0 );
//Determine placement of label from form combo box
switch ( mPlacementIndex )
{
case 0: // Bottom Left
//Define bottom left hand corner start point
myYOffset = myHeight - ( size.height() + 5 );
myXOffset = 5;
break;
case 1: // Top left
//Define top left hand corner start point
myYOffset = 0;;
myXOffset = 5;
break;
case 2: // Top Right
//Define top right hand corner start point
myYOffset = 0;
myXOffset = myWidth - ( size.width() + 5 );
break;
case 3: // Bottom Right
//Define bottom right hand corner start point
myYOffset = myHeight - ( size.height() + 5 );
myXOffset = myWidth - ( size.width() + 5 );
break;
default:
QgsDebugMsg( QString( "Unknown placement index of %1" ).arg( mPlacementIndex ) );
}

//Paint label to canvas
QMatrix worldMatrix = theQPainter->worldMatrix();
theQPainter->translate( myXOffset, myYOffset );
text.drawContents( theQPainter );
// Put things back how they were
theQPainter->setWorldMatrix( worldMatrix );
}
}

void QgsDecorationCopyright::saveToProject()
{
//save state to the project file.....
QgsProject* prj = QgsProject::instance();
prj->writeEntry( "CopyrightLabel", "/FontName", mQFont.family() );
prj->writeEntry( "CopyrightLabel", "/FontSize", mQFont.pointSize() );
prj->writeEntry( "CopyrightLabel", "/Label", mLabelQString );
prj->writeEntry( "CopyrightLabel", "/Color", mLabelQColor.name() );
prj->writeEntry( "CopyrightLabel", "/Placement", mPlacementIndex );
prj->writeEntry( "CopyrightLabel", "/Enabled", mEnable );
}
@@ -18,61 +18,35 @@
***************************************************************************/
#ifndef QGSCOPYRIGHTLABELPLUGIN
#define QGSCOPYRIGHTLABELPLUGIN
#include "../qgisplugin.h"

#include <QColor>
#include <QFont>
#include <QObject>
class QAction;
class QPainter;

class QgisInterface;
class QgsDecorationCopyrightDialog;

/**
* \class Plugin
* \brief OpenModeller plugin for QGIS
*
*/
class QgsCopyrightLabelPlugin: public QObject, public QgisPlugin
class QgsDecorationCopyright : public QObject
{
Q_OBJECT public:
/**
* Constructor for a plugin. The QgisInterface pointer is passed by
* QGIS when it attempts to instantiate the plugin.
* @param qI Pointer to the QgisInterface object.
*/
QgsCopyrightLabelPlugin( QgisInterface * );
Q_OBJECT
public:

//! Constructor
QgsDecorationCopyright( QObject* parent = NULL );
//! Destructor
virtual ~ QgsCopyrightLabelPlugin();
void writeEntry( QString theScope, QString theProperty, QVariant theValue );
virtual ~QgsDecorationCopyright();

public slots:
//! init the gui
void initGui();
//!set values on the gui when a project is read or the gui first loaded
//! set values on the gui when a project is read or the gui first loaded
void projectRead();
//! save values to the project
void saveToProject();

//! Show the dialog box
void run();
//! render the copyright label
void renderLabel( QPainter * );
//! Refresh the map display using the mapcanvas exported via the plugin interface
void refreshCanvas();
//! unload the plugin
void unload();
//! show the help document
void help();
//! change the copyright font
void setFont( QFont );
//! change the copyright text
void setLabel( QString );
//! change the copyright font color
void setColor( QColor );
//! set copyright label placement
void setPlacement( int );
//! set copyright label enabled
void setEnable( bool );
//! update the plugins theme when the app tells us its theme is changed
void setCurrentTheme( QString theThemeName );



private:
//! This is the font that will be used for the copyright label
@@ -87,11 +61,7 @@ class QgsCopyrightLabelPlugin: public QObject, public QgisPlugin
//! Copyright label enabled
bool mEnable;

int pluginType;
//! Pointer to the QGIS interface object
QgisInterface *qGisInterface;
//! Pointer to the QAction object used in the menu and toolbar
QAction *myQActionPointer;
friend class QgsDecorationCopyrightDialog;
};

#endif

0 comments on commit 2095872

Please sign in to comment.
You can’t perform that action at this time.