Skip to content

Commit

Permalink
use Qt version-independent macro for macOS check
Browse files Browse the repository at this point in the history
  • Loading branch information
kambala-decapitator committed May 9, 2024
1 parent 037d785 commit 90a5eec
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
7 changes: 4 additions & 3 deletions d2stringtablewidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "d2stringtablewidget.h"
#include "qtcompat.h"

#include <QProgressDialog>
#include <QKeyEvent>
Expand Down Expand Up @@ -26,15 +27,15 @@ void D2StringTableWidget::keyPressEvent(QKeyEvent *keyEvent)
{
switch (keyEvent->key())
{
#ifndef Q_OS_MAC
#ifndef OS_MACOS
case Qt::Key_Enter: // Return (usual Enter) or Enter (on the numpad)
#endif
case Qt::Key_Return: // starts editing of the current selected cell
if (state() != QAbstractItemView::EditingState)
emit itemDoubleClicked(currentItem());
break;
// in-place edit
#ifdef Q_OS_MAC
#ifdef OS_MACOS
case Qt::Key_Enter:
#endif
case Qt::Key_F2:
Expand Down Expand Up @@ -178,7 +179,7 @@ void D2StringTableWidget::changeRowHeaderDisplay()
QString rowText = QString::number(row);
if (_displayRowHex)
rowText += QString(" (0x%2)").arg(row, 0, 16);
#ifdef Q_OS_MAC
#ifdef OS_MACOS
rowText += " "; // fixes slight text truncation
#endif
rowLabels += rowText;
Expand Down
5 changes: 3 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
#include <QTranslator>

#include "qtbleditor.h"
#include "qtcompat.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setOrganizationName("kambala");
app.setApplicationName("QTblEditor");
app.setApplicationVersion("1.5");
#ifdef Q_OS_MAC
#ifdef OS_MACOS
app.setAttribute(Qt::AA_DontShowIconsInMenus);
#endif


QString locale = QLocale::system().name(), translationsPath =
#ifdef Q_OS_MAC
#ifdef OS_MACOS
qApp->applicationDirPath() + "/../Resources/" +
#endif
"Translations/" + locale;
Expand Down
14 changes: 7 additions & 7 deletions qtbleditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <QMimeData>
#include <QDateTime>

#ifdef Q_OS_MAC
#ifdef OS_MACOS
#ifdef IS_QT5
#include <QStandardPaths>
#else
Expand Down Expand Up @@ -79,7 +79,7 @@ QTblEditor::QTblEditor(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par

ui.actionRenderGreyAsWhite->setText(tr("Render %1 as white", "Arg is grey's color code").arg(colorStrings.at(2)));

#ifdef Q_OS_MAC
#ifdef OS_MACOS
ui.actionInsertAfterCurrent->setShortcut(QKeySequence("+"));
ui.actionAppendEntry->setShortcut(QKeySequence("Ctrl++"));
ui.actionGoTo->setShortcut(QKeySequence("Ctrl+L"));
Expand Down Expand Up @@ -109,7 +109,7 @@ QTblEditor::QTblEditor(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(par
_keyHashLabel->setMinimumSize(_keyHashLabel->sizeHint());
_keyHashLabel->clear();

#ifndef Q_OS_MAC
#ifndef OS_MACOS
ui.statusBar->addWidget(new QLabel, 1);
#endif
ui.statusBar->addPermanentWidget(_keyHashLabel);
Expand Down Expand Up @@ -238,7 +238,7 @@ int QTblEditor::openTableMsgBoxResult()
openOptsDlg.setEscapeButton(openOptsDlg.addButton(QMessageBox::Cancel));
openOptsDlg.addButton(tr("Replace active"), QMessageBox::NoRole);
openOptsDlg.setText(tr("How do you want to open the table?"));
#ifdef Q_OS_MAC
#ifdef OS_MACOS
openOptsDlg.setWindowModality(Qt::WindowModal);
#endif
return openOptsDlg.exec();
Expand Down Expand Up @@ -989,7 +989,7 @@ bool QTblEditor::isDialogQuestionConfirmed(const QString &text)
{
QMessageBox confirmationDialog(QMessageBox::Question, qApp->applicationName(), text, QMessageBox::Yes | QMessageBox::No, this);
confirmationDialog.setDefaultButton(QMessageBox::Yes);
#ifdef Q_OS_MAC
#ifdef OS_MACOS
confirmationDialog.setWindowModality(Qt::WindowModal);
#endif
return confirmationDialog.exec() == QMessageBox::Yes;
Expand Down Expand Up @@ -1162,7 +1162,7 @@ void QTblEditor::readSettings()

// read custom colors from file
QFile f(customColorsFilePath());
#ifndef Q_OS_MAC
#ifndef OS_MACOS
if (!f.exists()) // fallback for older versions
f.setFileName(kCustomColorsFileName);
#endif
Expand Down Expand Up @@ -1399,7 +1399,7 @@ QString QTblEditor::restoreNewlines(const QString &s)

QString QTblEditor::customColorsFilePath() const
{
#ifdef Q_OS_MAC
#ifdef OS_MACOS
#ifdef IS_QT5
QString basePath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
#else
Expand Down
10 changes: 10 additions & 0 deletions qtcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

#include <QLatin1String>

#if IS_QT5
# ifdef Q_OS_MACOS
# define OS_MACOS
# endif
#else
# ifdef Q_OS_MAC
# define OS_MACOS
# endif
#endif // IS_QT5

class QFont;
class QLineEdit;

Expand Down

0 comments on commit 90a5eec

Please sign in to comment.