Merge pull request #45 from RigoLigoRLC/MacHack

WIP:添加MacOS支持,顺便对不同平台设置默认界面字体
This commit is contained in:
Roy Qu 2022-05-30 18:16:27 +08:00 committed by GitHub
commit 10fb1d5c17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 104 additions and 9 deletions

View File

@ -13,7 +13,15 @@ isEmpty(APP_VERSION) {
APP_VERSION=1.1.0
}
macos: {
# This package needs to be installed via homebrew before we can compile it
INCLUDEPATH += \
/opt/homebrew/opt/icu4c/include
QT += gui-private
ICON = ../macos/RedPandaIDE.icns
}
win32: VERSION = $${APP_VERSION}.0
else: VERSION = $${APP_VERSION}
@ -32,7 +40,7 @@ gcc {
}
msvc {
DEFINES += NOMINMAX
DEFINES += NOMINMAX
}
# You can make your code fail to compile if it uses deprecated APIs.
@ -424,6 +432,7 @@ unix: {
settingsdialog/formatterpathwidget.ui \
settingsdialog/environmentprogramswidget.ui
}
linux: {
LIBS+= \
-lrt
@ -494,3 +503,16 @@ RESOURCES += qmake_qm_files
RESOURCES += iconsets_files
RESOURCES += theme_files
RESOURCES += colorscheme_files
macos: {
# Add needed executables into the main app bundle
bundled_executable.files = \
$$OUT_PWD/../astyle/astyle \
$$OUT_PWD/../consolepauser/consolepauser \
$$OUT_PWD/../redpanda-git-askpass/redpanda-git-askpass.app/Contents/MacOS/redpanda-git-askpass
bundled_executable.path = Contents/MacOS
# Also bundled templates
QMAKE_BUNDLE_DATA += bundled_executable
}

View File

@ -54,6 +54,8 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent),
mFontDummy = QFont("Consolas",12);
#elif defined(Q_OS_LINUX)
mFontDummy = QFont("terminal",14);
#elif defined(Q_OS_MACOS)
mFontDummy = QFont("Menlo", 14);
#else
#error "Not supported!"
#endif

View File

