Skip to content

Commit

Permalink
WIP Icons
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrePTJ committed Jul 1, 2024
1 parent a1a393c commit 5be689e
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ if (KEMAI_BUILD_LOCAL_DEPENDENCIES)
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.14.0
OVERRIDE_FIND_PACKAGE)
FetchContent_Declare(QtAwesome
GIT_REPOSITORY https://github.com/gamecreature/QtAwesome.git
GIT_TAG font-awesome-6.5.1
OVERRIDE_FIND_PACKAGE)
endif (KEMAI_BUILD_LOCAL_DEPENDENCIES)

# Find external dependencies
find_package(fmt REQUIRED)
find_package(magic_enum REQUIRED)
find_package(spdlog REQUIRED)
find_package(QtAwesome REQUIRED)
find_package(Qt6 QUIET COMPONENTS Widgets Network LinguistTools)

# Write version to file to ease packaging
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(SRCS
gui/timeSheetParamsItemDelegate.cpp
main.cpp
misc/dataReader.cpp
misc/fontAwesomeHolder.cpp
misc/helpers.cpp
models/loggerTreeModel.cpp
models/taskFilterProxyModel.cpp
Expand Down Expand Up @@ -61,6 +62,7 @@ set(HDRS
gui/timeSheetParamsItemDelegate.h
misc/customFmt.h
misc/dataReader.h
misc/fontAwesomeHolder.h
misc/helpers.h
models/loggerTreeModel.h
models/taskFilterProxyModel.h
Expand Down Expand Up @@ -136,7 +138,7 @@ qt_add_translations(

target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Widgets Qt::Network spdlog::spdlog magic_enum::magic_enum ${KEMAI_ADDITIONAL_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Widgets Qt::Network QtAwesome spdlog::spdlog magic_enum::magic_enum ${KEMAI_ADDITIONAL_LIBS})

# Install configuration
install(TARGETS ${PROJECT_NAME}
Expand Down
8 changes: 6 additions & 2 deletions src/gui/activityWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <spdlog/spdlog.h>

#include "misc/customFmt.h"
#include "misc/fontAwesomeHolder.h"
#include "misc/helpers.h"
#include "timeSheetItemDelegate.h"
#include "timeSheetListWidgetItem.h"
Expand All @@ -16,6 +17,9 @@ static const auto gDefaultDurationText = "--:--:--";
ActivityWidget::ActivityWidget(QWidget* parent) : QWidget(parent), mUi(std::make_unique<Ui::ActivityWidget>())
{
mUi->setupUi(this);

mUi->btEditTimeSheet->setIcon(FontAwesomeHolder::get()->icon(fa::fa_regular, fa::fa_square_pen));

mUi->lbDurationTime->setText(gDefaultDurationText);

mUi->cbTimeSheetParams->setModel(&mTimeSheetParamsModel);
Expand Down Expand Up @@ -194,11 +198,11 @@ void ActivityWidget::updateControls()

if (mSession->hasCurrentTimeSheet())
{
mUi->btStartStop->setIcon(QIcon(":/icons/stop"));
mUi->btStartStop->setIcon(QIcon(":/icons/kimai-stop"));
}
else
{
mUi->btStartStop->setIcon(QIcon(":/icons/play"));
mUi->btStartStop->setIcon(QIcon(":/icons/kimai-play"));
mUi->lbDurationTime->setText(gDefaultDurationText);
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/gui/activityWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="btEditTimeSheet">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
Expand All @@ -91,10 +91,6 @@
<height>32</height>
</size>
</property>
<property name="icon">
<iconset resource="../resources/kemai.qrc">
<normaloff>:/icons/update</normaloff>:/icons/update</iconset>
</property>
<property name="iconSize">
<size>
<width>30</width>
Expand Down
9 changes: 5 additions & 4 deletions src/gui/settingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "client/kimaiFeatures.h"
#include "kemaiConfig.h"
#include "misc/fontAwesomeHolder.h"

using namespace kemai;

Expand All @@ -19,12 +20,12 @@ static void toggleLineEditEchoMode(QLineEdit* lineEdit, QAction* action)
if (lineEdit->echoMode() == QLineEdit::Password)
{
lineEdit->setEchoMode(QLineEdit::Normal);
action->setIcon(QIcon(":/icons/visible"));
action->setIcon(FontAwesomeHolder::get()->icon(fa::fa_regular, fa::fa_eye));
}
else
{
lineEdit->setEchoMode(QLineEdit::Password);
action->setIcon(QIcon(":/icons/visible-off"));
action->setIcon(FontAwesomeHolder::get()->icon(fa::fa_regular, fa::fa_eye_slash));
}
}

Expand All @@ -43,8 +44,8 @@ SettingsDialog::SettingsDialog(const std::shared_ptr<DesktopEventsMonitor>& desk
cbLanguage->addItem(QString("%1 [%2]").arg(QLocale::languageToString(locale.language()), QLocale::territoryToString(locale.territory())), locale);
};

mActToggleTokenVisible = mUi->leToken->addAction(QIcon(":/icons/visible-off"), QLineEdit::TrailingPosition);
mActToggleAPITokenVisible = mUi->leAPIToken->addAction(QIcon(":/icons/visible-off"), QLineEdit::TrailingPosition);
mActToggleTokenVisible = mUi->leToken->addAction(FontAwesomeHolder::get()->icon(fa::fa_regular, fa::fa_eye_slash), QLineEdit::TrailingPosition);
mActToggleAPITokenVisible = mUi->leAPIToken->addAction(FontAwesomeHolder::get()->icon(fa::fa_regular, fa::fa_eye_slash), QLineEdit::TrailingPosition);

// Add default en_US language
addLanguage("en_US");
Expand Down
20 changes: 14 additions & 6 deletions src/gui/timeSheetItemDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QPalette>
#include <QStyle>

#include "misc/fontAwesomeHolder.h"
#include "models/timeSheetModel.h"

using namespace kemai;
Expand All @@ -14,6 +15,7 @@ static const auto gTextSpacing = 2;
static const auto gTextLeftOffset = gIndicatorWidth + gTextSpacing;
static const auto gPadding = 4;
static const auto gButtonWidth = 64;
static const auto gButtonIconSide = 24;

// gIndicatorWidth + gPadding (1 x blue rect + 1 x empty)
// | |
Expand Down Expand Up @@ -76,21 +78,27 @@ void TimeSheetItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem&
const auto buttonY = option.rect.top() + gPadding;
const auto buttonH = option.rect.height() - 2 * gPadding;

QVariantMap fontAwesomeOptions;
if (isHover)
{
fontAwesomeOptions.insert("color-disabled", QColor::fromString("#009d39"));
}

// Reload button
QStyleOptionButton reloadButtonOption;
reloadButtonOption.features = QStyleOptionButton::Flat;
reloadButtonOption.text = "Reload";
reloadButtonOption.state = QStyle::State_Sunken;
reloadButtonOption.icon = FontAwesomeHolder::get()->icon(fa::fa_solid, fa::fa_play, fontAwesomeOptions);
reloadButtonOption.iconSize = {gButtonIconSide, gButtonIconSide};
reloadButtonOption.rect = QRect(option.rect.right() - 3 * gPadding - 2 * gButtonWidth, buttonY, gButtonWidth, buttonH);

qApp->style()->drawControl(QStyle::CE_PushButton, &reloadButtonOption, painter);

// Restart button
QStyleOptionButton restartButtonOption;
// buttonOption.features = QStyleOptionButton::DefaultButton;
restartButtonOption.text = "Restart";
restartButtonOption.state = QStyle::State_Sunken;
restartButtonOption.rect = QRect(option.rect.right() - gPadding - gButtonWidth, buttonY, gButtonWidth, buttonH);
restartButtonOption.features = QStyleOptionButton::Flat;
restartButtonOption.icon = FontAwesomeHolder::get()->icon(fa::fa_solid, fa::fa_rotate_right, fontAwesomeOptions);
restartButtonOption.iconSize = {gButtonIconSide, gButtonIconSide};
restartButtonOption.rect = QRect(option.rect.right() - gPadding - gButtonWidth, buttonY, gButtonWidth, buttonH);

qApp->style()->drawControl(QStyle::CE_PushButton, &restartButtonOption, painter);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "gui/mainWindow.h"
#include "kemaiConfig.h"
#include "misc/customFmt.h"
#include "misc/fontAwesomeHolder.h"
#include "misc/helpers.h"
#include "models/loggerTreeModel.h"
#include "settings/settings.h"
Expand Down Expand Up @@ -89,6 +90,9 @@ int main(int argc, char* argv[])
// Setup trusted certificates
KimaiClient::addTrustedCertificates(kemaiSettings.trustedCertificates);

// Init QtAwesome
FontAwesomeHolder::get()->initFontAwesome();

// Startup
MainWindow mainWindow;
mainWindow.restoreGeometry(kemaiSettings.kemai.geometry);
Expand Down
11 changes: 11 additions & 0 deletions src/misc/fontAwesomeHolder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "fontAwesomeHolder.h"

#include <memory>

using namespace kemai;

fa::QtAwesome* FontAwesomeHolder::get()
{
static std::unique_ptr<fa::QtAwesome> _instance = std::make_unique<fa::QtAwesome>();
return _instance.get();
}
11 changes: 11 additions & 0 deletions src/misc/fontAwesomeHolder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <QtAwesome.h>

namespace kemai {
class FontAwesomeHolder
{
public:
static fa::QtAwesome* get();
};
} // namespace kemai
54 changes: 54 additions & 0 deletions src/resources/icons/kimai-stop.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 54 additions & 1 deletion src/resources/icons/kimai.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/resources/icons/visibility-off.svg

This file was deleted.

Loading

0 comments on commit 5be689e

Please sign in to comment.