Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes
FontPreview Class Reference

Main window for "Font Preview" plugin. More...

#include <fontpreview.h>

List of all members.

Public Member Functions

 FontPreview (QString fontName=QString::null, QWidget *parent=0, ScribusDoc *doc=0)
 Create Font Preview window,.
 ~FontPreview ()
 Writes configuration, destroys the object and frees any allocated resources.
QString getCurrentFont ()
 Get the current selected font name.

Protected Slots

virtual void languageChange ()
 Translations.
virtual void searchEdit_textChanged (const QString &s)
 Called after each text change.
virtual void searchButton_clicked ()
 Fill the font list by search mask.
virtual void fontList_mouseButtonClicked (int button, QListViewItem *item, const QPoint &point, int column)
 Creates pixmap with font sample.
void displayButton_clicked ()
 Setup the preview phrase instead of "blue quartz...".
void resetDisplayButton_clicked ()
 Reset the sample phrase to the standard "blue quartz".
void sizeSpin_valueChanged (int)
void cancelButton_clicked ()
void okButton_clicked ()

Protected Member Functions

void updateFontList (QString searchStr)
 Setup fontList by search string.
void keyReleaseEvent (QKeyEvent *k)
 Overriden key event to prevent "preview freeze" waiting for preview painting.
void paintSample (QListViewItem *item)
 Create a pixmap sample with font preview.
bool allowSample ()
 Check if is there any item in list to prevent crashes.

Protected Attributes

QPixmap ttfFont
 Pixmaps for each font type.
QPixmap otfFont
QPixmap psFont
QPixmap okIcon
QString defaultStr
 Default "blue quartz" text.
PrefsContext * prefs
 Configuration structure.
uint sortColumn
 Column for sorting.
uint xsize
 window size
uint ysize
SampleItem * sampleItem
 Sample text frame to render the preview.
ScribusDoc * m_Doc

Detailed Description

Main window for "Font Preview" plugin.

It's only gui. Constructs a FontPreview as a child of 'parent', with the name 'name' and widget flags set to 'f'. The dialog will by default be modeless, unless you set 'modal' to true to construct a modal dialog.

Definition at line 25 of file fontpreview.h.


Constructor & Destructor Documentation

FontPreview::FontPreview ( QString  fontName = QString::null,
QWidget *  parent = 0,
ScribusDoc *  doc = 0 
)

Create Font Preview window,.

Parameters:
fontNameOptional name of the font to init/select on start.

Definition at line 31 of file fontpreview.cpp.

       : FontPreviewBase(parent, "FontPreview", true, 0)
{
       setIcon(loadIcon("AppIcon.png"));
       m_Doc=doc;

       sampleItem = new SampleItem(m_Doc);

       languageChange();

       fontList->setAllColumnsShowFocus(true);
       fontList->setShowSortIndicator(true);
       fontList->setColumnAlignment(1, Qt::AlignCenter);
       fontList->setColumnAlignment(3, Qt::AlignCenter);
       resetDisplayButton->setPixmap(loadIcon("u_undo16.png"));

       ttfFont = loadIcon("font_truetype16.png");
       otfFont = loadIcon("font_otf16.png");
       psFont = loadIcon("font_type1_16.png");
       okIcon = loadIcon("ok.png");

       updateFontList("");

       // scribus config
       defaultStr = tr("Woven silk pyjamas exchanged for blue quartz", "font preview");
       prefs = PrefsManager::instance()->prefsFile->getPluginContext("fontpreview");
       sortColumn = prefs->getUInt("sortColumn", 0);
       fontList->setSorting(sortColumn);
       xsize = prefs->getUInt("xsize", 640);
       ysize = prefs->getUInt("ysize", 480);
       sizeSpin->setValue(prefs->getUInt("fontSize", 18));
       QString ph = prefs->get("phrase", defaultStr);
       displayEdit->setText(ph);
       displayButton_clicked();
       resize(QSize(xsize, ysize).expandedTo(minimumSizeHint()));

       // set initial listitem
       QListViewItem *item;
       if (!fontName.isEmpty())
              item = fontList->findItem(fontName, 0);
       else
       {
              Q_ASSERT(m_Doc!=0);
              if (m_Doc->m_Selection->count() != 0)
                     item = fontList->findItem(m_Doc->currentStyle.charStyle().font().scName(), 0);
              else
                     item = fontList->findItem(PrefsManager::instance()->appPrefs.toolSettings.defFont, 0);
       }
       if (item != 0)
       {
              fontList->setCurrentItem(item);
              paintSample(item);
              fontList->center(0, fontList->currentItem()->itemPos());
//            qDebug("1");
       }
}

