[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
src/klftools/klfrelativefont.h
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   file klfrelativefont.h
00003  *   This file is part of the KLatexFormula Project.
00004  *   Copyright (C) 2011 by Philippe Faist
00005  *   philippe.faist at bluewin.ch
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /* $Id$ */
00023 
00024 #ifndef KLFRELATIVEFONT_H
00025 #define KLFRELATIVEFONT_H
00026 
00027 #include <QObject>
00028 #include <QWidget>
00029 #include <QFont>
00030 
00031 #include <klfdefs.h>
00032 
00033 
00034 class KLF_EXPORT KLFRelativeFontBase : public QObject
00035 {
00036   Q_OBJECT
00037 public:
00038   KLFRelativeFontBase(QWidget *parent);
00039   KLFRelativeFontBase(QWidget *reference, QWidget *target);
00040   virtual ~KLFRelativeFontBase();
00041 
00042   bool eventFilter(QObject *object, QEvent *event);
00043 
00044   void setThorough(bool thorough);
00045 
00046 protected:
00047   virtual QFont calculateRelativeFont(const QFont& baseFont) = 0;
00048 
00049   inline QWidget * referenceWidget() { return pReference; }
00050   inline QWidget * targetWidget() { return pTarget; }
00051 
00052 private:
00053   void calculateAndApplyNewFont();
00054 
00055 private:
00056   QWidget *pReference;
00057   QWidget *pTarget;
00058 
00059   bool pInhibitFontChangeRecursion;
00060   bool pHasAppliedFont;
00061 
00062   bool pThorough;
00063 };
00064 
00065 
00066 // ----
00067 
00068 
00069 class KLF_EXPORT KLFRelativeFont : public KLFRelativeFontBase
00070 {
00071   Q_OBJECT
00072 public:
00073   KLFRelativeFont(QWidget *parent);
00074   KLFRelativeFont(QWidget *reference, QWidget *target);
00075 
00076   virtual ~KLFRelativeFont();
00077 
00078   inline QString forceFamily() const { return pForceFamily; }
00079   inline int relPointSize() const { return pRelPointSize; }
00080 
00081   void setRelPointSize(int relps);
00082 
00083   void setForceFamily(const QString& family);
00084   void releaseForceFamily() { setForceFamily(QString()); }
00085 
00086   void setForceBold(bool bold) { setForceWeight(bold ? QFont::Bold : QFont::Normal); }
00087   void setForceWeight(int weight);
00088   void releaseForceWeight() { setForceWeight(-1); }
00089 
00090   void setForceItalic(bool it) { setForceStyle(it ? QFont::StyleItalic : QFont::StyleNormal); }
00091   void setForceStyle(int style);
00092   void releaseForceStyle() { setForceStyle(-1); }
00093 
00094 protected:
00095   virtual QFont calculateRelativeFont(const QFont& baseFont);
00096 
00097 private:
00098   QString pForceFamily;
00099   int pRelPointSize;
00100   int pForceWeight;
00101   int pForceStyle;
00102 
00103   void rfinit();
00104 };
00105 
00106 
00107 #endif

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net