Subversion Repositories Scribus

Rev

Rev 1323 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
288 Franz 1
#include "ui.h"
2
#include "ui.moc"
3
#include <qvariant.h>
4
#include <qpushbutton.h>
1309 subik 5
#include <qlistview.h>
288 Franz 6
#include <qlabel.h>
7
#include <qlayout.h>
8
#include <qtooltip.h>
9
#include <qwhatsthis.h>
412 Franz 10
#include <qstring.h>
288 Franz 11
 
1309 subik 12
#include <prefsfile.h>
13
 
418 Franz 14
extern QPixmap fontSamples(QString da, int s, QString ts, QColor back);
288 Franz 15
extern QPixmap loadIcon(QString nam);
1309 subik 16
extern PrefsFile *prefsFile;
288 Franz 17
 
1309 subik 18
/*! Main window for "Font Preview" plugin. It's only gui.
19
 *
288 Franz 20
 *  Constructs a FontPreview as a child of 'parent', with the
21
 *  name 'name' and widget flags set to 'f'.
22
 *
23
 *  The dialog will by default be modeless, unless you set 'modal' to
24
 *  TRUE to construct a modal dialog.
25
 */
1309 subik 26
FontPreview::FontPreview(ScribusApp *carrier, QWidget* parent, const char* name, bool modal, WFlags fl)
27
        : QDialog(parent, name, modal, fl)
288 Franz 28
{
29
        this->carrier = carrier;
1309 subik 30
        if (!name)
31
                setName( "FontPreview" );
288 Franz 32
        setIcon(loadIcon("AppIcon.png"));
1309 subik 33
        // scribus config
34
        prefs = prefsFile->getPluginContext("fontpreview");
35
        sortColumn = prefs->getUInt("sortColumn", 0);
36
        xsize = prefs->getUInt("xsize", 640);
37
        ysize = prefs->getUInt("ysize", 480);
38
 
1321 fschmid 39
        FontPreviewLayout = new QGridLayout(this, 1, 1, 10, 5, "FontPreviewLayout");
40
        layout6 = new QVBoxLayout(0, 0, 5, "layout6");
41
        layout5 = new QHBoxLayout(0, 0, 5, "layout5");
1309 subik 42
        fontList = new QListView(this, "fontList" );
43
        fontList->setAllColumnsShowFocus(true);
1323 subik 44
        fontList->setShowSortIndicator(true);
1309 subik 45
        layout5->addWidget(fontList);
46
        // columns
1323 subik 47
        fontList->addColumn(tr("Font Name", "font preview"));
48
        fontList->addColumn(tr("Doc", "font preview"));
49
        fontList->setColumnAlignment(1, Qt::AlignCenter);
50
        fontList->addColumn(tr("Type", "font preview"));
51
        fontList->addColumn(tr("Subset", "font preview"));
52
        fontList->setColumnAlignment(3, Qt::AlignCenter);
53
        fontList->addColumn(tr("Access", "font preview"));
1309 subik 54
 
1321 fschmid 55
        layout2 = new QVBoxLayout(0, 0, 5, "layout2");
56
        layout1 = new QVBoxLayout(0, 0, 5, "layout1");
1309 subik 57
        okButton = new QPushButton(this, "okButton");
58
        layout1->addWidget(okButton);
59
        cancelButton = new QPushButton(this, "cancelButton");
60
        layout1->addWidget(cancelButton);
61
        layout2->addLayout(layout1);
62
        QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding);
63
        layout2->addItem(spacer);
64
        layout5->addLayout(layout2);
65
        layout6->addLayout(layout5);
66
        fontPreview = new QLabel(this, "fontPreview");
67
        fontPreview->setMinimumSize(QSize(400, 90));
1030 subik 68
        fontPreview->setFrameShape(QFrame::Box);
69
        fontPreview->setPaletteBackgroundColor(paletteBackgroundColor());
1309 subik 70
        layout6->addWidget(fontPreview);
288 Franz 71
 
1309 subik 72
        FontPreviewLayout->addLayout(layout6, 0, 0);
288 Franz 73
        languageChange();
1309 subik 74
        resize(QSize(xsize, ysize).expandedTo(minimumSizeHint()));
302 Franz 75
        layout()->activate();
1309 subik 76
        clearWState(WState_Polished);
77
 
78
        /* go through available fonts and check their properties */
79
        QMap<QString,QFont> reallyUsedFonts;
80
        reallyUsedFonts.clear();
81
        carrier->GetUsedFonts(&reallyUsedFonts);
1338 fschmid 82
        QPixmap ttfFont = loadIcon("font_truetype16.png");
83
        QPixmap otfFont = loadIcon("font_otf16.png");
84
        QPixmap psFont = loadIcon("font_type1_16.png");
1321 fschmid 85
        QPixmap okIcon = loadIcon("ok.png");
1323 subik 86
 
1309 subik 87
        for (SCFontsIterator fontIter(carrier->Prefs.AvailFonts); fontIter.current(); ++fontIter)
