Commit 69f08a6f4ccd0fda2c02a83d6072f005dcd350b6

Authored by Peter Zhigalov
1 parent 30a5d0c8

Унифицировал макросы и починил меню в OS X в проекте с Qt

src_qt/main.cpp
1 1 #include "mainwindow.h"
2 2 #include <QApplication>
3 3  
4   -#if defined USE_STATIC_QJPEG
  4 +#if defined (USE_STATIC_QJPEG)
5 5 Q_IMPORT_PLUGIN(qjpeg)
6 6 #endif
7   -#if defined USE_STATIC_QTIFF
  7 +#if defined (USE_STATIC_QTIFF)
8 8 Q_IMPORT_PLUGIN(qtiff)
9 9 #endif
10 10  
11 11 int main(int argc, char *argv[])
12 12 {
13 13 QApplication a(argc, argv);
14   -#if defined (Q_OS_OSX)
15   - // TODO: При возможности добавить поддержку нативного меню
16   - a.setAttribute(Qt::AA_DontUseNativeMenuBar);
17   -#endif
18 14 MainWindow w;
19 15 if(argc > 1)
20 16 {
... ...
src_qt/mainwindow.cpp
... ... @@ -76,7 +76,7 @@ MainWindow::MainWindow(QWidget *parent) :
76 76 last_saved = "draw.png";
77 77 last_opened = "";
78 78  
79   -#if defined (Q_OS_OSX)
  79 +#if defined (Q_OS_MAC)
80 80 // Очень грустный костыль: под маком очень странная политика работы с фокусом.
81 81 // Из-за этого по-умолчанию фокус устанавливается только на SpinBox'ах. Самый
82 82 // вменяемый способ починить это - заблокировать фокус у всех элементов
... ... @@ -91,6 +91,8 @@ MainWindow::MainWindow(QWidget *parent) :
91 91 ui->comboBox_Vectors_U->setFocusPolicy(Qt::NoFocus);
92 92 ui->label_2->setFocusPolicy(Qt::NoFocus);
93 93 ui->comboBox_Vectors_V->setFocusPolicy(Qt::NoFocus);
  94 + ui->centralwidget->setFocusPolicy(Qt::StrongFocus);
  95 + ui->centralwidget->setFocus();
94 96 #endif
95 97 }
96 98  
... ... @@ -176,7 +178,7 @@ void MainWindow::open_file(QString filename)
176 178  
177 179 // Установим заголовок окна
178 180 QString label = filename.split('/').last();
179   -#if defined _WIN32
  181 +#if defined (Q_OS_WIN32)
180 182 label = label.split('\\').last();
181 183 #endif
182 184 if(ui->widget->title.length() > 0)
... ... @@ -187,7 +189,7 @@ void MainWindow::open_file(QString filename)
187 189 // Сохраним директорию, в которой находится файл
188 190 last_opened = "";
189 191 int stop_index = filename.lastIndexOf("/");
190   -#if defined _WIN32
  192 +#if defined (Q_OS_WIN32)
191 193 int stop_index_win = filename.lastIndexOf("\\");
192 194 if(stop_index_win > stop_index)
193 195 stop_index = stop_index_win;
... ... @@ -226,7 +228,7 @@ void MainWindow::on_actionSave_Image_File_triggered()
226 228 supported.push_back(QString(*it).toLower());
227 229 supported_temp.clear();
228 230 supported.push_back("svg");
229   -//#if !defined HAVE_QT5
  231 +//#if !defined (HAVE_QT5)
230 232 // supported.push_back("ps");
231 233 //#endif
232 234 supported.push_back("pdf");
... ... @@ -305,7 +307,7 @@ void MainWindow::on_actionSave_Image_File_triggered()
305 307 QSvgGenerator generator;
306 308 generator.setFileName(filename);
307 309 generator.setSize(QSize(ui->widget->width(), ui->widget->height()));
308   -#if !defined HAVE_LESS_THAN_QT45
  310 +#if !defined (HAVE_LESS_THAN_QT45)
309 311 generator.setViewBox(QRect(0, 0, ui->widget->width(), ui->widget->height()));
310 312 generator.setTitle(ui->widget->title);
311 313 generator.setDescription(trUtf8("Generated with FEM Draw"));
... ... @@ -313,7 +315,7 @@ void MainWindow::on_actionSave_Image_File_triggered()
313 315 ui->widget->draw(& generator, ui->actionTransparent_Image->isChecked(), true);
314 316 saved = true;
315 317 }
316   -//#if !defined HAVE_QT5
  318 +//#if !defined (HAVE_QT5)
