bpp-qt  2.1.0
Bpp/Qt/QtTools.h
Go to the documentation of this file.
00001 //
00002 // File: QtTools.h
00003 // Created by: Julien Dutheil
00004 // Created on: Wed Dec 30 2009
00005 //
00006 
00007 /*
00008 Copyright or © or Copr. CNRS, (November 16, 2006)
00009 
00010 This software is a computer program whose purpose is to provide 
00011 graphical components using the Qt library.
00012 This file belongs to the Bio++ Project.
00013 
00014 This software is governed by the CeCILL  license under French law and
00015 abiding by the rules of distribution of free software.  You can  use, 
00016 modify and/ or redistribute the software under the terms of the CeCILL
00017 license as circulated by CEA, CNRS and INRIA at the following URL
00018 "http://www.cecill.info". 
00019 
00020 As a counterpart to the access to the source code and  rights to copy,
00021 modify and redistribute granted by the license, users are provided only
00022 with a limited warranty  and the software's author,  the holder of the
00023 economic rights,  and the successive licensors  have only  limited
00024 liability. 
00025 
00026 In this respect, the user's attention is drawn to the risks associated
00027 with loading,  using,  modifying and/or developing or reproducing the
00028 software by the user in light of its specific status of free software,
00029 that may mean  that it is complicated to manipulate,  and  that  also
00030 therefore means  that it is reserved for developers  and  experienced
00031 professionals having in-depth computer knowledge. Users are therefore
00032 encouraged to load and test the software's suitability as regards their
00033 requirements in conditions enabling the security of their systems and/or 
00034 data to be ensured and,  more generally, to use and operate it in the 
00035 same conditions as regards security. 
00036 
00037 The fact that you are presently reading this means that you have had
00038 knowledge of the CeCILL license and that you accept its terms.
00039 */
00040 
00041 #ifndef _QTTOOLS_H_
00042 #define _QTTOOLS_H_
00043 
00044 #include <Bpp/Graphics/RgbColor.h>
00045 #include <Bpp/Graphics/Font/Font.h>
00046 #include <Bpp/BppString.h>
00047 #include <Bpp/Numeric/Number.h>
00048 
00049 //From Qt:
00050 #include <QColor>
00051 #include <QFont>
00052 
00053 namespace bpp
00054 {
00055 
00061 class QtTools
00062 {
00063 public:
00064 
00065   static QString toQt(const char* str)
00066   {
00067     return QString(str);
00068   }
00069 
00070    static QString toQt(const std::string& str)
00071   {
00072     return QString(str.c_str());
00073   }
00074 
00075   static QString toQt(const BppString& str)
00076   {
00077     return QString(str.toSTL().c_str());
00078   }
00079 
00080   template<class T>
00081   static QString toQt(const Number<T>& number)
00082   {
00083     return toQt(TextTools::toString(number.getValue()));
00084   }
00085 
00086   static QColor toQt(const RGBColor& color)
00087   {
00088     return QColor(color[0], color[1], color[2]);
00089   }
00090 
00091   static QFont toQt(const Font& font)
00092   {
00093     QFont qFont(toQt(font.getFamily()), static_cast<int>(font.getSize()));
00094     
00095     if (font.getStyle() == Font::STYLE_NORMAL)
00096       qFont.setStyle(QFont::StyleNormal); 
00097     else if(font.getStyle() == Font::STYLE_ITALIC)
00098       qFont.setStyle(QFont::StyleItalic); 
00099     
00100     if (font.getWeight() == Font::WEIGHT_NORMAL)
00101       qFont.setWeight(QFont::Normal); 
00102     else if (font.getWeight() == Font::WEIGHT_BOLD)
00103       qFont.setWeight(QFont::Bold); 
00104     
00105     return qFont;
00106  }
00107 
00108 };
00109 
00110 } //end of namespace bpp;
00111 
00112 #endif //_QTTOOLS_H_
00113 
 All Classes Namespaces Files Functions Variables Typedefs Friends