summaryrefslogtreecommitdiffstats
path: root/scribus/plugins/fontpreview/fontpreviewplugin.cpp
blob: 4288de7e81bce80935dbc26f31473beae6d302d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include "fontpreviewplugin.h"
//#include "fontpreviewplugin.moc"
#include "fontpreview.h"
#include "scribuscore.h"
#include "scribusdoc.h"
#include <QCursor>

int fontpreview_getPluginAPIVersion()
{
	return PLUGIN_API_VERSION;
}

ScPlugin* fontpreview_getPlugin()
{
	FontPreviewPlugin* plug = new FontPreviewPlugin();
	Q_CHECK_PTR(plug);
	return plug;
}

void fontpreview_freePlugin(ScPlugin* plugin)
{
	FontPreviewPlugin* plug = dynamic_cast<FontPreviewPlugin*>(plugin);
	Q_ASSERT(plug);
	delete plug;
}

FontPreviewPlugin::FontPreviewPlugin() : ScActionPlugin()
{
	// Set action info in languageChange, so we only have to do
	// it in one place.
	languageChange();
}

FontPreviewPlugin::~FontPreviewPlugin() {};

void FontPreviewPlugin::languageChange()
{
	// Note that we leave the unused members unset. They'll be initialised
	// with their default ctors during construction.
	// Action name
	m_actionInfo.name = "FontPreview";
	// Action text for menu, including accel
	m_actionInfo.text = tr("&Font Preview...");
	// Menu
	m_actionInfo.menu = "Extras";
	m_actionInfo.enabledOnStartup = false;
	m_actionInfo.needsNumObjects = -1;
}

const QString FontPreviewPlugin::fullTrName() const
{
	return QObject::tr("Font Preview");
}

const ScActionPlugin::AboutData* FontPreviewPlugin::getAboutData() const
{
	AboutData* about = new AboutData;
	Q_CHECK_PTR(about);
	about->authors = QString::fromUtf8("Petr Van\xc4\x9bk <petr@scribus.info>");
	about->shortDescription = tr("Font Preview dialog");
	about->description = tr("Sorting, searching and browsing available fonts.");
	// about->version
	// about->releaseDate
	// about->copyright
	about->license = "GPL";
	return about;
}

void FontPreviewPlugin::deleteAboutData(const AboutData* about) const
{
	Q_ASSERT(about);
	delete about;
}

/**
Create dialog and insert font into Style menu when user accepts.
*/
bool FontPreviewPlugin::run(ScribusDoc* doc, QString target)
{
	ScribusMainWindow* scmw=(doc==0)?ScCore->primaryMainWindow():doc->scMW();
	return run(scmw, doc, target);
}

bool FontPreviewPlugin::run(QWidget* parent, ScribusDoc* doc, QString target)
{
	if (doc==NULL)
		return false;
	// I don't know how many fonts user has...
	qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
	FontPreview *dlg = new FontPreview(target, parent, doc);
	qApp->changeOverrideCursor(Qt::ArrowCursor);
	// run it and wait for user's reaction
	if (dlg->exec() == QDialog::Accepted)
	{
		if  (target.isEmpty())
			doc->scMW()->SetNewFont(dlg->getCurrentFont());
		else
			m_runResult = dlg->getCurrentFont();
	}
	delete dlg;
	return true;
}