From 141fbb6f8c8518843ae69a48c1e33f5406951e87 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Sun, 3 Feb 2013 12:23:31 +0100 Subject: [PATCH] Prepare LyX code to compile and link with Qt5: * some functionality is in new modules now new header locations and library names: QtConcurrent and QtWidgets * method setResizeMode is renamed to setSectionResizeMode * deprecated QAbstractItemModel::reset() is dropped now * platform specific code like QApplication::syncX() is not common anymore * QString::fromAscii() is dropped now * some QDesktopServices methods has been moved to QStandardPaths --- config/qt4.m4 | 3 ++- development/LyX-Mac-binary-release.sh | 34 +++++++++++++++++++-------- src/frontends/qt4/FancyLineEdit.cpp | 24 +++++++++---------- src/frontends/qt4/FancyLineEdit.h | 4 ++-- src/frontends/qt4/GuiApplication.cpp | 5 +++- src/frontends/qt4/GuiCompleter.cpp | 7 +++--- src/frontends/qt4/GuiDocument.cpp | 5 ++-- src/frontends/qt4/GuiSymbols.cpp | 3 ++- src/frontends/qt4/GuiWorkArea.cpp | 6 +++++ src/frontends/qt4/LyXFileDialog.cpp | 2 +- src/frontends/qt4/Menus.cpp | 2 +- src/frontends/qt4/PanelStack.cpp | 2 +- src/frontends/qt4/TocModel.cpp | 4 ++++ src/frontends/qt4/qt_helpers.cpp | 17 ++++++++++++++ src/frontends/qt4/qt_helpers.h | 8 +++++++ src/support/FileName.cpp | 4 ++++ src/support/Package.cpp | 7 ++++++ 17 files changed, 101 insertions(+), 36 deletions(-) diff --git a/config/qt4.m4 b/config/qt4.m4 index 5cbf7f7538..3114341051 100644 --- a/config/qt4.m4 +++ b/config/qt4.m4 @@ -39,6 +39,7 @@ AC_DEFUN([QT4_CHECK_COMPILE], qt4_cv_libname= for libname in '-lQtCore -lQtGui' \ '-lQtCore4 -lQtGui4' \ + '-framework QtCore -framework QtConcurrent -framework QtWidgets -framework QtGui'\ '-framework QtCore -framework QtGui' do QT4_TRY_LINK($libname) @@ -197,7 +198,7 @@ AC_DEFUN([QT4_DO_MANUAL_CONFIG], QT4_CORE_LDFLAGS= if test -n "$qt4_cv_includes"; then QT4_INCLUDES="-I$qt4_cv_includes" - for i in Qt QtCore QtGui; do + for i in Qt QtCore QtGui QtWidgets QtConcurrent; do QT4_INCLUDES="$QT4_INCLUDES -I$qt4_cv_includes/$i" done QT4_CORE_INCLUDES="-I$qt4_cv_includes -I$qt4_cv_includes/QtCore" diff --git a/development/LyX-Mac-binary-release.sh b/development/LyX-Mac-binary-release.sh index 8b66c7ce53..32e4b7cd7b 100644 --- a/development/LyX-Mac-binary-release.sh +++ b/development/LyX-Mac-binary-release.sh @@ -44,7 +44,7 @@ LyXConfigureOptions="--enable-warnings --enable-optimization=-Os --with-x=no" LyXConfigureOptions="${LyXConfigureOptions} --disable-stdlib-debug" AspellConfigureOptions="--enable-warnings --enable-optimization=-O0 --enable-debug --disable-nls --enable-compile-in-filters --disable-pspell-compatibility" HunspellConfigureOptions="--with-warnings --disable-nls --disable-static" -Qt4ConfigureOptions="${Qt4ConfigureOptions} -opensource -silent -shared -fast -no-exceptions" +Qt4ConfigureOptions="${QtConfigureOptions} -opensource -silent -shared -fast -no-exceptions" Qt4ConfigureOptions="${Qt4ConfigureOptions} -no-webkit -no-qt3support -no-javascript-jit -no-dbus" Qt4ConfigureOptions="${Qt4ConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools" @@ -52,6 +52,11 @@ Qt4ConfigureOptions="${Qt4ConfigureOptions} -nomake examples -nomake demos -noma case "${Qt4Version}:${Qt4API}" in 4.6*:-carbon) ;; +5.0*) + Qt4ConfigureOptions="${QtConfigureOptions} -opensource -silent -shared -fast -no-strip" + Qt4ConfigureOptions="${Qt4ConfigureOptions} -no-javascript-jit -no-pkg-config" + Qt4ConfigureOptions="${Qt4ConfigureOptions} -nomake examples -nomake demos -nomake docs -nomake tools" + ;; *) Qt4ConfigureOptions="${Qt4ConfigureOptions} ${Qt4API}" ;; @@ -125,6 +130,12 @@ usage() { exit 0 } +NCPU=$(sysctl -n hw.ncpu) +NCPU=$((NCPU / 2)) +if [ $NCPU -gt 1 ]; then + MAKEJOBS=-j${NCPU} +fi + while [ $# -gt 0 ]; do case "${1}" in --with-qt4-frameworks=*) @@ -226,7 +237,6 @@ done if [ "${configure_qt4_frameworks}" != "yes" ]; then QtInstallDir=${QTDIR:-"/opt/qt4"} fi -QtFrameworkVersion="4" ARCH_LIST=${ARCH_LIST:-"ppc i386"} @@ -277,7 +287,16 @@ LyxAppPrefix="${LyxAppDir}.app" # --------------------------------- # don't change order here... -QtLibraries="QtSvg QtXml QtGui QtNetwork QtCore" +case "${Qt4Version}" in +5*) + QtLibraries="QtSvg QtXml QtPrintSupport QtWidgets QtGui QtNetwork QtConcurrent QtCore" + QtFrameworkVersion="5" + ;; +*) + QtLibraries="QtSvg QtXml QtGui QtNetwork QtCore" + QtFrameworkVersion="4" + ;; +esac DMGNAME="${LyxBase}" DMGSIZE="550m" @@ -332,7 +351,7 @@ if [ "${configure_qt4_frameworks}" != "yes" -a -d "${Qt4SourceDir}" -a ! \( -d " echo configure options: echo ${Qt4ConfigureOptions} ${ARCHS} -prefix "${QtInstallDir}" echo yes | "${Qt4SourceDir}"/configure ${Qt4ConfigureOptions} ${ARCHS} -prefix "${QtInstallDir}" - make && make install + make ${MAKEJOBS} && make install ) cd "${QtInstallDir}" && ( mkdir -p include @@ -603,12 +622,7 @@ build_lyx() { ${QtInstallDir:+"--with-qt4-dir=${QtInstallDir}"} \ ${LyXConfigureOptions}\ --enable-build-type=rel && \ - NCPU=$(sysctl -n hw.ncpu) - NCPU=$((NCPU / 2)) - if [ $NCPU -gt 1 ]; then - NUMJOBS=-j${NCPU} - fi - make ${NUMJOBS} && make install${strip} + make ${MAKEJOBS} && make install${strip} for file in ${LYX_FILE_LIST} ; do if [ -f "${LYX_BUNDLE_PATH}/${file}" ]; then mv "${LYX_BUNDLE_PATH}/${file}"\ diff --git a/src/frontends/qt4/FancyLineEdit.cpp b/src/frontends/qt4/FancyLineEdit.cpp index 48bcf34130..e0057daecf 100644 --- a/src/frontends/qt4/FancyLineEdit.cpp +++ b/src/frontends/qt4/FancyLineEdit.cpp @@ -17,18 +17,18 @@ #if QT_VERSION >= 0x040600 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include enum { margin = 6 }; diff --git a/src/frontends/qt4/FancyLineEdit.h b/src/frontends/qt4/FancyLineEdit.h index 89ef45b4ab..ae62c8539e 100644 --- a/src/frontends/qt4/FancyLineEdit.h +++ b/src/frontends/qt4/FancyLineEdit.h @@ -14,8 +14,8 @@ #ifndef FANCYLINEEDIT_H #define FANCYLINEEDIT_H -#include -#include +#include +#include namespace lyx { namespace frontend { diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index f463ec1ed4..83f1dc1ef6 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -93,7 +93,6 @@ #include #include #include -#include #include #include #include @@ -127,6 +126,10 @@ #include #endif // Q_WS_WIN +#ifdef Q_WS_MACX +#include +#endif // Q_WS_MACX + #include "support/bind.h" #include diff --git a/src/frontends/qt4/GuiCompleter.cpp b/src/frontends/qt4/GuiCompleter.cpp index 7ef1a1a579..0f9686ad60 100644 --- a/src/frontends/qt4/GuiCompleter.cpp +++ b/src/frontends/qt4/GuiCompleter.cpp @@ -90,9 +90,10 @@ public: ~GuiCompletionModel() { delete list_; } /// void setList(CompletionList const * l) { + beginResetModel(); delete list_; list_ = l; - reset(); + endResetModel(); } /// bool sorted() const @@ -444,8 +445,8 @@ void GuiCompleter::asyncUpdatePopup() // has a bad memory about it and we have to tell him again and again. QTreeView * listView = static_cast(popup()); listView->header()->setStretchLastSection(false); - listView->header()->setResizeMode(0, QHeaderView::Stretch); - listView->header()->setResizeMode(1, QHeaderView::Fixed); + setSectionResizeMode(listView->header(), 0, QHeaderView::Stretch); + setSectionResizeMode(listView->header(), 1, QHeaderView::Fixed); listView->header()->resizeSection(1, 22); // show/update popup diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index 481bc0947b..16242c0974 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -1132,8 +1132,7 @@ GuiDocument::GuiDocument(GuiView & lv) numberingModule->tocTW->headerItem()->setText(0, qt_("Example")); numberingModule->tocTW->headerItem()->setText(1, qt_("Numbered")); numberingModule->tocTW->headerItem()->setText(2, qt_("Appears in TOC")); - numberingModule->tocTW->header()->setResizeMode(QHeaderView::ResizeToContents); - + setSectionResizeMode(numberingModule->tocTW->header(), QHeaderView::ResizeToContents); // biblio biblioModule = new UiWidget; @@ -1327,7 +1326,7 @@ GuiDocument::GuiDocument(GuiView & lv) // Modules modulesModule = new UiWidget; modulesModule->availableLV->header()->setVisible(false); - modulesModule->availableLV->header()->setResizeMode(QHeaderView::ResizeToContents); + setSectionResizeMode(modulesModule->availableLV->header(), QHeaderView::ResizeToContents); modulesModule->availableLV->header()->setStretchLastSection(false); selectionManager = new ModuleSelectionManager(modulesModule->availableLV, diff --git a/src/frontends/qt4/GuiSymbols.cpp b/src/frontends/qt4/GuiSymbols.cpp index 2fb1b3f170..874f275874 100644 --- a/src/frontends/qt4/GuiSymbols.cpp +++ b/src/frontends/qt4/GuiSymbols.cpp @@ -248,8 +248,9 @@ public: void setSymbols(QList const & symbols) { + QAbstractItemModel::beginResetModel(); symbols_ = symbols; - QAbstractItemModel::reset(); + QAbstractItemModel::endResetModel(); } private: diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 147d84203a..ba99255a56 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -55,7 +55,9 @@ #include "frontends/WorkAreaManager.h" #include +#if (QT_VERSION < 0x050000) #include +#endif #include #include #ifdef Q_WS_MACX @@ -674,7 +676,9 @@ void GuiWorkArea::scrollTo(int value) } // Show the cursor immediately after any operation. startBlinkingCursor(); +#ifdef Q_WS_X11 QApplication::syncX(); +#endif } @@ -794,7 +798,9 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e) return; } +#if (QT_VERSION < 0x050000) inputContext()->reset(); +#endif FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(), q_button_state(e->button())); diff --git a/src/frontends/qt4/LyXFileDialog.cpp b/src/frontends/qt4/LyXFileDialog.cpp index c0981611b5..2bc7ba1a03 100644 --- a/src/frontends/qt4/LyXFileDialog.cpp +++ b/src/frontends/qt4/LyXFileDialog.cpp @@ -49,7 +49,7 @@ LyXFileDialog::LyXFileDialog(QString const & title, // FIXME replace that with guiApp->currentView() : QFileDialog(qApp->focusWidget(), title, path) { - setFilters(filters); + setNameFilters(filters); setWindowTitle(title); QList layout = findChildren(); diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index 1c641a020c..cd7518b481 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1875,7 +1875,7 @@ void Menus::Impl::macxMenuBarInit(GuiView * view, QMenuBar * qmb) QAction::MenuRole role; }; - MacMenuEntry entries[] = { + static MacMenuEntry entries[] = { {LFUN_DIALOG_SHOW, "aboutlyx", "About LyX", QAction::AboutRole}, {LFUN_DIALOG_SHOW, "prefs", "Preferences", diff --git a/src/frontends/qt4/PanelStack.cpp b/src/frontends/qt4/PanelStack.cpp index 47662a66c7..d006f450b8 100644 --- a/src/frontends/qt4/PanelStack.cpp +++ b/src/frontends/qt4/PanelStack.cpp @@ -60,7 +60,7 @@ PanelStack::PanelStack(QWidget * parent) list_->setRootIsDecorated(false); list_->setColumnCount(1); list_->header()->hide(); - list_->header()->setResizeMode(QHeaderView::ResizeToContents); + setSectionResizeMode(list_->header(), QHeaderView::ResizeToContents); list_->header()->setStretchLastSection(false); list_->setMinimumSize(list_->viewport()->size()); diff --git a/src/frontends/qt4/TocModel.cpp b/src/frontends/qt4/TocModel.cpp index 755d260fd6..6320536f59 100644 --- a/src/frontends/qt4/TocModel.cpp +++ b/src/frontends/qt4/TocModel.cpp @@ -44,7 +44,11 @@ public: /// void reset() { +#if (QT_VERSION < 0x050000) QStandardItemModel::reset(); +#else + QStandardItemModel::endResetModel(); +#endif } /// void beginResetModel() diff --git a/src/frontends/qt4/qt_helpers.cpp b/src/frontends/qt4/qt_helpers.cpp index dcbd2e9cb1..35bac8bbd0 100644 --- a/src/frontends/qt4/qt_helpers.cpp +++ b/src/frontends/qt4/qt_helpers.cpp @@ -196,6 +196,23 @@ void setValid(QWidget * widget, bool valid) } } +/// wrapper to hide the change of method name to setSectionResizeMode +void setSectionResizeMode(QHeaderView * view, + int logicalIndex, QHeaderView::ResizeMode mode) { +#if (QT_VERSION >= 0x050000) + view->setSectionResizeMode(logicalIndex, mode); +#else + view->setResizeMode(logicalIndex, mode); +#endif +} + +void setSectionResizeMode(QHeaderView * view, QHeaderView::ResizeMode mode) { +#if (QT_VERSION >= 0x050000) + view->setSectionResizeMode(mode); +#else + view->setResizeMode(mode); +#endif +} } // namespace frontend QString const qt_(char const * str, const char *) diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index 44e6b0e07b..753fdbfad3 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -18,6 +18,7 @@ #include "qt_i18n.h" #include +#include class QComboBox; class QLineEdit; @@ -66,6 +67,13 @@ void doubleToWidget(QLineEdit * input, std::string const & value, /// colors a widget red if invalid void setValid(QWidget * widget, bool valid); +/// Qt5 changed setSectionMode to setSectionResizeMode +/// These wrappers work for Qt4 and Qt5 +void setSectionResizeMode(QHeaderView * view, + int logicalIndex, QHeaderView::ResizeMode mode); +void setSectionResizeMode(QHeaderView * view, + QHeaderView::ResizeMode mode); + } // namespace frontend diff --git a/src/support/FileName.cpp b/src/support/FileName.cpp index fe081ab655..96317bed27 100644 --- a/src/support/FileName.cpp +++ b/src/support/FileName.cpp @@ -746,7 +746,11 @@ docstring FileName::fileContents(string const & encoding) const if (encoding.empty() || encoding == "UTF-8") s = QString::fromUtf8(contents.data()); else if (encoding == "ascii") +#if (QT_VERSION < 0x050000) s = QString::fromAscii(contents.data()); +#else + s = QString::fromLatin1(contents.data()); +#endif else if (encoding == "local8bit") s = QString::fromLocal8Bit(contents.data()); else if (encoding == "latin1") diff --git a/src/support/Package.cpp b/src/support/Package.cpp index 6ea458e67c..dab008e77c 100644 --- a/src/support/Package.cpp +++ b/src/support/Package.cpp @@ -381,6 +381,9 @@ FileName const get_document_dir(FileName const & home_dir) (void)home_dir; // Silence warning about unused variable. os::GetFolderPath win32_folder_path; return FileName(win32_folder_path(os::GetFolderPath::PERSONAL)); +#elif defined (USE_MACOSX_PACKAGING) && (QT_VERSION >= 0x050000) + (void)home_dir; // Silence warning about unused variable. + return FileName(fromqstr(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation))); #elif defined (USE_MACOSX_PACKAGING) (void)home_dir; // Silence warning about unused variable. return FileName(fromqstr(QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation))); @@ -647,6 +650,10 @@ FileName const get_default_user_support_dir(FileName const & home_dir) os::GetFolderPath win32_folder_path; return FileName(addPath(win32_folder_path(os::GetFolderPath::APPDATA), PACKAGE)); +#elif defined (USE_MACOSX_PACKAGING) && (QT_VERSION >= 0x050000) + (void)home_dir; // Silence warning about unused variable. + return FileName(addPath(fromqstr(QStandardPaths::writableLocation(QStandardPaths::DataLocation)), PACKAGE)); + #elif defined (USE_MACOSX_PACKAGING) (void)home_dir; // Silence warning about unused variable. return FileName(addPath(fromqstr(QDesktopServices::storageLocation(QDesktopServices::DataLocation)), PACKAGE)); -- 2.39.5