Here is the call graph for this function:

Writes configuration, destroys the object and frees any allocated resources.

Definition at line 91 of file fontpreview.cpp.

{
       prefs->set("sortColumn", fontList->sortColumn());
       prefs->set("xsize", width());
       prefs->set("ysize", height());
       prefs->set("fontSize", sizeSpin->value());
       prefs->set("phrase", displayEdit->text());
       sampleItem->cleanupTemporary(); // just to be sure
}

Member Function Documentation

bool FontPreview::allowSample ( ) [protected]

Check if is there any item in list to prevent crashes.

It allows not to paint the sample if there could be memory leak. E.g. if (allowSample()) paintSample(fontList->currentItem()); See code as example.

Return values:
booltrue if you can paint sample safely.

Definition at line 114 of file fontpreview.cpp.

{
       if (fontList->childCount() != 0)
              return true;
       fontPreview->setText("No font selected");
       return false;
}

Here is the caller graph for this function:

void FontPreview::cancelButton_clicked ( ) [protected, slot]

Definition at line 238 of file fontpreview.cpp.

{
       reject();
}
void FontPreview::displayButton_clicked ( ) [protected, slot]

Setup the preview phrase instead of "blue quartz...".

Definition at line 226 of file fontpreview.cpp.

{
       sampleItem->setText(displayEdit->text());
       if (allowSample())
              paintSample(fontList->currentItem());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FontPreview::fontList_mouseButtonClicked ( int  button,
QListViewItem *  item,
const QPoint &  point,
int  column 
) [protected, virtual, slot]

Creates pixmap with font sample.

Parameters:
itemcurrent list item

Definition at line 134 of file fontpreview.cpp.

{
       if (allowSample())
              paintSample(item);
}

Here is the call graph for this function:

Get the current selected font name.

Return values:
QStringthe font name.

Definition at line 221 of file fontpreview.cpp.

{
       return fontList->currentItem()->text(0);
}
void FontPreview::keyReleaseEvent ( QKeyEvent *  k) [protected]

Overriden key event to prevent "preview freeze" waiting for preview painting.

Sample is painted only on key release, no in the repeat mode.

Parameters:
kevent to get the mode

Definition at line 122 of file fontpreview.cpp.

{
       if (k->isAutoRepeat())
       {
              fontPreview->setText( tr("Sample will be shown after key release"));
              return;
       }
       if (allowSample())
              paintSample(fontList->currentItem());
}

Here is the call graph for this function:

void FontPreview::languageChange ( ) [protected, virtual, slot]

Translations.

Sets the strings of the subwidgets using the current language.

Definition at line 105 of file fontpreview.cpp.

{
       QToolTip::add(okButton, "<qt>" + tr("Append selected font into Style, Font menu", "font preview") + "</qt>");
       QToolTip::add(cancelButton,tr("Leave preview", "font preview"));
       QToolTip::add(searchEdit, "<qt>" + tr("Typing the text here provides quick searching in the font names. Searching is case insensitive. You can provide a common wild cards (*, ?, [...]) in your phrase. Examples: t* will list all fonts starting with t or T. *bold* will list all fonts with word bold, bolder etc. in the name.") + "</qt>");
       QToolTip::add(searchButton, tr("Start searching"));
       QToolTip::add(sizeSpin, tr("Size of the selected font"));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FontPreview::okButton_clicked ( ) [protected, slot]

Definition at line 233 of file fontpreview.cpp.

{
       accept();
}
void FontPreview::paintSample ( QListViewItem *  item) [protected]

Create a pixmap sample with font preview.

Parameters:
itema reference to existing item (see allowSample())

Definition at line 140 of file fontpreview.cpp.

{
       if (!item)
              return;
       sampleItem->setFontSize(sizeSpin->value() * 10, true);
       sampleItem->setFont(item->text(0));
       QPixmap pixmap = sampleItem->getSample(fontPreview->maximumWidth(),
                                                                         fontPreview->maximumHeight());
       fontPreview->clear();
       if (!pixmap.isNull())
              fontPreview->setPixmap(pixmap);
}

Here is the caller graph for this function:

void FontPreview::resetDisplayButton_clicked ( ) [protected, slot]

Reset the sample phrase to the standard "blue quartz".

Definition at line 243 of file fontpreview.cpp.

{
       displayEdit->setText(defaultStr);
       displayButton_clicked();
}

Here is the call graph for this function:

void FontPreview::searchButton_clicked ( ) [protected, virtual, slot]

Fill the font list by search mask.

Definition at line 216 of file fontpreview.cpp.

{
       updateFontList(searchEdit->text());
}

Here is the call graph for this function:

void FontPreview::searchEdit_textChanged ( const QString &  s) [protected, virtual, slot]

Called after each text change.

It checks the string length for 0 length- calling font list re-filling with all fonts = without search filter. Of course that search filling can be used afterall all changes but it will slow down the dialog.

Parameters:
sstring

Definition at line 210 of file fontpreview.cpp.

{
       if (s.length()==0)
              updateFontList(s);
}

Here is the call graph for this function:

void FontPreview::sizeSpin_valueChanged ( int  ) [protected, slot]

Definition at line 249 of file fontpreview.cpp.

{
       if (allowSample())
              paintSample(fontList->currentItem());
}

Here is the call graph for this function:

void FontPreview::updateFontList ( QString  searchStr) [protected]

Setup fontList by search string.

If the search string is empty list all fonts

Parameters:
searchStrtext to search

Definition at line 153 of file fontpreview.cpp.

{
       fontList->clear();
       if (searchStr.find('*') == -1)
              searchStr = '*' + searchStr + '*';
       QRegExp re(searchStr);
       re.setCaseSensitive(false);
       re.setWildcard(true);

       for (SCFontsIterator fontIter(PrefsManager::instance()->appPrefs.AvailFonts);
                     fontIter.hasNext(); fontIter.next())
       {
              if (searchStr.length()!=0 & !re.exactMatch(fontIter.current().scName()))
                     continue;

              if (fontIter.current().usable())
              {
                     QListViewItem *row = new QListViewItem(fontList);
                     ScFace::FontType type = fontIter.current().type();

                     row->setText(0, fontIter.current().scName());
                     // searching

                     if (m_Doc->UsedFonts.contains(fontIter.current().scName()))
                            row->setPixmap(1, okIcon);

                     if (type == ScFace::OTF)
                     {
                            row->setPixmap(2, otfFont);
                            row->setText(2, "OpenType");
                     }
                     else
                            if (fontIter.current().subset())
                                   row->setPixmap(3, okIcon);

                     if (type == ScFace::TYPE1) // type1
                     {
                            row->setPixmap(2, psFont);
                            row->setText(2, "Type1");
                     }

                     if (type == ScFace::TTF)
                     {
                            row->setPixmap(2, ttfFont);
                            row->setText(2, "TrueType");
                     }

                     QFileInfo fi(fontIter.current().fontFilePath());
                     fi.absFilePath().contains(QDir::homeDirPath()) ?
                                   row->setText(4, tr("User", "font preview")):
                                   row->setText(4, tr("System", "font preview"));

                     fontList->insertItem(row);
              }
       } // for fontIter
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

QString FontPreview::defaultStr [protected]

Default "blue quartz" text.

Definition at line 47 of file fontpreview.h.

ScribusDoc* FontPreview::m_Doc [protected]

Definition at line 76 of file fontpreview.h.

QPixmap FontPreview::okIcon [protected]

Definition at line 45 of file fontpreview.h.

QPixmap FontPreview::otfFont [protected]

Definition at line 43 of file fontpreview.h.

PrefsContext* FontPreview::prefs [protected]

Configuration structure.

Definition at line 49 of file fontpreview.h.

QPixmap FontPreview::psFont [protected]

Definition at line 44 of file fontpreview.h.

SampleItem* FontPreview::sampleItem [protected]

Sample text frame to render the preview.

Definition at line 56 of file fontpreview.h.

uint FontPreview::sortColumn [protected]

Column for sorting.

Definition at line 51 of file fontpreview.h.

QPixmap FontPreview::ttfFont [protected]

Pixmaps for each font type.

Definition at line 42 of file fontpreview.h.

uint FontPreview::xsize [protected]

window size

Definition at line 53 of file fontpreview.h.

uint FontPreview::ysize [protected]

Definition at line 54 of file fontpreview.h.


The documentation for this class was generated from the following files: