Skip to content

Commit

Permalink
Merge pull request #388 from ra3xdh/window-title
Browse files Browse the repository at this point in the history
Window title (part I)
  • Loading branch information
ra3xdh authored Nov 29, 2023
2 parents e58bc3e + fa9698c commit 164107a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ file (STRINGS "${qucs-suite_SOURCE_DIR}/VERSION" QUCS_VERSION)
message(STATUS "Configuring Qucs: VERSION ${QUCS_VERSION}")

set(GIT unknown)
if(EXISTS ${CMAKE_SOURCE_DIR}/../.git )
if(EXISTS ${CMAKE_SOURCE_DIR}/.git )
find_package(Git)
# Get the latest abbreviated commit hash of the working branch
execute_process(
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
24.1.0
26 changes: 13 additions & 13 deletions qucs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ set(PROJECT_DOMAIN_FIRST "qucs")
set(PROJECT_DOMAIN_SECOND "org")

# If Git hash not defined, try to define it
IF(NOT GIT)
IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../.git )
FIND_PACKAGE(Git)
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND ${GIT_EXECUTABLE} log --pretty=format:%h -n 1u
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
)
set(GIT ${GIT_COMMIT_HASH})
message(STATUS "Found Git repository, last commit hash: ${GIT}")
ENDIF()
ENDIF()
#IF(NOT GIT)
# IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../../.git )
# FIND_PACKAGE(Git)
# # Get the latest abbreviated commit hash of the working branch
# execute_process(
# COMMAND ${GIT_EXECUTABLE} log --pretty=format:%h -n 1u
# WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
# OUTPUT_VARIABLE GIT_COMMIT_HASH
# )
# set(GIT ${GIT_COMMIT_HASH})
# message(STATUS "Found Git repository, last commit hash: ${GIT}")
# ENDIF()
#ENDIF()

if(UNIX AND NOT APPLE)
#string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWERCASE)
Expand Down
2 changes: 1 addition & 1 deletion qucs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ int main(int argc, char *argv[])
}
else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) {
#ifdef GIT
fprintf(stdout, "Qucs " PACKAGE_VERSION " (" GIT ")" "\n");
fprintf(stdout, "qucs s" PACKAGE_VERSION " (" GIT ")" "\n");
#else
fprintf(stdout, "Qucs " PACKAGE_VERSION "\n");
#endif
Expand Down
17 changes: 17 additions & 0 deletions qucs/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@
#include <QtWidgets>


QString misc::getWindowTitle()
{
QString title = QUCS_NAME " " PACKAGE_VERSION;
if (title.endsWith(".0")) {
title.chop(2);
}
#if defined(GIT)
QString hash = GIT;
if (hash != "unknown") {
title = title + "-" + hash;
}
#endif

return title;
}


bool misc::isDarkTheme()
{
QLabel *lbl = new QLabel("check dark");
Expand Down
1 change: 1 addition & 0 deletions qucs/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace misc {
QStringList parseCmdArgs(const QString &program);
QString getIconPath(const QString &file, int icon_type);
bool isDarkTheme();
QString getWindowTitle();
QString wildcardToRegularExpression(const QString &wc_str, const bool enableEscaping);

bool simulatorExists(const QString &exe_file);
Expand Down
20 changes: 17 additions & 3 deletions qucs/qucs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ QucsApp::QucsApp()
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
#endif

setWindowTitle(QUCS_NAME " " PACKAGE_VERSION);
windowTitle = misc::getWindowTitle();
setWindowTitle(windowTitle);

QucsSettings.hasDarkTheme = misc::isDarkTheme();

Expand Down Expand Up @@ -1422,7 +1423,7 @@ void QucsApp::openProject(const QString& Path)
QDir parentDir = QucsSettings.QucsWorkDir;
parentDir.cdUp();
// show name in title of main window
setWindowTitle(QUCS_NAME " " PACKAGE_VERSION " - " + tr("Project: ") + ProjName + " (" + parentDir.absolutePath() + ")");
setWindowTitle( tr("Project: ") + ProjName + " (" + parentDir.absolutePath() + ") - " + windowTitle);
}

// ----------------------------------------------------------
Expand Down Expand Up @@ -1482,7 +1483,7 @@ void QucsApp::slotMenuProjClose()
view->drawn = false;

slotResetWarnings();
setWindowTitle(QUCS_NAME " " PACKAGE_VERSION " - " + tr("No project"));
setWindowTitle(windowTitle);
QucsSettings.QucsWorkDir.setPath(QDir::homePath()+QDir::toNativeSeparators ("/.qucs"));
octave->adjustDirectory();

Expand Down Expand Up @@ -2003,6 +2004,19 @@ void QucsApp::slotChangeView()
}

Doc->becomeCurrent(true);

// TODO proper window title
// QFileInfo Info (Doc-> DocName);
//
// if (!ProjName.isEmpty()) {
// QDir parentDir = QucsSettings.QucsWorkDir;
// parentDir.cdUp();
// setWindowTitle(tr("Project: ") + ProjName + " (" + parentDir.absolutePath() + ") "
// + windowTitle);
// } else {
// setWindowTitle(Info.fileName() + " (" + Info.filePath() +") - " + windowTitle);
// }

view->drawn = false;

HierarchyHistory.clear();
Expand Down
1 change: 1 addition & 0 deletions qucs/qucs.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ private slots:

QAction *activeAction; // pointer to the action selected by the user
bool TuningMode;
QString windowTitle;

private:
// ********* Widgets on the main area **********************************
Expand Down

0 comments on commit 164107a

Please sign in to comment.