From d5cec47da92e080f25d87b2aa19ae8b808035800 Mon Sep 17 00:00:00 2001 From: Gennady Pospelov <g.pospelov@fz-juelich.de> Date: Tue, 17 Sep 2013 23:08:04 +0200 Subject: [PATCH] Compiling GUI with CMake, part I --- App/CMakeLists.txt | 2 +- CMakeLists.txt | 2 +- GUI/CMakeLists.txt | 4 + GUI/coregui/CMakeLists.txt | 83 +++++++ .../SampleDesigner/DesignerScene.cpp | 1 - .../SampleDesigner/LayerDockView.cpp | 207 ------------------ .../Components/SampleDesigner/LayerDockView.h | 61 ------ GUI/coregui/coregui.pro | 5 +- .../qtbuttonpropertybrowser.cpp | 1 + .../qtpropertybrowser/qteditorfactory.cpp | 1 + .../qt-manhattan-style/CMakeLists.txt | 5 +- .../qt-root-gui-factory/CMakeLists.txt | 3 +- GUI/externals/qt-root/CMakeLists.txt | 2 +- 13 files changed, 100 insertions(+), 277 deletions(-) create mode 100644 GUI/coregui/CMakeLists.txt delete mode 100644 GUI/coregui/Views/Components/SampleDesigner/LayerDockView.cpp delete mode 100644 GUI/coregui/Views/Components/SampleDesigner/LayerDockView.h diff --git a/App/CMakeLists.txt b/App/CMakeLists.txt index 071c3b3bd72..4ceb8221e82 100644 --- a/App/CMakeLists.txt +++ b/App/CMakeLists.txt @@ -52,7 +52,7 @@ execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/T # dictionaries ROOT_GENERATE_DICTIONARY(AppDict inc/DrawHelper.h inc/TreeEventStructure.h LINKDEF AppLinkDef.h) -add_executable(${executable_name} ${source_files} AppDict.cxx ${header_files}) +add_executable(${executable_name} ${source_files} AppDict.cxx ${include_files}) # --- dependencies --- include_directories( diff --git a/CMakeLists.txt b/CMakeLists.txt index 5db9b8e8996..f777ef7d4a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ project(BornAgain) # --- General project settings --- if(NOT BORNAGAIN_PYTHON) -# set(BORNAGAIN_PYTHON ON) + set(BORNAGAIN_PYTHON ON) endif() if(NOT BORNAGAIN_APP) diff --git a/GUI/CMakeLists.txt b/GUI/CMakeLists.txt index 919e9ebe26f..23ba90e4baa 100644 --- a/GUI/CMakeLists.txt +++ b/GUI/CMakeLists.txt @@ -4,7 +4,11 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR) +find_package(Qt5Widgets REQUIRED) + add_subdirectory(externals/qt-manhattan-style) add_subdirectory(externals/qt-root) add_subdirectory(externals/qt-root-gui-factory) +add_subdirectory(coregui) + diff --git a/GUI/coregui/CMakeLists.txt b/GUI/coregui/CMakeLists.txt new file mode 100644 index 00000000000..b2c787beb1a --- /dev/null +++ b/GUI/coregui/CMakeLists.txt @@ -0,0 +1,83 @@ +############################################################################ +# CMakeLists.txt file for building coregui +############################################################################ + +cmake_minimum_required(VERSION 2.8 FATAL_ERROR) + +set(executable_name coregui) + +# --- source and include files --- +set(include_dirs + ${CMAKE_CURRENT_SOURCE_DIR}/mainwindow + ${CMAKE_CURRENT_SOURCE_DIR}/utils + ${CMAKE_CURRENT_SOURCE_DIR}/Models + ${CMAKE_CURRENT_SOURCE_DIR}/Views + ${CMAKE_CURRENT_SOURCE_DIR}/Views/Components/widgetbox + ${CMAKE_CURRENT_SOURCE_DIR}/Views/Components/SampleDesigner + ${CMAKE_CURRENT_SOURCE_DIR}/qttools/qtpropertybrowser +) +include_directories(${include_dirs}) +message("XXX ${CMAKE_CURRENT_BINARY_DIR}") +include_directories(${CMAKE_CURRENT_BINARY_DIR}) # qtpropertybrowser needs some moc files + +file(GLOB source_files + "mainwindow/*.cpp" + "utils/*.cpp" + "Models/*.cpp" + "Views/*.cpp" + "Views/Components/widgetbox/*.cpp" + "Views/Components/SampleDesigner/*.cpp" + "qttools/qtpropertybrowser/*.cpp" +) + +file(GLOB include_files + "mainwindow/*.h" + "utils/*.h" + "Models/*.h" + "Views/*.h" + "Views/Components/widgetbox/*.h" + "Views/Components/SampleDesigner/*.h" + "qttools/qtpropertybrowser/*.h" +) + +set(resource_files + "coregui.qrc" + "qttools/qtpropertybrowser/qtpropertybrowser.qrc" + "Views/Components/SampleDesigner/SampleDesigner.qrc" + "Views/Components/widgetbox/widgetbox.qrc" +) + +set(CMAKE_AUTOMOC ON) +qt5_add_resources(RC_SRCS ${resource_files}) +add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x040900) + +add_executable(${executable_name} ${source_files} ${RC_SRCS} ${include_files}) + +# --- dependencies --- +message("XXX ${PYTHON_INCLUDE_DIRS}") +include_directories( + ${BornAgainCore_INCLUDE_DIRS} + ${BornAgainFit_INCLUDE_DIRS} + ${ROOT_INCLUDE_DIR} + ${ManhattanStyle_INCLUDE_DIRS} + ${GQt_INCLUDE_DIRS} + ${QtRoot_INCLUDE_DIRS} + ${EIGEN3_INCLUDE_DIR} + ${PYTHON_INCLUDE_DIRS} +) +target_link_libraries(${executable_name} + ${BornAgainCore_LIBRARY} + ${BornAgainFit_LIBRARY} + ${ROOT_LIBRARIES} + ${GQt_LIBRARY} + ${QtRoot_LIBRARY} +) + +#core gui script webkit webkitwidgets designer designercomponents + +target_link_libraries(${executable_name} ${Qt5Widgets_LIBRARIES}) + +#core gui script webkit webkitwidgets designer designercomponents +qt5_use_modules(${executable_name} Widgets Core Gui Script WebKit WebKitWidgets Designer) + + diff --git a/GUI/coregui/Views/Components/SampleDesigner/DesignerScene.cpp b/GUI/coregui/Views/Components/SampleDesigner/DesignerScene.cpp index b0472b0767f..d3ae2e3637c 100644 --- a/GUI/coregui/Views/Components/SampleDesigner/DesignerScene.cpp +++ b/GUI/coregui/Views/Components/SampleDesigner/DesignerScene.cpp @@ -6,7 +6,6 @@ #include "MultiLayerView.h" #include "DesignerMimeData.h" #include "DesignerHelper.h" -#include "LayerDockView.h" #include "NodeEditor.h" #include "ISampleToIView.h" #include "SampleBuilderFactory.h" diff --git a/GUI/coregui/Views/Components/SampleDesigner/LayerDockView.cpp b/GUI/coregui/Views/Components/SampleDesigner/LayerDockView.cpp deleted file mode 100644 index fb3d368065a..00000000000 --- a/GUI/coregui/Views/Components/SampleDesigner/LayerDockView.cpp +++ /dev/null @@ -1,207 +0,0 @@ -#include "LayerDockView.h" - -#include <QPainter> -#include <QGraphicsSceneMouseEvent> -#include <QDrag> -#include <QCursor> -#include <QApplication> -#include <QMimeData> -#include <QBitmap> -#include <QWidget> -#include <QGradient> -#include <iostream> -#include <QDropEvent> -#include <QStyleOptionGraphicsItem> - -#include "LayerView.h" -#include "MultiLayerView.h" -#include "DesignerHelper.h" -#include "DesignerMimeData.h" - - -//bool sort_layers(QGraphicsItem* left, QGraphicsItem *right) { -// return left->y() < right->y(); -//} - - -LayerDockView::LayerDockView(QGraphicsItem *parent) - : ISampleView(parent) - , m_color(Qt::lightGray) - , m_rect(0, 0, DesignerHelper::getMultiLayerWidth(), DesignerHelper::getMultiLayerHeight()) -{ - setToolTip(QString("LayerDockWidget: drag layers and multi layers on top") ); - setFlag(QGraphicsItem::ItemIsMovable, true); - setFlag(QGraphicsItem::ItemIsSelectable, false); - setFlag(QGraphicsItem::ItemSendsGeometryChanges); - setAcceptDrops(true); - - connect(this, SIGNAL(childrenChanged()), this, SLOT(updateHeight())); - updateHeight(); -} - - -void LayerDockView::addLayer(LayerView *layer, QPointF pos) -{ - // adjusting main rectangle othervise item->setPos will not work due to 'LayerView::itemChange' - m_rect.setHeight(m_rect.height()+layer->boundingRect().height()); - - int xpos = (DesignerHelper::getMultiLayerWidth() - DesignerHelper::getLayerWidth())/2.; - layer->setPos(xpos, pos.y()); - layer->setFixedX(); - connect(layer, SIGNAL(LayerMoved()), this, SLOT(updateHeight()) ); - layer->setParentItem(this); -} - - -void LayerDockView::addLayer(MultiLayerView *layer, QPointF pos) -{ - // adjusting main rectangle othervise item->setPos will not work due to 'LayerView::itemChange' - m_rect.setHeight(m_rect.height()+layer->boundingRect().height()); - - int xpos = (DesignerHelper::getMultiLayerWidth() - DesignerHelper::getLayerWidth())/2.; - layer->setPos(xpos, pos.y()); - //layer->setFixedX(); - connect(layer, SIGNAL(LayerMoved()), this, SLOT(updateHeight()) ); - layer->setParentItem(this); -} - - - -// adjusts positions of Layers inside MultiLayer, updates total MultiLayer height -// calculates drop areas for new layers -// called when one of Layer is changed -void LayerDockView::updateHeight() -{ - std::cout << "LayerDockView::updateHeight() " << std::endl; - // drop areas are rectangles covering the area of layer interfaces - m_drop_areas.clear(); - - QList<QGraphicsItem *> list = childItems(); - qSort(list.begin(), list.end(), DesignerHelper::sort_layers); - - int total_height = 0; - if( childItems().size() > 0) { - foreach(QGraphicsItem *item, list) { - item->setY(total_height); - total_height += item->boundingRect().height(); - m_drop_areas.append(QRectF(0, item->y() - item->boundingRect().height()/4., boundingRect().width(), item->boundingRect().height()/2.)); - } - m_drop_areas.append(QRectF(0, list.back()->y() +list.back()->boundingRect().height() - list.back()->boundingRect().height()/4., boundingRect().width(), list.back()->boundingRect().height()/2.)); - } else { - total_height = DesignerHelper::getMultiLayerHeight(); - m_drop_areas.append(boundingRect()); - } - - m_rect.setHeight(total_height); - update(); -} - - -bool LayerDockView::isInDropArea(QPointF pos) -{ - foreach(QRectF rect, m_drop_areas) { - //std::cout << " drop areas " << rect.x() << " " << rect.y() << " " << rect.width() << " " << rect.height() << " point" << pos.x() << " " << pos.y() << std::endl; - if (rect.contains(pos)) return true; - } - return false; -} - - -QRectF LayerDockView::boundingRect() const -{ - return rect(); -} - - -void LayerDockView::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(widget); - painter->setPen(Qt::lightGray); - if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) { - painter->setPen(Qt::DashLine); - } - painter->setBrush(DesignerHelper::getLayerGradient(m_color, rect() ) ); - painter->drawRect(rect()); -} - - -void LayerDockView::dragEnterEvent(QGraphicsSceneDragDropEvent *event) -{ - const DesignerMimeData *mimeData = checkDragEvent(event); - if (mimeData) { - std::cout << "LayerDockView::dragEnterEvent() -> INSIDE " << std::endl; - } -} - - -void LayerDockView::dragLeaveEvent(QGraphicsSceneDragDropEvent *event) -{ - Q_UNUSED(event); - std::cout << "LayerDockView::dragLeaveEvent() -> " << std::endl; -} - - -void LayerDockView::dropEvent(QGraphicsSceneDragDropEvent *event) -{ - std::cout << "LayerDockView::dropEvent() -> " << std::endl; - const DesignerMimeData *mimeData = checkDragEvent(event); - if (mimeData) { - std::cout << "LayerDockView::dropEvent() -> yes" << std::endl; - if(mimeData->getClassName() == QString("Layer") ) addLayer(new LayerView(), event->pos()); - if(mimeData->getClassName() == QString("MultiLayer") ) addLayer(new MultiLayerView(), event->pos()); - update(); - } -} - - -void LayerDockView::dragMoveEvent(QGraphicsSceneDragDropEvent *event) -{ - const DesignerMimeData *mimeData = checkDragEvent(event); - if (mimeData) { - std::cout << "LayerDockView::dragMoveEvent() -> pos:" << event->pos().x() << " " << event->pos().y() << std::endl; - update(); - - } -} - - -void LayerDockView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - std::cout << "LayerDockView::mouseMoveEvent -> " << x() << " " << y() << std::endl; - QGraphicsObject::mouseMoveEvent(event); -} - - -void LayerDockView::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - std::cout << "LayerDockView::mousePressEvent -> " << x() << " " << y() << std::endl; - QGraphicsObject::mousePressEvent(event); -} - -void LayerDockView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - std::cout << "LayerDockView::mouseReleaseEvent -> " << x() << " " << y() << std::endl; - QGraphicsObject::mouseReleaseEvent(event); -} - - -const DesignerMimeData *LayerDockView::checkDragEvent(QGraphicsSceneDragDropEvent * event) -{ - std::cout << "LayerDockView::checkDragEvent -> " << std::endl; - const DesignerMimeData *mimeData = qobject_cast<const DesignerMimeData *>(event->mimeData()); - if (!mimeData) { - event->ignore(); - return 0; - } - - if(mimeData->hasFormat("bornagain/widget") - && (mimeData->getClassName() == QString("Layer") || mimeData->getClassName() == QString("MultiLayer") ) - && isInDropArea(event->pos()) ) { - std::cout << "LayerDockView::checkDragEvent -> yes" << std::endl; - event->setAccepted(true); - } else { - event->setAccepted(false); - } - return mimeData; -} - diff --git a/GUI/coregui/Views/Components/SampleDesigner/LayerDockView.h b/GUI/coregui/Views/Components/SampleDesigner/LayerDockView.h deleted file mode 100644 index 1128ecb613d..00000000000 --- a/GUI/coregui/Views/Components/SampleDesigner/LayerDockView.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef LAYERDOCKVIEW_H -#define LAYERDOCKVIEW_H - -#include "ConnectableView.h" - -#include <QGraphicsItem> -#include <QGraphicsObject> -#include <QColor> -#include <QRectF> -#include <QRect> -#include <QGradient> - -class LayerView; -class MultiLayerView; -class DesignerMimeData; - - -class LayerDockView : public IView -{ - Q_OBJECT -public: - - LayerDockView(QGraphicsItem *parent = 0); - - QRectF boundingRect() const; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - - QRect rect() const { return m_rect; } - - - - void addLayer(LayerView *layer, QPointF pos=QPointF()); - void addLayer(MultiLayerView *layer, QPointF pos=QPointF()); - -public slots: - void updateHeight(); - -protected: - void dragEnterEvent(QGraphicsSceneDragDropEvent *event); - void dragLeaveEvent(QGraphicsSceneDragDropEvent *event); - void dropEvent(QGraphicsSceneDragDropEvent *event); - void dragMoveEvent(QGraphicsSceneDragDropEvent *event); - - - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - - const DesignerMimeData *checkDragEvent(QGraphicsSceneDragDropEvent * event); -private: - bool isInDropArea(QPointF pos); - - QColor m_color; - QRect m_rect; - QLine m_line; - QList<QRectF> m_drop_areas; -}; - - - -#endif // LAYERDOCKVIEW_H diff --git a/GUI/coregui/coregui.pro b/GUI/coregui/coregui.pro index 6bea19e5b04..055da7ae126 100644 --- a/GUI/coregui/coregui.pro +++ b/GUI/coregui/coregui.pro @@ -2,7 +2,8 @@ # qmake project file to compile GUI core # ----------------------------------------------------------------------------- -QT += core gui script webkit webkitwidgets designer designercomponents +#QT += core gui script webkit webkitwidgets designer designercomponents +QT += core gui script webkit webkitwidgets designer greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = coregui TEMPLATE = app @@ -116,7 +117,7 @@ lessThan(QT_MAJOR_VERSION, 5): LIBS += -lQtDesigner -lQtDesignerComponents -lQtX # general project settings # ----------------------------------------------------------------------------- include($$PWD/../../shared.pri) -#INCLUDEPATH -= /opt/local/include +INCLUDEPATH -= /opt/local/include INCLUDEPATH += $${ROOT_FRAMEWORK_INCLUDEPATH} LIBS += $${ROOT_FRAMEWORK_LIBS} diff --git a/GUI/coregui/qttools/qtpropertybrowser/qtbuttonpropertybrowser.cpp b/GUI/coregui/qttools/qtpropertybrowser/qtbuttonpropertybrowser.cpp index 293fbf6bfdb..dc79c6db544 100644 --- a/GUI/coregui/qttools/qtpropertybrowser/qtbuttonpropertybrowser.cpp +++ b/GUI/coregui/qttools/qtpropertybrowser/qtbuttonpropertybrowser.cpp @@ -624,4 +624,5 @@ bool QtButtonPropertyBrowser::isExpanded(QtBrowserItem *item) const QT_END_NAMESPACE #endif +//XXX #include "moc_qtbuttonpropertybrowser.cpp" diff --git a/GUI/coregui/qttools/qtpropertybrowser/qteditorfactory.cpp b/GUI/coregui/qttools/qtpropertybrowser/qteditorfactory.cpp index afd15206b99..2dcf6a010df 100644 --- a/GUI/coregui/qttools/qtpropertybrowser/qteditorfactory.cpp +++ b/GUI/coregui/qttools/qtpropertybrowser/qteditorfactory.cpp @@ -2678,5 +2678,6 @@ void QtFontEditorFactory::disconnectPropertyManager(QtFontPropertyManager *manag QT_END_NAMESPACE #endif +//XXX #include "moc_qteditorfactory.cpp" #include "qteditorfactory.moc" diff --git a/GUI/externals/qt-manhattan-style/CMakeLists.txt b/GUI/externals/qt-manhattan-style/CMakeLists.txt index c0edc51e060..eaf7a631551 100644 --- a/GUI/externals/qt-manhattan-style/CMakeLists.txt +++ b/GUI/externals/qt-manhattan-style/CMakeLists.txt @@ -49,6 +49,9 @@ set(SRCS extensions/threelevelsitempicker.cpp ) +set(include_dirs ${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${include_dirs}) + set(RCS resources/resources.qrc ) @@ -60,7 +63,7 @@ set(UI_FILES # Qt5 set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) -find_package(Qt5Widgets) +#find_package(Qt5Widgets) # Run uic on ui files qt5_wrap_ui(UI_HDRS ${UI_FILES}) diff --git a/GUI/externals/qt-root-gui-factory/CMakeLists.txt b/GUI/externals/qt-root-gui-factory/CMakeLists.txt index 5bbcd5c5cf3..29b29e9f15a 100644 --- a/GUI/externals/qt-root-gui-factory/CMakeLists.txt +++ b/GUI/externals/qt-root-gui-factory/CMakeLists.txt @@ -24,7 +24,6 @@ set(${library_name}_INCLUDE_DIRS ${include_dirs} PARENT_SCOPE) set(${library_name}_LIBRARY ${library_name} PARENT_SCOPE) # --- dependencies --- -message("XXX ${GQt_INCLUDE_DIRS} XXX") include_directories( ${ROOT_INCLUDE_DIR} ${GQt_INCLUDE_DIRS} @@ -32,6 +31,6 @@ include_directories( target_link_libraries(${library_name} ${ROOT_LIBRARIES}) -find_package(Qt5Widgets REQUIRED) +#find_package(Qt5Widgets REQUIRED) qt5_use_modules(${library_name} Widgets) diff --git a/GUI/externals/qt-root/CMakeLists.txt b/GUI/externals/qt-root/CMakeLists.txt index 61234ed4e39..758be6b4d1e 100644 --- a/GUI/externals/qt-root/CMakeLists.txt +++ b/GUI/externals/qt-root/CMakeLists.txt @@ -21,7 +21,7 @@ set(CMAKE_AUTOMOC ON) # inc/TQtClientGuard.h" "inc/TQtClientWidget.h" "inc/TQtTimer.h" # inc/TQtRootSlot.h) -find_package(Qt5Widgets REQUIRED) +#find_package(Qt5Widgets REQUIRED) ROOT_GENERATE_DICTIONARY(G__GQt ${headers} LINKDEF LinkDef.h) ROOT_GENERATE_DICTIONARY(AppDict inc/DrawHelper.h inc/TreeEventStructure.h LINKDEF AppLinkDef.h) -- GitLab