302 Franz 88
        {
89
                if (fontIter.current()->UseFont)
1309 subik 90
                {
1323 subik 91
                        QListViewItem *row = new QListViewItem(fontList);
1309 subik 92
                        QFileInfo fi = QFileInfo(fontIter.current()->Datei);
93
                        QString ext = fi.extension(false).lower();
1323 subik 94
 
1321 fschmid 95
                        row->setText(0, fontIter.current()->SCName);
1309 subik 96
                        if (reallyUsedFonts.contains(fontIter.current()->SCName))
1321 fschmid 97
                                row->setPixmap(1, okIcon);
1323 subik 98
 
99
                        if (ext == "otf")
100
                        {
101
                                row->setPixmap(2, otfFont);
102
                                row->setText(2, "OpenType");
103
                        }
104
                        else
105
                                if (fontIter.current()->Subset)
106
                                        row->setPixmap(3, okIcon);
107
 
1309 subik 108
                        if ((ext == "pfa") || (ext == "pfb")) // type1
1323 subik 109
                        {
1321 fschmid 110
                                row->setPixmap(2, psFont);
1323 subik 111
                                row->setText(2, "Type1");
112
                        }
113
 
1309 subik 114
                        if (ext == "ttf")
1323 subik 115
                        {
1321 fschmid 116
                                row->setPixmap(2, ttfFont);
1323 subik 117
                                row->setText(2, "TrueType");
118
                        }
119
 
120
                        fi.absFilePath().contains(QDir::homeDirPath()) ?
121
                                        row->setText(4, tr("User", "font preview")):
122
                                        row->setText(4, tr("System", "font preview"));
123
 
124
                        fontList->insertItem(row);
1309 subik 125
                }
302 Franz 126
        } // for fontIter
127
 
1309 subik 128
        fontList->setSorting(sortColumn);
129
 
130
        QListViewItem *item;
357 Franz 131
        if (carrier->DLLinput != "")
1309 subik 132
                item = fontList->findItem(carrier->DLLinput, 0);
343 Franz 133
        else
357 Franz 134
        {
456 fschmid 135
                if (carrier->view->SelItem.count() != 0)
1309 subik 136
                        item = fontList->findItem(carrier->doc->CurrFont, 0);
357 Franz 137
                else
1309 subik 138
                        item = fontList->findItem(carrier->Prefs.toolSettings.defFont, 0);
357 Franz 139
        }
343 Franz 140
        if (item != 0)
302 Franz 141
        {
343 Franz 142
                fontList_changed(item);
143
                fontList->setCurrentItem(item);
302 Franz 144
        }
145
 
288 Franz 146
        // signals and slots connections
1309 subik 147
        connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
148
        connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
149
        connect(fontList, SIGNAL(selectionChanged(QListViewItem*)), this, SLOT(fontList_changed(QListViewItem*)));
288 Franz 150
}
151
 
152
/**
1309 subik 153
 * Writes configuration, destroys the object and frees any allocated resources.
288 Franz 154
 */
155
FontPreview::~FontPreview()
156
{
1309 subik 157
   prefs->set("sortColumn", fontList->sortColumn());
1323 subik 158
   prefs->set("xsize", width());
159
   prefs->set("ysize", height());
288 Franz 160
}
161
 
1309 subik 162
/**
288 Franz 163
 *  Sets the strings of the subwidgets using the current
164
 *  language.
165
 */
166
void FontPreview::languageChange()
167
{
1323 subik 168
        setCaption(tr("Fonts Preview", "font preview"));
169
        okButton->setText(tr("&OK", "font preview"));
170
        okButton->setAccel(QKeySequence(tr("Alt+O", "font preview")));
171
        cancelButton->setText(tr("&Cancel", "font preview"));
172
        cancelButton->setAccel(QKeySequence(tr("Alt+C", "font preview")));
173
        QToolTip::add(okButton, tr("Append selected font into Style, Font menu", "font preview"));
174
        QToolTip::add(cancelButton,tr("Leave preview", "font preview"));
288 Franz 175
}
176
 
456 fschmid 177
/**
1309 subik 178
 * Creates pixmap with font sample
179
 */
180
void FontPreview::fontList_changed(QListViewItem *item)
288 Franz 181
{
412 Franz 182
        uint size = 16;
1323 subik 183
        QString t = tr("Woven silk pyjamas exchanged for blue quartz", "font preview");
1194 fschmid 184
        if (carrier->doc->toolSettings.defSize && carrier->doc->toolSettings.defSize < 28 && carrier->doc->toolSettings.defSize > 10)
185
                size = carrier->doc->toolSettings.defSize;
456 fschmid 186
        t.replace('\n', " "); // remove French <NL> from translation...
1309 subik 187
        QString da = carrier->Prefs.AvailFonts[item->text(0)]->Datei;
418 Franz 188
        QPixmap pixmap = fontSamples(da, size, t, paletteBackgroundColor());
288 Franz 189
        fontPreview->clear();
418 Franz 190
        if (!pixmap.isNull())
456 fschmid 191
                fontPreview->setPixmap(pixmap);
288 Franz 192
}
1309 subik 193