317 319 // else if(ext == "ps" || ext == "pdf")
318 320 //#else
319 321 else if(ext == "pdf")
... ... @@ -322,7 +324,7 @@ void MainWindow::on_actionSave_Image_File_triggered()
322 324 QPrinter printer(QPrinter::ScreenResolution);
323 325 if(ext == "pdf")
324 326 printer.setOutputFormat(QPrinter::PdfFormat);
325   -//#if !defined HAVE_QT5
  327 +//#if !defined (HAVE_QT5)
326 328 // else if(ext == "ps")
327 329 // printer.setOutputFormat(QPrinter::PostScriptFormat);
328 330 //#endif
... ... @@ -457,7 +459,7 @@ void MainWindow::on_actionShow_Isolines_triggered()
457 459 // Событие при запросе конфигурации цвета изолиний
458 460 void MainWindow::on_actionIsolines_Color_triggered()
459 461 {
460   -#if !defined HAVE_LESS_THAN_QT45
  462 +#if !defined (HAVE_LESS_THAN_QT45)
461 463 QColor color = QColorDialog::getColor(ui->widget->isolines_config.color, this, trUtf8("Select Isolines Color"));
462 464 #else
463 465 QColor color = QColorDialog::getColor(ui->widget->isolines_config.color, this);
... ... @@ -491,7 +493,7 @@ void MainWindow::on_actionShow_Vectors_triggered()
491 493 // Событие при запросе конфигурации цвета векторов
492 494 void MainWindow::on_actionVectors_Color_triggered()
493 495 {
494   -#if !defined HAVE_LESS_THAN_QT45
  496 +#if !defined (HAVE_LESS_THAN_QT45)
495 497 QColor color = QColorDialog::getColor(ui->widget->vectors_config.color, this, trUtf8("Select Vectors Color"));
496 498 #else
497 499 QColor color = QColorDialog::getColor(ui->widget->isolines_config.color, this);
... ...
src_qt/mainwindow.ui
... ... @@ -275,6 +275,9 @@
275 275 <property name="shortcut">
276 276 <string>Ctrl+Q</string>
277 277 </property>
  278 + <property name="menuRole">
  279 + <enum>QAction::QuitRole</enum>
  280 + </property>
278 281 </action>
279 282 <action name="actionIncrease_Interpolation">
280 283 <property name="text">
... ... @@ -302,16 +305,25 @@
302 305 <property name="text">
303 306 <string>About FEM Draw...</string>
304 307 </property>
  308 + <property name="menuRole">
  309 + <enum>QAction::AboutRole</enum>
  310 + </property>
305 311 </action>
306 312 <action name="actionAbout_Third_Party_Libraries">
307 313 <property name="text">
308 314 <string>About Third Party Libraries...</string>
309 315 </property>
  316 + <property name="menuRole">
  317 + <enum>QAction::ApplicationSpecificRole</enum>
  318 + </property>
310 319 </action>
311 320 <action name="actionAbout_Qt">
312 321 <property name="text">
313 322 <string>About Qt...</string>
314 323 </property>
  324 + <property name="menuRole">
  325 + <enum>QAction::AboutQtRole</enum>
  326 + </property>
315 327 </action>
316 328 <action name="actionTransparent_Image">
317 329 <property name="checkable">
... ...
src_qt/paintwidget.cpp
1   -#if defined(HAVE_QT5)
  1 +#if defined (HAVE_QT5)
2 2 #include <QtWidgets>
3 3 #else
4 4 #include <QtGui>
... ... @@ -1017,7 +1017,7 @@ void paintwidget::draw(QPaintDevice * device, bool transparency, bool is_svg)
1017 1017 fnt_serif.setPixelSize(fnt_serif_h < fnt_serif_w ? fnt_serif_h : fnt_serif_w);
1018 1018 fnt_serif.setBold(true);
1019 1019  
1020   -#if defined HAVE_LESS_THAN_QT45
  1020 +#if defined (HAVE_LESS_THAN_QT45)
1021 1021 fnt_mono.setPointSizeF(qreal(fnt_mono.pixelSize()) * qreal(0.75));
1022 1022 fnt_serif.setPointSizeF(qreal(fnt_serif.pixelSize()) * qreal(0.75));
1023 1023 #endif
... ...