Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SVG icons #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ proceed as follows:
copy lib\QtNetwork4.* C:\Qt-4.8.7\lib
copy lib\QtOpenGL4.* C:\Qt-4.8.7\lib
copy lib\QtSql4.* C:\Qt-4.8.7\lib
copy lib\QtSvg4.* C:\Qt-4.8.7\lib
copy lib\QtXml4.* C:\Qt-4.8.7\lib

- Install the Qt header files required for building FEDEM.
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ add_subdirectory ( src )

# Install some resource files

file ( GLOB RESOURCES resources/*.* )
file ( GLOB RESOURCES resources/*.f* )
if ( FTENV_VERBOSE )
message ( STATUS "Installing ${RESOURCES} to ${CMAKE_INSTALL_PREFIX}" )
endif ( FTENV_VERBOSE )
Expand Down
7 changes: 7 additions & 0 deletions resources/fedem_icons.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
<file alias="open.svg">icons/open-open-a-file-svgrepo-com.svg</file>
<file alias="save.svg">icons/save-save-the-document-svgrepo-com.svg</file>
</qresource>
</RCC>
3 changes: 3 additions & 0 deletions resources/icons/open-open-a-file-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/icons/save-save-the-document-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ if ( WIN )
endif ( USE_COMAPI )

# Resource file for the executable
set ( APP_ICON "vpmUI/Icons/win32AppIcon/fedem_app_icon.rc" )
set ( RESOURCES vpmUI/Icons/win32AppIcon/fedem_app_icon.rc )
endif ( WIN )

set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX_FLAGS}" CACHE STRING "Flags needed by the C++ compiler" FORCE )
Expand Down Expand Up @@ -132,9 +132,21 @@ if ( Coin_library )
endif ( Coin_library )
list ( APPEND DEPENDENCY_LIST vpmDB FiUserElmPlugin FFaOperation )

# Main program source file(s)
file ( GLOB CPP_SOURCE_FILES *.C )

# Target Qt4::rcc is defined in FindQt4.cmake but is not propagated to here
if ( NOT TARGET Qt4::rcc AND QT_RCC_EXECUTABLE )
add_executable ( Qt4::rcc IMPORTED )
set_property ( TARGET Qt4::rcc PROPERTY IMPORTED_LOCATION ${QT_RCC_EXECUTABLE} )
endif ( NOT TARGET Qt4::rcc AND QT_RCC_EXECUTABLE )

# Add resource file for toolbar and menu icons
qt4_add_resources ( RESOURCES ../resources/fedem_icons.qrc )

message ( STATUS "Building executable Fedem" )
string ( APPEND CMAKE_CXX_FLAGS " -DFT_USE_CONNECTORS" )
add_executable ( Fedem WIN32 vpm_main.C vpm_main_init.C ${COM_FILES} ${APP_ICON} )
add_executable ( Fedem WIN32 ${CPP_SOURCE_FILES} ${COM_FILES} ${RESOURCES} )
target_link_libraries ( Fedem ${DEPENDENCY_LIST} )

#
Expand Down
89 changes: 36 additions & 53 deletions src/FFuLib/FFuAuxClasses/FFuaCmdItem.C
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <fstream>


FFuaCmdItem::CommandMap* FFuaCmdItem::cmdItemMap = 0;
std::map<std::string,FFuaCmdItem*>* FFuaCmdItem::cmdItemMap = NULL;
bool FFuaCmdItem::weAreLoggingCmds = false;

//--------------------------------------------------------------------
Expand All @@ -21,11 +21,10 @@ void FFuaCmdItem::printCmdListToFile()
if (!cmdItemMap) return;

std::ofstream liste("FedemCmdList.txt");
CommandMap::const_iterator it;
for (it = cmdItemMap->begin(); it != cmdItemMap->end(); it++)
liste << "@" << it->first
<< "$" << it->second->getText()
<< "$" << it->second->getToolTip() << std::endl;
for (const std::pair<const std::string,FFuaCmdItem*>& cmd : *cmdItemMap)
liste <<"@"<< cmd.first
<<"$"<< cmd.second->getText()
<<"$"<< cmd.second->getToolTip() << std::endl;
}
//--------------------------------------------------------------------

Expand All @@ -50,82 +49,66 @@ void FFuaCmdItem::invokeToggledCB(bool toggle)
void FFuaCmdItem::init()
{
if (!cmdItemMap)
cmdItemMap = new CommandMap();
cmdItemMap = new std::map<std::string,FFuaCmdItem*>();
}
//----------------------------------------------------------------------------

FFuaCmdItem* FFuaCmdItem::getCmdItem(const std::string& itemId)
FFuaCmdItem* FFuaCmdItem::getCmdItem(const std::string& id)
{
if (itemId.empty() || !cmdItemMap) return 0;
if (!cmdItemMap || id.empty())
return NULL;

CommandMap::iterator it = cmdItemMap->find(itemId);
if (it != FFuaCmdItem::cmdItemMap->end())
std::map<std::string,FFuaCmdItem*>::iterator it = cmdItemMap->find(id);
if (it != cmdItemMap->end())
return it->second;

std::cerr <<"ERROR FFuaCmdItem: \""<< itemId <<"\" does not exist"
<< std::endl;
return 0;
std::cerr <<" *** FFuaCmdItem: \""<< id <<"\" does not exist"<< std::endl;
return NULL;
}
//----------------------------------------------------------------------------

FFuaCmdItem::FFuaCmdItem(const std::string& itemId)
FFuaCmdItem::FFuaCmdItem(const std::string& id) : cmdItemId(id)
{
this->initVars();
this->cmdItemId = itemId;
if (itemId.empty() || !cmdItemMap) return;

CommandMap::iterator it = FFuaCmdItem::cmdItemMap->find(itemId);
if (it != FFuaCmdItem::cmdItemMap->end()) {
std::cerr <<"ERROR FFuaCmdItem: \""<< itemId <<"\" already exists"
<< std::endl;
*(char*)0 = 'd'; // To make core
this->svgIcon = NULL;
this->smallIcon = NULL;
this->pixmap = NULL;
this->accelKey = 0;
this->toggleAble = false;
this->behaveAsRadio = false;
this->toggled = false;
this->menuButtonPopupMode = false;
if (!cmdItemMap || id.empty()) return;

if (cmdItemMap->find(id) == cmdItemMap->end())
(*cmdItemMap)[id] = this; // unique id
else
{
std::cerr <<" *** FFuaCmdItem: \""<< id <<"\" already exists"<< std::endl;
abort();
}
else // unique id
(*cmdItemMap)[itemId] = this;
}
//----------------------------------------------------------------------------

FFuaCmdItem::~FFuaCmdItem()
{
if (!this->cmdItemId.empty() && cmdItemMap) // subject to static management
cmdItemMap->erase(this->cmdItemId);
}
//----------------------------------------------------------------------------

void FFuaCmdItem::initVars()
{
this->bigIcon = 0;
this->smallIcon = 0;
this->pixmap = 0;
this->accelKey = 0;
this->toggleAble = false;
this->behaveAsRadio = false;
this->toggled = false;
this->menuButtonPopupMode = false;
if (cmdItemMap && !cmdItemId.empty()) // subject to static management
cmdItemMap->erase(cmdItemId);
}
//----------------------------------------------------------------------------

bool FFuaCmdItem::getSensitivity()
{
bool sensitivity = true;
this->invokeGetSensitivityCB(sensitivity);
this->getSensitivityCB.invoke(sensitivity);
return sensitivity;
}
//----------------------------------------------------------------------------

bool FFuaCmdItem::getToggled()
{
if (this->getToggledCB.empty())
return this->toggled;

bool toggle;
this->invokeGetToggledCB(toggle);
bool toggle = this->toggled;
if (!this->getToggledCB.empty())
this->getToggledCB.invoke(toggle);
return toggle;
}
//----------------------------------------------------------------------------

FFuaCmdHeaderItem::FFuaCmdHeaderItem(const std::string& txt) : FFuaCmdItem()
{
this->setText(txt);
}
//----------------------------------------------------------------------------
45 changes: 16 additions & 29 deletions src/FFuLib/FFuAuxClasses/FFuaCmdItem.H
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,22 @@

class FFuaCmdItem
{
static void printCmdListToFile();

public:
// FFaInitializer init - used for the cmdItemMap;
static void init();

static void enableCmdLogging(bool doEnable) { weAreLoggingCmds = doEnable; }
static FFuaCmdItem* getCmdItem(const std::string& cmdItemId);

// A FFuaCmdItem subject to static management must have a cmdItemId string
// otherwise it escapes the static management
FFuaCmdItem(const std::string& cmdItemId = "");

// A FFuaCmdItem must not be deleted as long as it is in use
virtual ~FFuaCmdItem();

static FFuaCmdItem* getCmdItem(const std::string& cmdItemId);
static void enableCmdLogging(bool doEnable) { weAreLoggingCmds = doEnable; }

const std::string& getCmdItemId() const { return this->cmdItemId; }

// callbacks
Expand All @@ -38,7 +43,7 @@ public:
this->setToggleAble(false);
this->activatedCB = dynCB;
}
void invokeActivatedCB() ;
void invokeActivatedCB();
void setToggledCB(const FFaDynCB1<bool>& dynCB) {
this->setToggleAble(true);
this->toggledCB = dynCB;
Expand All @@ -50,28 +55,14 @@ public:
// You should set this cb if possible, ie if the db stores the toggle statuses
void setGetToggledCB(const FFaDynCB1<bool&>& dynCB) {this->getToggledCB = dynCB;}

private:
void invokeGetSensitivityCB(bool& sensitivity)
{this->getSensitivityCB.invoke(sensitivity);}
void invokeGetToggledCB(bool& toggle)
{this->getToggledCB.invoke(toggle);}

static void printCmdListToFile();

void initVars();

public:
// item attributes
// icons are used in front of popupmenu text entries and on toolbuttons
// small should be < 23 pix
// popupmenues do always require a small icon, if not it a bigone is scaled
void setBigIcon(const char** pixMap) { this->bigIcon = pixMap; }
const char** getBigIcon() const { return this->bigIcon; }
void setSvgIcon(const char* svgFile) { this->svgIcon = svgFile; }
const char* getSvgIcon() const { return this->svgIcon; }

void setSmallIcon(const char** pixMap) { this->smallIcon = pixMap; }
const char** getSmallIcon() const { return this->smallIcon; }

bool hasIcon() const { return this->bigIcon || this->smallIcon; }
bool hasIcon() const { return this->svgIcon || this->smallIcon; }

// pixmaps are used as a substitute for the text on popupmenu entries
void setPixmap(const char** pixMap) { this->pixmap = pixMap; }
Expand All @@ -88,6 +79,7 @@ public:
int getAccelKey() const { return this->accelKey; }

bool getSensitivity();

// toggle
void setToggleAble(bool toggleable) { this->toggleAble = toggleable; }
bool getToggleAble() const { return this->toggleAble; }
Expand All @@ -107,13 +99,8 @@ public:
void setMenuButtonPopupMode(bool val) { this->menuButtonPopupMode = val; }
bool getMenuButtonPopupMode() const { return this->menuButtonPopupMode; }

// FFaInitializer init - used for the cmdItemMap;
static void init();

private:
typedef std::map<std::string,FFuaCmdItem*> CommandMap;

static CommandMap* cmdItemMap;
static std::map<std::string,FFuaCmdItem*>* cmdItemMap;
static bool weAreLoggingCmds;

std::string cmdItemId;
Expand All @@ -123,7 +110,7 @@ private:
FFaDynCB1<bool&> getSensitivityCB;
FFaDynCB1<bool&> getToggledCB;

const char** bigIcon;
const char* svgIcon;
const char** smallIcon;
const char** pixmap;
std::string text;
Expand All @@ -140,7 +127,7 @@ class FFuaCmdHeaderItem : public FFuaCmdItem
{
public:
// A FFuaCmdHeaderItem is NOT book-kept (in static management)
FFuaCmdHeaderItem(const std::string& text = "");
FFuaCmdHeaderItem(const std::string& text = "") { this->setText(text); }
// A FFuaCmdHeaderItem can be deleted even if it is used
virtual ~FFuaCmdHeaderItem() {}

Expand Down
7 changes: 2 additions & 5 deletions src/FFuLib/FFuQtComponents/FFuQtPopUpMenu.C
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ int FFuQtPopUpMenu::basicNewItem(FFuaCmdItem* item, FFuPopUpMenu* menu)
{
// px + text
QIcon* ic;
if (item->getBigIcon()) {
ic = new QIcon(FFuaQtPixmapCache::getPixmap(item->getBigIcon()));
if (item->getSmallIcon())
ic->addPixmap(FFuaQtPixmapCache::getPixmap(item->getSmallIcon()));
}
if (item->getSvgIcon())
ic = new QIcon(item->getSvgIcon());
else if (item->getSmallIcon())
ic = new QIcon(FFuaQtPixmapCache::getPixmap(item->getSmallIcon()));
else
Expand Down
18 changes: 4 additions & 14 deletions src/FFuLib/FFuQtComponents/FFuQtToolButton.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// This file is part of FEDEM - https://openfedem.org
////////////////////////////////////////////////////////////////////////////////

#include <QPixmap>

#include "FFuLib/FFuAuxClasses/FFuQtAuxClasses/FFuaQtPixmapCache.H"
#include "FFuLib/FFuAuxClasses/FFuaCmdItem.H"
#include "FFaLib/FFaDynCalls/FFaDynCB.H"
Expand Down Expand Up @@ -76,18 +74,10 @@ void FFuQtToolButton::setActiveCmdItem(FFuaCmdItem* cmd)
{
this->activeCmdItem = cmd;

if (cmd->getBigIcon()) {
QIcon ic(FFuaQtPixmapCache::getPixmap(cmd->getBigIcon()));
if (cmd->getSmallIcon())
ic.addPixmap(FFuaQtPixmapCache::getPixmap(cmd->getSmallIcon()));
this->setIcon(ic);
}
else if (cmd->getSmallIcon()) {
QIcon ic(FFuaQtPixmapCache::getPixmap(cmd->getSmallIcon()));
if (cmd->getBigIcon())
ic.addPixmap(FFuaQtPixmapCache::getPixmap(cmd->getBigIcon()));
this->setIcon(ic);
}
if (cmd->getSvgIcon())
this->setIcon(QIcon(cmd->getSvgIcon()));
else if (cmd->getSmallIcon())
this->setIcon(QIcon(FFuaQtPixmapCache::getPixmap(cmd->getSmallIcon())));
else
this->setIcon(QIcon());

Expand Down
4 changes: 2 additions & 2 deletions src/vpmApp/vpmAppCmds/FapFileCmds.C
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ void FapFileCmds::init()
cmdItem->setGetSensitivityCB(FFaDynCB1S(FapFileCmds::getChangeModelSensitivity,bool&));

cmdItem = new FFuaCmdItem("cmdId_file_open");
cmdItem->setSmallIcon(open_xpm);
cmdItem->setSvgIcon(":/open.svg");
cmdItem->setText("Open...");
cmdItem->setToolTip("Open");
cmdItem->setAccelKey(FFuaKeyCode::CtrlAccel+FFuaKeyCode::O);
cmdItem->setActivatedCB(FFaDynCB0S(FapFileCmds::open));
cmdItem->setGetSensitivityCB(FFaDynCB1S(FapFileCmds::getChangeModelSensitivity,bool&));

cmdItem = new FFuaCmdItem("cmdId_file_save");
cmdItem->setSmallIcon(save_xpm);
cmdItem->setSvgIcon(":/save.svg");
cmdItem->setText("Save");
cmdItem->setToolTip("Save");
cmdItem->setAccelKey(FFuaKeyCode::CtrlAccel+FFuaKeyCode::S);
Expand Down
2 changes: 1 addition & 1 deletion src/vpmUI/vpmUITopLevels/vpmUIQtTopLevels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ target_link_libraries ( ${LIB_ID} ${DEPENDENCY_LIST} )

# Install the dependent shared object libraries

set ( QT_LIBS Qt3Support QtCore QtGui QtNetwork QtOpenGL QtSql QtXml )
set ( QT_LIBS Qt3Support QtCore QtGui QtNetwork QtOpenGL QtSql QtSvg QtXml )
foreach ( LIB ${QT_LIBS} )
get_target_property ( LIB_PATH Qt4::${LIB} LOCATION )
if ( WIN )
Expand Down