@ -190,15 +190,21 @@ QString Settings::Dirs::appResourceDir() const
return appDir();
#elif defined(Q_OS_LINUX)
return includeTrailingPathDelimiter(PREFIX)+"share/"+APP_NAME;
#elif defined(Q_OS_MACOS)
// return QApplication::instance()->applicationDirPath();
return "";
#endif
}
QString Settings::Dirs::appLibexecDir() const
{
#ifdef Q_OS_WIN
return appDir();
#elif defined(Q_OS_LINUX)
return includeTrailingPathDelimiter(PREFIX)+"libexec/"+APP_NAME;
#elif defined(Q_OS_MACOS)
return QApplication::instance()->applicationDirPath();
#endif
}
@ -1274,10 +1280,13 @@ void Settings::Editor::doLoad()
mRightEdgeWidth = intValue("right_edge_width",80);
mRightEdgeLineColor = colorValue("right_edge_line_color",Qt::yellow);
//Font
//Editor font
#ifdef Q_OS_WIN
mFontName = stringValue("font_name","consolas");
mNonAsciiFontName = stringValue("non_ascii_font_name","consolas");
#elif defined(Q_OS_MACOS)
mFontName = stringValue("font_name","Menlo");
mNonAsciiFontName = stringValue("non_ascii_font_name","PingFang SC");
#else
mFontName = stringValue("font_name","Dejavu Sans Mono");
mNonAsciiFontName = stringValue("non_ascii_font_name","Dejavu Sans Mono");
@ -2845,7 +2854,13 @@ void Settings::Environment::doLoad()
QString defaultLocaleName = QLocale::system().name();
if (defaultLocaleName == "zh_CN") {
QString fontName;
#ifdef Q_OS_WINDOWS
fontName = "Microsoft Yahei";
#elif defined(Q_OS_MACOS)
fontName = "PingFang SC";
#elif defined(Q_OS_LINUX)
fontName = "Noto Sans CJK";
#endif
QFont font(fontName);
if (font.exactMatch()) {
defaultFontName = fontName;
@ -2874,6 +2889,10 @@ void Settings::Environment::doLoad()
if (mTerminalPath.isEmpty())
mTerminalPath = stringValue("terminal_path","/usr/bin/x-terminal-emulator");
mAStylePath = includeTrailingPathDelimiter(pSettings->dirs().appLibexecDir())+"astyle";
#elif defined(Q_OS_MACOS)
mTerminalPath = stringValue("terminal_path",
"/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal");
mAStylePath = includeTrailingPathDelimiter(pSettings->dirs().appLibexecDir())+"astyle";
#endif
mHideNonSupportFilesInFileView=boolValue("hide_non_support_files_file_view",true);
mOpenFilesInSingleInstance = boolValue("open_files_in_single_instance",false);
@ -3222,6 +3241,8 @@ void Settings::Executor::doLoad()
mIgnoreSpacesWhenValidatingCases = boolValue("ignore_spaces_when_validating_cases",false);
#ifdef Q_OS_WIN
mCaseEditorFontName = stringValue("case_editor_font_name","consolas");
#elif defined(Q_OS_MACOS)
mCaseEditorFontName = stringValue("case_editor_font_name", "Menlo");
#else
mCaseEditorFontName = stringValue("case_editor_font_name","Dejavu Sans Mono");
#endif

View File

@ -50,6 +50,21 @@
#define CLANG_PROGRAM "clang"
#define CLANG_CPP_PROGRAM "clang++"
#define LLDB_MI_PROGRAM "lldb-mi"
#elif defined(Q_OS_MACOS)
#define GCC_PROGRAM "gcc"
#define GPP_PROGRAM "g++"
#define GDB_PROGRAM "gdb"
#define GDB_SERVER_PROGRAM "gdbserver"
#define GDB32_PROGRAM "gdb32"
#define MAKE_PROGRAM "make"
#define WINDRES_PROGRAM ""
#define GPROF_PROGRAM "gprof"
#define CLEAN_PROGRAM "rm -rf"
#define CPP_PROGRAM "cpp"
#define GIT_PROGRAM "git"
#define CLANG_PROGRAM "clang"
#define CLANG_CPP_PROGRAM "clang++"
#define LLDB_MI_PROGRAM "lldb-mi"
#else
#error "Only support windows and linux now!"
#endif
@ -85,7 +100,7 @@
# define DYNAMIC_LIB_EXT "dll"
# define MAKEFILE_NAME "makefile.win"
# define ALL_FILE_WILDCARD "*.*"
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) || defined(Q_OS_MACOS)
# define PATH_SENSITIVITY Qt::CaseSensitive
# define PATH_SEPARATOR ":"
# define LINE_BREAKER "\n"

View File

@ -27,6 +27,11 @@
#include <QSvgRenderer>
#include "../settings.h"
#if defined(Q_OS_MACX)
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformtheme.h>
#endif
#define BEGIN_STYLE_PIXMAPCACHE(a) \
QRect rect = option->rect; \
QPixmap internalPixmapCache; \

View File

@ -5,14 +5,20 @@ SUBDIRS += \
astyle \
consolepauser
# Add the dependencies so that the RedPandaIDE project can add the depended programs
# into the main app bundle
RedPandaIDE.depends = astyle consolepauser
win32: {
SUBDIRS += \
redpanda-win-git-askpass
RedPandaIDE.depends += redpanda-win-git-askpass
}
linux: {
unix: {
SUBDIRS += \
redpanda-git-askpass
RedPandaIDE.depends += redpanda-git-askpass
}
APP_NAME = RedPandaCPP
@ -20,7 +26,6 @@ APP_NAME = RedPandaCPP
APP_VERSION = 1.1.0
linux: {
isEmpty(PREFIX) {
PREFIX = /usr/local
}
@ -44,7 +49,6 @@ linux: {
desktop.path = $${PREFIX}/share/applications
desktop.files += linux/redpandaide.desktop
INSTALLS += desktop
}
win32: {

View File

@ -19,10 +19,15 @@ SOURCES += \
unix: {
SOURCES += \
main.unix.cpp
LIBS+= \
-lrt
}
# macOS does not provide rt library, only use it for Linux
linux: {
LIBS+= \
-lrt
}
CONFIG += lrelease
CONFIG += embed_translations

View File

@ -109,7 +109,9 @@ int ExecuteCommand(vector<string>& command,bool reInp) {
if (result) {
printf("Failed to start command %s %s!\n",path_to_command.c_str(), file.c_str());
printf("errno %d: %s\n",errno,strerror(errno));
printf("current dir: %s",get_current_dir_name());
char* current_dir = getcwd(nullptr, 0);
printf("current dir: %s",current_dir);
free(current_dir);
exit(-1);
}
} else {

BIN
macos/RedPandaIDE.icns Normal file

Binary file not shown.

19
macos/gen_macos_icns.sh Executable file
View File

@ -0,0 +1,19 @@
#!/bin/bash
input_icon="../RedPandaIDE/images/devcpp.png"
output_dir="RedPandaIDE.iconset"
mkdir $output_dir
sips -z 16 16 $input_icon --out "${output_dir}/icon_16x16.png"
sips -z 32 32 $input_icon --out "${output_dir}/icon_16x16@2x.png"
sips -z 32 32 $input_icon --out "${output_dir}/icon_32x32.png"
sips -z 64 64 $input_icon --out "${output_dir}/icon_32x32@2x.png"
sips -z 128 128 $input_icon --out "${output_dir}/icon_128x128.png"
sips -z 256 256 $input_icon --out "${output_dir}/icon_128x128@2x.png"
sips -z 256 256 $input_icon --out "${output_dir}/icon_256x256.png"
sips -z 512 512 $input_icon --out "${output_dir}/icon_256x256@2x.png"
iconutil -c icns $output_dir
rm -R $output_dir