From d6511969cde6707d6671b5629b9aa700885f867d Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 23 Feb 2012 20:25:33 +0100 Subject: [PATCH] Extend application branding --- src/App/Application.cpp | 2 +- src/Gui/BitmapFactory.cpp | 4 ++ src/Gui/CommandStd.cpp | 4 +- src/Gui/MainWindow.cpp | 28 +++++------ src/Gui/NavigationStyle.cpp | 2 + src/Gui/Splashscreen.cpp | 4 +- src/Main/FreeCADGuiPy.cpp | 4 +- src/Main/MainCmd.cpp | 2 +- src/Main/MainGui.cpp | 81 +++++++++++++++++------------- src/Main/res/branding.xml | 23 +++++++++ src/Mod/MeshPart/Gui/PreCompiled.h | 8 ++- 11 files changed, 104 insertions(+), 58 deletions(-) create mode 100644 src/Main/res/branding.xml diff --git a/src/App/Application.cpp b/src/App/Application.cpp index 541203ab6..2afdac40f 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -1095,7 +1095,7 @@ void Application::initConfig(int argc, char ** argv) mConfig["BuildVersionMajor"].c_str(), mConfig["BuildVersionMinor"].c_str(), mConfig["BuildRevision"].c_str(), - mConfig["ConsoleBanner"].c_str()); + mConfig["CopyrightInfo"].c_str()); else Console().Message("%s %s, Libs: %s.%sB%s\n",mConfig["ExeName"].c_str(), mConfig["ExeVersion"].c_str(), diff --git a/src/Gui/BitmapFactory.cpp b/src/Gui/BitmapFactory.cpp index bbf130914..3ec0189e7 100644 --- a/src/Gui/BitmapFactory.cpp +++ b/src/Gui/BitmapFactory.cpp @@ -77,6 +77,10 @@ BitmapFactoryInst& BitmapFactoryInst::instance(void) if (_pcSingleton == NULL) { _pcSingleton = new BitmapFactoryInst; + std::map::const_iterator it; + it = App::GetApplication().Config().find("ProgramIcons"); + if (it != App::GetApplication().Config().end()) + _pcSingleton->addPath(QString::fromUtf8(it->second.c_str())); _pcSingleton->addPath(QLatin1String(":/icons/")); _pcSingleton->addPath(QLatin1String(":/Icons/")); _pcSingleton->addPath(QString::fromUtf8(App::GetApplication().GetHomePath())); diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index 2cf32c57a..089fdb523 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -193,7 +193,7 @@ Action * StdCmdAbout::createAction(void) QString exe; std::map& cfg = App::Application::Config(); - std::map::iterator it = cfg.find("WindowTitle"); + std::map::iterator it = cfg.find("Application"); if (it != cfg.end()) exe = QString::fromUtf8(it->second.c_str()); else @@ -235,7 +235,7 @@ void StdCmdAbout::languageChange() if (_pcAction) { QString exe; std::map& cfg = App::Application::Config(); - std::map::iterator it = cfg.find("WindowTitle"); + std::map::iterator it = cfg.find("Application"); if (it != cfg.end()) exe = QString::fromUtf8(it->second.c_str()); else diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index b36d3e661..05f5c8f47 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1303,12 +1303,15 @@ QPixmap MainWindow::splashImage() const if (fi.isFile() && fi.exists()) splash_image.load(fi.filePath(), "PNG"); if (splash_image.isNull()) - splash_image = Gui::BitmapFactory().pixmap(App::Application::Config()["SplashPicture"].c_str()); + splash_image = Gui::BitmapFactory().pixmap(App::Application::Config()["SplashScreen"].c_str()); // include application name and version number - std::map::const_iterator tc = App::Application::Config().find("SplashExeColor"); + std::map::const_iterator tc = App::Application::Config().find("SplashInfoColor"); if (tc != App::Application::Config().end()) { - QString exeName = QString::fromAscii(App::Application::Config()["ExeName"].c_str()); + QString title = QString::fromAscii(App::Application::Config()["ExeName"].c_str()); + std::map::iterator it = App::Application::Config().find("Application"); + if (it != App::Application::Config().end()) + title = QString::fromUtf8(it->second.c_str()); QString major = QString::fromAscii(App::Application::Config()["BuildVersionMajor"].c_str()); QString minor = QString::fromAscii(App::Application::Config()["BuildVersionMinor"].c_str()); QString version = QString::fromAscii("%1.%2").arg(major).arg(minor); @@ -1318,7 +1321,7 @@ QPixmap MainWindow::splashImage() const QFont fontExe = painter.font(); fontExe.setPointSize(20); QFontMetrics metricExe(fontExe); - int l = metricExe.width(exeName); + int l = metricExe.width(title); int w = splash_image.width(); int h = splash_image.height(); @@ -1329,17 +1332,14 @@ QPixmap MainWindow::splashImage() const QColor color; color.setNamedColor(QString::fromAscii(tc->second.c_str())); - if (!color.isValid()) { - color.setRed(200); - color.setGreen(200); - color.setBlue(200); + if (color.isValid()) { + painter.setPen(color); + painter.setFont(fontExe); + painter.drawText(w-(l+v+10),h-20, title); + painter.setFont(fontVer); + painter.drawText(w-(v+5),h-20, version); + painter.end(); } - painter.setPen(color); - painter.setFont(fontExe); - painter.drawText(w-(l+v+10),h-20, exeName); - painter.setFont(fontVer); - painter.drawText(w-(v+5),h-20, version); - painter.end(); } return splash_image; diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 34bec5184..883183fc1 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -715,6 +715,8 @@ void NavigationStyle::zoomByCursor(const SbVec2f & thispos, const SbVec2f & prev void NavigationStyle::doZoom(SoCamera* camera, SbBool forward, const SbVec2f& pos) { + if (this->button3down) + return; SbBool zoomAtCur = this->zoomAtCursor; if (zoomAtCur) { const SbViewportRegion & vp = viewer->getViewportRegion(); diff --git a/src/Gui/Splashscreen.cpp b/src/Gui/Splashscreen.cpp index 53dd9688f..fbfaca519 100644 --- a/src/Gui/Splashscreen.cpp +++ b/src/Gui/Splashscreen.cpp @@ -256,7 +256,7 @@ void AboutDialog::setupLabels() std::map::iterator it = config.find("WindowTitle"); if (it != config.end()) exeName = QString::fromUtf8(it->second.c_str()); - QString banner = QString::fromUtf8(config["ConsoleBanner"].c_str()); + QString banner = QString::fromUtf8(config["CopyrightInfo"].c_str()); banner = banner.left( banner.indexOf(QLatin1Char('\n')) ); QString major = QString::fromAscii(config["BuildVersionMajor"].c_str()); QString minor = QString::fromAscii(config["BuildVersionMinor"].c_str()); @@ -266,7 +266,7 @@ void AboutDialog::setupLabels() QString author = ui->labelAuthor->text(); author.replace(QString::fromAscii("Unknown Application"), exeName); - author.replace(QString::fromAscii("Unknown Author"), banner); + author.replace(QString::fromAscii("(c) Unknown Author"), banner); ui->labelAuthor->setText(author); ui->labelAuthor->setUrl(mturl); diff --git a/src/Main/FreeCADGuiPy.cpp b/src/Main/FreeCADGuiPy.cpp index ab5320e37..f3fb494cb 100644 --- a/src/Main/FreeCADGuiPy.cpp +++ b/src/Main/FreeCADGuiPy.cpp @@ -303,8 +303,8 @@ PyMODINIT_FUNC initFreeCADGui() try { Base::Interpreter().loadModule("FreeCAD"); App::Application::Config()["AppIcon"] = "freecad"; - App::Application::Config()["SplashPicture"] = "freecadsplash"; - App::Application::Config()["ConsoleBanner"] = "\xc2\xa9 Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2011\n"; + App::Application::Config()["SplashScreen"] = "freecadsplash"; + App::Application::Config()["CopyrightInfo"] = "\xc2\xa9 Juergen Riegel, Werner Mayer, Yorik van Havre 2001-2011\n"; Gui::Application::initApplication(); Py_InitModule("FreeCADGui", FreeCADGui_methods); } diff --git a/src/Main/MainCmd.cpp b/src/Main/MainCmd.cpp index b6c335e1b..f42d7598b 100644 --- a/src/Main/MainCmd.cpp +++ b/src/Main/MainCmd.cpp @@ -79,7 +79,7 @@ int main( int argc, char ** argv ) App::Application::Config()["AppDataSkipVendor"] = "true"; // set the banner (for logging and console) - App::Application::Config()["ConsoleBanner"] = sBanner; + App::Application::Config()["CopyrightInfo"] = sBanner; try { // Init phase =========================================================== diff --git a/src/Main/MainGui.cpp b/src/Main/MainGui.cpp index 7d898cfe7..83c4487f4 100644 --- a/src/Main/MainGui.cpp +++ b/src/Main/MainGui.cpp @@ -35,6 +35,10 @@ # include #endif // HAVE_CONFIG_H +#include +#include +#include + #include #include #include @@ -74,16 +78,31 @@ const char sBanner[] = "\xc2\xa9 Juergen Riegel, Werner Mayer, Yorik van Havre 2 class Branding { public: - struct UserDefines - { - std::string windowTitle; - std::string windowIcon; - std::string programLogo; - std::string splashScreen; - }; - + typedef std::map XmlConfig; Branding() { + filter.push_back("Application"); + filter.push_back("WindowTitle"); + filter.push_back("CopyrightInfo"); + filter.push_back("MaintainerUrl"); + filter.push_back("WindowIcon"); + filter.push_back("ProgramLogo"); + filter.push_back("ProgramIcons"); + + filter.push_back("BuildVersionMajor"); + filter.push_back("BuildVersionMinor"); + filter.push_back("BuildRevision"); + filter.push_back("BuildRevisionDate"); + + filter.push_back("SplashScreen"); + filter.push_back("SplashAlignment"); + filter.push_back("SplashTextColor"); + filter.push_back("SplashInfoColor"); + + filter.push_back("StartWorkbench"); + + filter.push_back("ExeName"); + filter.push_back("ExeVendor"); } bool readFile(const QString& fn) @@ -96,29 +115,26 @@ public: file.close(); return true; } - UserDefines getUserDefines() const + XmlConfig getUserDefines() const { - UserDefines ud; + XmlConfig cfg; QDomElement root = domDocument.documentElement(); QDomElement child; if (!root.isNull()) { - child = root.firstChildElement(QLatin1String("WindowTitle")); - if (!child.isNull()) - ud.windowTitle = (const char*)child.text().toUtf8(); - child = root.firstChildElement(QLatin1String("WindowIcon")); - if (!child.isNull()) - ud.windowIcon = (const char*)child.text().toUtf8(); - child = root.firstChildElement(QLatin1String("ProgramLogo")); - if (!child.isNull()) - ud.programLogo = (const char*)child.text().toUtf8(); - child = root.firstChildElement(QLatin1String("SplashScreen")); - if (!child.isNull()) - ud.splashScreen = (const char*)child.text().toUtf8(); + child = root.firstChildElement(); + while (!child.isNull()) { + std::string name = (const char*)child.localName().toAscii(); + std::string value = (const char*)child.text().toUtf8(); + if (std::find(filter.begin(), filter.end(), name) != filter.end()) + cfg[name] = value; + child = child.nextSiblingElement(); + } } - return ud; + return cfg; } private: + std::vector filter; bool evaluateXML(QIODevice *device, QDomDocument& xmlDocument) { QString errorStr; @@ -269,14 +285,14 @@ int main( int argc, char ** argv ) App::Application::Config()["MaintainerUrl"] = "http://apps.sourceforge.net/mediawiki/free-cad/index.php?title=Main_Page"; // set the banner (for logging and console) - App::Application::Config()["ConsoleBanner"] = sBanner; + App::Application::Config()["CopyrightInfo"] = sBanner; App::Application::Config()["AppIcon"] = "freecad"; - App::Application::Config()["SplashPicture"] = "freecadsplash"; + App::Application::Config()["SplashScreen"] = "freecadsplash"; App::Application::Config()["StartWorkbench"] = "StartWorkbench"; //App::Application::Config()["HiddenDockWindow"] = "Property editor"; App::Application::Config()["SplashAlignment" ] = "Bottom|Left"; App::Application::Config()["SplashTextColor" ] = "#ffffff"; // white - App::Application::Config()["SplashExeColor" ] = "#c8c8c8"; // light grey + App::Application::Config()["SplashInfoColor" ] = "#c8c8c8"; // light grey try { // Init phase =========================================================== @@ -326,15 +342,10 @@ int main( int argc, char ** argv ) QString path = QString::fromUtf8(App::GetApplication().GetHomePath()); QFileInfo fi(path, QString::fromAscii("branding.xml")); if (brand.readFile(fi.absoluteFilePath())) { - Branding::UserDefines ud = brand.getUserDefines(); - if (!ud.windowTitle.empty()) - App::Application::Config()["WindowTitle"] = ud.windowTitle; - if (!ud.windowIcon.empty()) - App::Application::Config()["WindowIcon"] = ud.windowIcon; - if (!ud.programLogo.empty()) - App::Application::Config()["ProgramLogo"] = ud.programLogo; - if (!ud.splashScreen.empty()) - App::Application::Config()["SplashPicture"] = ud.splashScreen; + Branding::XmlConfig cfg = brand.getUserDefines(); + for (Branding::XmlConfig::iterator it = cfg.begin(); it != cfg.end(); ++it) { + App::Application::Config()[it->first] = it->second; + } } // Run phase =========================================================== diff --git a/src/Main/res/branding.xml b/src/Main/res/branding.xml new file mode 100644 index 000000000..2e9549248 --- /dev/null +++ b/src/Main/res/branding.xml @@ -0,0 +1,23 @@ + + + + + Application + 1 + 0 + 2000 + My Application with some text + My copyright notice + http://www.something.com + PartWorkbench + + diff --git a/src/Mod/MeshPart/Gui/PreCompiled.h b/src/Mod/MeshPart/Gui/PreCompiled.h index ed7943a8c..0966f935c 100644 --- a/src/Mod/MeshPart/Gui/PreCompiled.h +++ b/src/Mod/MeshPart/Gui/PreCompiled.h @@ -28,15 +28,21 @@ // Importing of App classes #ifdef FC_OS_WIN32 -# define PartExport __declspec(dllimport) +# define MeshExport __declspec(dllimport) +# define PartExport __declspec(dllimport) # define MeshPartAppExport __declspec(dllimport) # define MeshPartGuiExport __declspec(dllexport) #else // for Linux +# define MeshExport # define PartExport # define MeshPartAppExport # define MeshPartGuiExport #endif +#ifdef _MSC_VER +# pragma warning(disable : 4290) +# pragma warning(disable : 4275) +#endif #ifdef _PreComp_