2004-05-05 09:30:32 +00:00
|
|
|
/***************************************************************************
|
2004-06-01 01:05:43 +00:00
|
|
|
plugin.cpp
|
2004-05-05 09:30:32 +00:00
|
|
|
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. *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
// includes
|
|
|
|
|
|
|
|
#include <qgisapp.h>
|
|
|
|
#include <qgsmaplayer.h>
|
|
|
|
#include "plugin.h"
|
2004-11-11 09:07:00 +00:00
|
|
|
#include <qgsproject.h>
|
2004-05-05 09:30:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include <qtoolbar.h>
|
|
|
|
#include <qmenubar.h>
|
|
|
|
#include <qmessagebox.h>
|
|
|
|
#include <qpopupmenu.h>
|
|
|
|
#include <qlineedit.h>
|
|
|
|
#include <qaction.h>
|
|
|
|
#include <qapplication.h>
|
|
|
|
#include <qcursor.h>
|
2004-05-05 10:38:41 +00:00
|
|
|
#include <qpixmap.h>
|
|
|
|
#include <qpainter.h>
|
|
|
|
#include <qfont.h>
|
2004-05-08 11:59:10 +00:00
|
|
|
#include <qrect.h>
|
|
|
|
#include <qbrush.h>
|
|
|
|
#include <qbutton.h>
|
2004-05-16 22:02:10 +00:00
|
|
|
#include <qcheckbox.h>
|
2004-06-01 08:05:15 +00:00
|
|
|
#include <qpaintdevicemetrics.h>
|
2004-05-05 09:30:32 +00:00
|
|
|
|
|
|
|
//non qt includes
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
//the gui subclass
|
|
|
|
#include "plugingui.h"
|
|
|
|
|
|
|
|
// xpm for creating the toolbar icon
|
|
|
|
#include "icon.xpm"
|
2004-06-14 04:35:20 +00:00
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define QGISEXTERN extern "C" __declspec( dllexport )
|
|
|
|
#else
|
|
|
|
#define QGISEXTERN extern "C"
|
|
|
|
#endif
|
|
|
|
|
2004-05-05 09:30:32 +00:00
|
|
|
static const char * const ident_ = "$Id$";
|
|
|
|
|
|
|
|
static const char * const name_ = "CopyrightLabel";
|
|
|
|
static const char * const description_ = "This plugin overlays copyright information on the rendered map.";
|
|
|
|
static const char * const version_ = "Version 0.1";
|
|
|
|
static const QgisPlugin::PLUGINTYPE type_ = QgisPlugin::UI;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the plugin. The plugin is passed a pointer to the main app
|
|
|
|
* and an interface object that provides access to exposed functions in QGIS.
|
|
|
|
* @param qgis Pointer to the QGIS main window
|
|
|
|
* @param _qI Pointer to the QGIS interface object
|
|
|
|
*/
|
|
|
|
Plugin::Plugin(QgisApp * theQGisApp, QgisIface * theQgisInterFace):
|
2004-06-01 01:05:43 +00:00
|
|
|
qgisMainWindowPointer(theQGisApp),
|
2004-05-05 09:30:32 +00:00
|
|
|
qGisInterface(theQgisInterFace),
|
|
|
|
QgisPlugin(name_,description_,version_,type_)
|
|
|
|
{
|
2004-05-08 11:59:10 +00:00
|
|
|
|
2004-05-05 09:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Plugin::~Plugin()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-06-01 01:05:43 +00:00
|
|
|
* Initialize the GUI interface for the plugin
|
2004-05-05 09:30:32 +00:00
|
|
|
*/
|
|
|
|
void Plugin::initGui()
|
|
|
|
{
|
|
|
|
// add a menu with 2 items
|
|
|
|
QPopupMenu *pluginMenu = new QPopupMenu(qgisMainWindowPointer);
|
|
|
|
|
|
|
|
pluginMenu->insertItem(QIconSet(icon),"&CopyrightLabel", this, SLOT(run()));
|
|
|
|
|
|
|
|
menuBarPointer = ((QMainWindow *) qgisMainWindowPointer)->menuBar();
|
|
|
|
|
|
|
|
menuIdInt = qGisInterface->addMenu("&Decorations", pluginMenu);
|
|
|
|
// Create the action for tool
|
2004-08-30 00:53:35 +00:00
|
|
|
myQActionPointer = new QAction("Copyright Label", QIconSet(icon), "&Wmi",0, this, "run");
|
2004-05-05 09:30:32 +00:00
|
|
|
// Connect the action to the run
|
|
|
|
connect(myQActionPointer, SIGNAL(activated()), this, SLOT(run()));
|
2004-05-05 10:38:41 +00:00
|
|
|
// This calls the north arrow renderer everytime the cnavas has drawn itself
|
2004-06-01 01:05:43 +00:00
|
|
|
connect(qGisInterface->getMapCanvas(), SIGNAL(renderComplete(QPainter *)), this, SLOT(renderLabel(QPainter *)));
|
2004-08-28 01:09:46 +00:00
|
|
|
// Add the icon to the toolbar
|
|
|
|
qGisInterface->addToolBarIcon(myQActionPointer);
|
2004-11-11 09:07:00 +00:00
|
|
|
//default text to start with - try to fetch it from qgsproject
|
|
|
|
QgsProject::Properties myProperties = QgsProject::instance()->properties("CopyrightLabel");
|
|
|
|
for ( QgsProject::Properties::const_iterator i = myProperties.begin();
|
|
|
|
i != myProperties.end();
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
qDebug( "%s -> %s", (*i).first.ascii(), (*i).second.toString().ascii() );
|
|
|
|
QString myCurrentKeyString = (*i).first;
|
|
|
|
if ( "FontName" == myCurrentKeyString )
|
|
|
|
{
|
|
|
|
mQFont.setFamily((*i).second.toString());
|
|
|
|
}
|
|
|
|
else if( "FontSize" == myCurrentKeyString )
|
|
|
|
{
|
|
|
|
mQFont.setPointSize((*i).second.toInt());
|
|
|
|
}
|
2004-11-12 13:55:19 +00:00
|
|
|
else if( "Label" == myCurrentKeyString )
|
|
|
|
{
|
|
|
|
mLabelQString = (*i).second.toString();
|
|
|
|
}
|
|
|
|
else if( "Placement" == myCurrentKeyString )
|
|
|
|
{
|
|
|
|
mPlacement = (*i).second.toString();
|
|
|
|
}
|
|
|
|
else if( "Enabled" == myCurrentKeyString )
|
|
|
|
{
|
|
|
|
mEnable = (*i).second.toBool();
|
|
|
|
}
|
|
|
|
// todo - store state of font color
|
2004-11-11 09:07:00 +00:00
|
|
|
}
|
|
|
|
|
2004-11-12 13:55:19 +00:00
|
|
|
if (mLabelQString.isEmpty()) mLabelQString = QString(" QGIS 2004");
|
|
|
|
if (mQFont.family().isEmpty()) mQFont = QFont("times", 12, QFont::Bold);
|
|
|
|
if (mPlacement.isEmpty()) mPlacement=tr("Bottom Right");
|
|
|
|
|
|
|
|
//todo - read from settings file
|
2004-05-06 15:32:56 +00:00
|
|
|
mLabelQColor = QColor(Qt::black);
|
2004-05-08 11:59:10 +00:00
|
|
|
|
2004-05-05 10:38:41 +00:00
|
|
|
refreshCanvas();
|
2004-05-05 09:30:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
//method defined in interface
|
|
|
|
void Plugin::help()
|
|
|
|
{
|
|
|
|
//implement me!
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slot called when the buffer menu item is activated
|
|
|
|
void Plugin::run()
|
|
|
|
{
|
|
|
|
PluginGui *myPluginGui=new PluginGui(qgisMainWindowPointer,"Copyright Label",true,0);
|
|
|
|
//listen for when the layer has been made so we can draw it
|
2004-05-05 10:38:41 +00:00
|
|
|
//connect(myPluginGui, SIGNAL(drawRasterLayer(QString)), this, SLOT(drawRasterLayer(QString)));
|
|
|
|
//connect(myPluginGui, SIGNAL(drawVectorLayer(QString,QString,QString)), this, SLOT(drawVectorLayer(QString,QString,QString)));
|
|
|
|
//refresh the canvas when the user presses ok
|
|
|
|
connect(myPluginGui, SIGNAL(refreshCanvas()), this, SLOT(refreshCanvas()));
|
2004-05-06 15:32:56 +00:00
|
|
|
connect(myPluginGui, SIGNAL(changeFont(QFont )), this, SLOT(setFont(QFont )));
|
|
|
|
connect(myPluginGui, SIGNAL(changeLabel(QString )), this, SLOT(setLabel(QString )));
|
|
|
|
connect(myPluginGui, SIGNAL(changeColor(QColor)), this, SLOT(setColor(QColor)));
|
2004-05-08 11:59:10 +00:00
|
|
|
connect(myPluginGui, SIGNAL(changePlacement(QString)), this, SLOT(setPlacement(QString)));
|
2004-05-16 22:02:10 +00:00
|
|
|
connect(myPluginGui, SIGNAL(enableCopyrightLabel(bool)), this, SLOT(setEnable(bool)));
|
2004-05-24 08:12:46 +00:00
|
|
|
myPluginGui->setText(mLabelQString);
|
2004-05-24 23:29:12 +00:00
|
|
|
myPluginGui->setPlacement(mPlacement);
|
2004-05-05 09:30:32 +00:00
|
|
|
myPluginGui->show();
|
|
|
|
}
|
2004-05-05 10:38:41 +00:00
|
|
|
//! Refresh the map display using the mapcanvas exported via the plugin interface
|
|
|
|
void Plugin::refreshCanvas()
|
|
|
|
{
|
|
|
|
qGisInterface->getMapCanvas()->refresh();
|
|
|
|
}
|
|
|
|
|
2004-06-01 01:05:43 +00:00
|
|
|
void Plugin::renderLabel(QPainter * theQPainter)
|
|
|
|
{
|
2004-05-24 23:29:12 +00:00
|
|
|
//Large IF statement to enable/disable copyright label
|
|
|
|
if (mEnable)
|
2004-05-08 11:59:10 +00:00
|
|
|
{
|
2004-05-24 23:29:12 +00:00
|
|
|
//@todo softcode this!myQSimpleText.height()
|
|
|
|
int myRotationInt = 90;
|
2004-06-01 08:05:15 +00:00
|
|
|
// need width/height of paint device
|
|
|
|
QPaintDeviceMetrics myMetrics( theQPainter->device() );
|
|
|
|
int myHeight = myMetrics.height();
|
|
|
|
int myWidth = myMetrics.width();
|
2004-05-24 23:29:12 +00:00
|
|
|
//hard coded cludge for getting a colorgroup. Needs to be replaced
|
|
|
|
QButton * myQButton =new QButton();
|
2004-06-01 01:05:43 +00:00
|
|
|
QColorGroup myQColorGroup = myQButton->colorGroup();
|
2004-05-24 23:29:12 +00:00
|
|
|
|
|
|
|
QSimpleRichText myQSimpleText(mLabelQString, mQFont);
|
2004-06-01 08:05:15 +00:00
|
|
|
myQSimpleText.setWidth( theQPainter, myWidth-10 );
|
2004-05-24 23:29:12 +00:00
|
|
|
|
|
|
|
//Get canvas dimensions
|
2004-06-01 08:05:15 +00:00
|
|
|
int myYOffset = myHeight;
|
|
|
|
int myXOffset = myWidth;
|
2004-05-24 23:29:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
//Determine placement of label from form combo box
|
|
|
|
if (mPlacement==tr("Bottom Left"))
|
|
|
|
{
|
|
|
|
//Define bottom left hand corner start point
|
|
|
|
myYOffset = myYOffset - (myQSimpleText.height()+5);
|
|
|
|
myXOffset = 5;
|
2004-06-01 01:05:43 +00:00
|
|
|
}
|
2004-05-24 23:29:12 +00:00
|
|
|
else if (mPlacement==tr("Top Left"))
|
|
|
|
{
|
|
|
|
//Define top left hand corner start point
|
|
|
|
myYOffset = 5;
|
|
|
|
myXOffset = 5;
|
|
|
|
}
|
|
|
|
else if (mPlacement==tr("Top Right"))
|
|
|
|
{
|
|
|
|
//Define top right hand corner start point
|
|
|
|
myYOffset = 5;
|
|
|
|
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
|
2004-06-01 01:05:43 +00:00
|
|
|
}
|
2004-05-24 23:29:12 +00:00
|
|
|
else // defaulting to bottom right
|
|
|
|
{
|
|
|
|
//Define bottom right hand corner start point
|
|
|
|
myYOffset = myYOffset - (myQSimpleText.height()+5);
|
|
|
|
myXOffset = myXOffset - (myQSimpleText.widthUsed()+5);
|
2004-06-01 01:05:43 +00:00
|
|
|
}
|
2004-05-24 23:29:12 +00:00
|
|
|
|
|
|
|
//Paint label to canvas
|
|
|
|
QRect myRect(myXOffset,myYOffset,myQSimpleText.widthUsed(),myQSimpleText.height());
|
2004-06-01 01:05:43 +00:00
|
|
|
myQSimpleText.draw (theQPainter, myXOffset, myYOffset, myRect, myQColorGroup);
|
2004-05-24 23:29:12 +00:00
|
|
|
|
2004-05-08 11:59:10 +00:00
|
|
|
}
|
2004-05-16 22:02:10 +00:00
|
|
|
}
|
2004-05-05 09:30:32 +00:00
|
|
|
// Unload the plugin by cleaning up the GUI
|
|
|
|
void Plugin::unload()
|
|
|
|
{
|
|
|
|
// remove the GUI
|
|
|
|
menuBarPointer->removeItem(menuIdInt);
|
2004-08-30 00:53:35 +00:00
|
|
|
qGisInterface->removeToolBarIcon(myQActionPointer);
|
|
|
|
delete myQActionPointer;
|
2004-05-05 09:30:32 +00:00
|
|
|
}
|
2004-05-06 15:32:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
//! change the copyright font
|
|
|
|
void Plugin::setFont(QFont theQFont)
|
|
|
|
{
|
|
|
|
mQFont = theQFont;
|
2004-11-11 09:07:00 +00:00
|
|
|
//save state to the project file.....
|
|
|
|
QgsProject::instance()->properties("CopyrightLabel").append
|
|
|
|
( QgsProject::PropertyValue("FontName",
|
|
|
|
theQFont.family() ) );
|
|
|
|
//save state to the project file.....
|
|
|
|
QgsProject::instance()->properties("CopyrightLabel").append
|
|
|
|
( QgsProject::PropertyValue("FontSize",
|
|
|
|
theQFont.pointSize() ) );
|
2004-05-24 23:29:12 +00:00
|
|
|
refreshCanvas();
|
2004-05-06 15:32:56 +00:00
|
|
|
}
|
|
|
|
//! change the copyright text
|
|
|
|
void Plugin::setLabel(QString theLabelQString)
|
|
|
|
{
|
|
|
|
mLabelQString = theLabelQString;
|
2004-11-12 13:55:19 +00:00
|
|
|
QgsProject::instance()->properties("CopyrightLabel").append
|
|
|
|
( QgsProject::PropertyValue("Label",
|
|
|
|
mLabelQString ) );
|
2004-05-24 23:29:12 +00:00
|
|
|
refreshCanvas();
|
2004-05-06 15:32:56 +00:00
|
|
|
}
|
|
|
|
//! change the copyright text colour
|
|
|
|
void Plugin::setColor(QColor theQColor)
|
|
|
|
{
|
|
|
|
mLabelQColor = theQColor;
|
2004-11-12 13:55:19 +00:00
|
|
|
QgsProject::instance()->properties("CopyrightLabel").append
|
|
|
|
( QgsProject::PropertyValue("ColorRedPart",
|
|
|
|
mLabelQColor.red() ) );
|
|
|
|
QgsProject::instance()->properties("CopyrightLabel").append
|
|
|
|
( QgsProject::PropertyValue("ColorGreenPart",
|
|
|
|
mLabelQColor.green() ) );
|
|
|
|
QgsProject::instance()->properties("CopyrightLabel").append
|
|
|
|
( QgsProject::PropertyValue("ColorBluePart",
|
|
|
|
mLabelQColor.blue() ) );
|
2004-05-24 23:29:12 +00:00
|
|
|
refreshCanvas();
|
2004-05-06 15:32:56 +00:00
|
|
|
}
|
2004-06-01 01:05:43 +00:00
|
|
|
|
2004-05-08 11:59:10 +00:00
|
|
|
//! set placement of copyright label
|
|
|
|
void Plugin::setPlacement(QString theQString)
|
|
|
|
{
|
|
|
|
mPlacement = theQString;
|
2004-11-12 13:55:19 +00:00
|
|
|
QgsProject::instance()->properties("CopyrightLabel").append
|
|
|
|
( QgsProject::PropertyValue("Placement",
|
|
|
|
mPlacement ) );
|
2004-05-24 23:29:12 +00:00
|
|
|
refreshCanvas();
|
2004-05-08 11:59:10 +00:00
|
|
|
}
|
2004-05-06 15:32:56 +00:00
|
|
|
|
2004-05-16 22:02:10 +00:00
|
|
|
//! set whether copyright label is enabled
|
|
|
|
void Plugin::setEnable(bool theBool)
|
|
|
|
{
|
|
|
|
mEnable = theBool;
|
2004-11-12 13:55:19 +00:00
|
|
|
QgsProject::instance()->properties("CopyrightLabel").append
|
|
|
|
( QgsProject::PropertyValue("Enabled",
|
|
|
|
mEnable ) );
|
2004-05-24 23:29:12 +00:00
|
|
|
refreshCanvas();
|
2004-05-16 22:02:10 +00:00
|
|
|
}
|
2004-05-06 15:32:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-06-01 01:05:43 +00:00
|
|
|
/**
|
|
|
|
* Required extern functions needed for every plugin
|
2004-05-05 09:30:32 +00:00
|
|
|
* These functions can be called prior to creating an instance
|
|
|
|
* of the plugin class
|
|
|
|
*/
|
|
|
|
// Class factory to return a new instance of the plugin class
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN QgisPlugin * classFactory(QgisApp * theQGisAppPointer, QgisIface * theQgisInterfacePointer)
|
2004-05-05 09:30:32 +00:00
|
|
|
{
|
|
|
|
return new Plugin(theQGisAppPointer, theQgisInterfacePointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the name of the plugin - note that we do not user class members as
|
|
|
|
// the class may not yet be insantiated when this method is called.
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN QString name()
|
2004-05-05 09:30:32 +00:00
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the description
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN QString description()
|
2004-05-05 09:30:32 +00:00
|
|
|
{
|
|
|
|
return description_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the type (either UI or MapLayer plugin)
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN int type()
|
2004-05-05 09:30:32 +00:00
|
|
|
{
|
|
|
|
return type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the version number for the plugin
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN QString version()
|
2004-05-05 09:30:32 +00:00
|
|
|
{
|
|
|
|
return version_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete ourself
|
2004-06-14 04:35:20 +00:00
|
|
|
QGISEXTERN void unload(QgisPlugin * thePluginPointer)
|
2004-05-05 09:30:32 +00:00
|
|
|
{
|
|
|
|
delete thePluginPointer;
|
|
|
|
}
|