├── CMakeLists.txt ├── EntityDescriptorWidget.cpp ├── EntityDescriptorWidget.h ├── EntityDescriptorWidget.ui ├── ExpressTextEdit.cpp ├── ExpressTextEdit.h ├── ExpressViewDockWidget.cpp ├── ExpressViewDockWidget.h ├── MainWindow.cpp ├── MainWindow.h ├── MainWindow.ui ├── NavigateCommand.cpp ├── NavigateCommand.h ├── README.md ├── SCLDockWidget.cpp ├── SCLDockWidget.h ├── SCLView.pro ├── SchemaTree.cpp ├── SchemaTree.h ├── SchemaTreeDockWidget.cpp ├── SchemaTreeDockWidget.h ├── expressg ├── EntityItem.cpp ├── EntityItem.h ├── ExpressGScene.cpp ├── ExpressGScene.h ├── ExpressGView.cpp ├── ExpressGView.h ├── ExpressgRectItem.cpp ├── ExpressgRectItem.h ├── LinkItem.cpp ├── LinkItem.h ├── TypeItem.cpp └── TypeItem.h ├── icones ├── Express.png ├── ListView.png ├── SCLView.svg ├── Schema.png ├── TreeView.png ├── WhiteRect.png ├── attribute.png ├── close.png ├── find.png ├── redo.png ├── type.png └── undo.png ├── main.cpp ├── manhattanstyle.cpp ├── manhattanstyle.h ├── sclview.qrc ├── styleanimator.cpp ├── styleanimator.h └── textView ├── ExpressSyntaxHighlighter.cpp ├── ExpressSyntaxHighlighter.h ├── ExpressTextEdit.cpp ├── ExpressTextEdit.h ├── ExpressViewDockWidget.cpp └── ExpressViewDockWidget.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # This file is part of [To be named], a STEP-Express viewer 2 | # Copyright (C) 2012 Mark Pictor mpictor@gmail.com 3 | # 4 | # This library is free software; you can redistribute it and/or 5 | # modify it under the terms of the GNU Library General Public 6 | # License as published by the Free Software Foundation; version 2 7 | # of the License. 8 | # 9 | # This library is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | # Library General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU Library General Public License 15 | # along with this library; see the file COPYING.LIB. If not, write to 16 | # the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | # Boston, MA 02110-1301, USA. 18 | 19 | PROJECT( SCView ) 20 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8) 21 | 22 | set( CMAKE_BUILD_TYPE "Debug" ) 23 | set( SCL_IS_SUBBUILD TRUE ) 24 | set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib ) 25 | set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) 26 | 27 | # qt4 28 | find_package( Qt4 REQUIRED QtCore QtGui QtOpenGL ) 29 | include( ${QT_USE_FILE} ) 30 | add_definitions( ${QT4_DEFINITIONS} ) 31 | 32 | # STEPcode 33 | set( STEPCODE_ROOT_DIR "" CACHE PATH "Path to STEPcode, required" ) 34 | if( NOT IS_DIRECTORY ${STEPCODE_ROOT_DIR} ) 35 | message( FATAL_ERROR "STEPcode root dir must be set, either through the GUI or on the command line with '-DSTEPCODE_ROOT_DIR=/path/to/sc'" ) 36 | endif( NOT IS_DIRECTORY ${STEPCODE_ROOT_DIR} ) 37 | set( STEPCODE_BUILD_DIR ${CMAKE_BINARY_DIR}/sc CACHE PATH "STEPcode build subdir" ) 38 | 39 | # schemas 40 | if( NOT DEFINED SCHEMAS ) 41 | set( SCHEMAS "ap214e3" CACHE STRING "Schema(s) to compile and link to; use the names of directories under STEPcode/data." ) 42 | message( "** SCHEMAS undefined. Using ${SCHEMAS}" ) 43 | endif( NOT DEFINED SCHEMAS ) 44 | set( SCL_BUILD_SCHEMAS ${SCHEMAS} CACHE INTERNAL "Schema, internal, immutable" FORCE ) 45 | add_subdirectory( ${STEPCODE_ROOT_DIR} "${CMAKE_CURRENT_BINARY_DIR}/sc" EXCLUDE_FROM_ALL ) 46 | 47 | # QT ui files and MOCable headers 48 | set( MOC_HDRS 49 | MainWindow.h EntityDescriptorWidget.h SCLDockWidget.h expressg/ExpressGView.h 50 | expressg/ExpressGScene.h EntityTypeList.h manhattanstyle.h styleanimator.h 51 | ExpressViewDockWidget.h ExpressTextEdit.h ExpressSyntaxHighlighter.h 52 | ) 53 | set( UI_FILES 54 | EntityDescriptorWidget.ui MainWindow.ui 55 | ) 56 | set( RESOURCE_FILES sclview.qrc ) 57 | QT4_WRAP_UI( UI_HDRS ${UI_FILES} ) 58 | QT4_WRAP_CPP( MOC_SRCS ${MOC_HDRS} ) 59 | QT4_ADD_RESOURCES( RESOURCE_SRCS ${RESOURCE_FILES} ) 60 | 61 | # app sources and headers 62 | set( SRCS 63 | EntityDescriptorWidget.cpp expressg/ExpressGView.cpp manhattanstyle.cpp 64 | SchemaTree.cpp expressg/LinkItem.cpp NavigateCommand.cpp 65 | expressg/EntityItem.cpp expressg/TypeItem.cpp SCLDockWidget.cpp 66 | expressg/ExpressgRectItem.cpp main.cpp styleanimator.cpp 67 | expressg/ExpressGScene.cpp MainWindow.cpp ExpressViewDockWidget.cpp 68 | ExpressTextEdit.cpp ExpressSyntaxHighlighter.cpp 69 | ) 70 | 71 | set( HDRS 72 | EntityDescriptorWidget.h expressg/ExpressGView.h NavigateCommand.cpp 73 | SchemaTree.h expressg/LinkItem.h SCLDockWidget.h 74 | expressg/EntityItem.h expressg/TypeItem.h styleanimator.h 75 | expressg/ExpressgRectItem.h MainWindow.h 76 | expressg/ExpressGScene.h manhattanstyle.h 77 | ExpressViewDockWidget.h ExpressTextEdit.h ExpressSyntaxHighlighter.h 78 | ) 79 | include_directories( ${STEPCODE_ROOT_DIR}/src/base ${STEPCODE_ROOT_DIR}/src/clstepcore 80 | ${STEPCODE_ROOT_DIR}/src/cldai ${STEPCODE_ROOT_DIR}/src/clutils 81 | ${STEPCODE_ROOT_DIR}/src/cleditor ${STEPCODE_BUILD_DIR}/include 82 | ${STEPCODE_ROOT_DIR}/include ${CMAKE_BINARY_DIR} ) 83 | 84 | # this function builds SCView for a single schema 85 | function( BUILD_SCVIEW schema ) 86 | # Set SCHEMA_LINK_NAME. Logic below is derived from STEPcode/data/CMakeLists.txt; I (MP) am the author. 87 | # lib will be in ${CMAKE_BINARY_DIR}/lib/, named sdai_${SCHEMA_LINK_NAME}. Prefix/suffix depend on platform, of course. 88 | # lib source will be at ${CMAKE_BINARY_DIR}/${SCHEMA_LINK_NAME}/ 89 | file( GLOB SCHEMA_FILE "${STEPCODE_ROOT_DIR}/data/${schema}/*.exp" ) 90 | if( NOT EXISTS ${SCHEMA_FILE} ) 91 | message( FATAL_ERROR "Expected one express file. Found '${SCHEMA_FILE}' instead." ) 92 | endif( NOT EXISTS ${SCHEMA_FILE} ) 93 | get_filename_component( SCHEMA_SN ${SCHEMA_FILE} NAME ) 94 | string( REGEX REPLACE "\(.*\).[Ee][Xx][Pp]" "\\1" SCHEMA_LINK_NAME ${SCHEMA_SN} ) 95 | 96 | message( "** Building ${PROJECT_NAME} for ${SCHEMA_LINK_NAME}" ) 97 | add_executable( ${PROJECT_NAME}_${SCHEMA_LINK_NAME} ${SRCS} ${HDRS} ${UI_HDRS} ${MOC_SRCS} ${RESOURCE_SRCS} ) 98 | target_link_libraries( ${PROJECT_NAME}_${SCHEMA_LINK_NAME} ${QT_LIBRARIES} base stepcore stepeditor stepdai steputils sdai_${SCHEMA_LINK_NAME} ) 99 | #can't use include_directories for the schema headers because each target would see the headers from all previous targets 100 | set_target_properties( ${PROJECT_NAME}_${SCHEMA_LINK_NAME} PROPERTIES COMPILE_FLAGS "-I${STEPCODE_BUILD_DIR}/data/${SCHEMA_LINK_NAME}" ) 101 | endfunction( BUILD_SCVIEW schema ) 102 | 103 | foreach( schema ${SCHEMAS} ) 104 | BUILD_SCVIEW( ${schema} ) 105 | endforeach( schema ${SCHEMAS} ) 106 | -------------------------------------------------------------------------------- /EntityDescriptorWidget.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "EntityDescriptorWidget.h" 21 | #include "ui_EntityDescriptorWidget.h" 22 | 23 | #include 24 | using namespace std; 25 | 26 | EntityDescriptorWidget::EntityDescriptorWidget(QWidget *parent) : 27 | QWidget(parent), 28 | ui(new Ui::EntityDescriptorWidget) 29 | { 30 | ui->setupUi(this); 31 | connect (ui->attrListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(findEntityDescriptor(QListWidgetItem*))); 32 | connect (ui->typeListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(findEntityDescriptor(QListWidgetItem*))); 33 | connect (ui->attrListWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(findEntityDescriptor(QListWidgetItem*))); 34 | } 35 | 36 | EntityDescriptorWidget::~EntityDescriptorWidget() 37 | { 38 | delete ui; 39 | } 40 | 41 | void EntityDescriptorWidget::fill(EntityDescriptor *ed) 42 | { 43 | QListWidget * attrListWidget = ui->attrListWidget; 44 | QListWidget * typeListWidget = ui->typeListWidget; 45 | attrListWidget->clear(); 46 | typeListWidget->clear(); 47 | ui->nameLineEdit->setText(QString(ed->Name())); 48 | 49 | // adapted from clprobe-ui/stepentdescriptor.cc 50 | const AttrDescriptorList * attrList = &( ( ( EntityDescriptor * )ed )->ExplicitAttr() ); 51 | 52 | int attrCount = attrList->EntryCount(); 53 | cout << "-----------------------------" << endl; 54 | cout << "attr entries =" << attrCount << endl; 55 | 56 | std::string str; 57 | 58 | AttrDescLinkNode * attrPtr = ( AttrDescLinkNode * )attrList->GetHead(); 59 | while( attrPtr != 0 ) { 60 | str.clear(); 61 | 62 | const AttrDescriptor * ad = attrPtr->AttrDesc(); 63 | /* 64 | if( ad->Derived() == LTrue ) { 65 | str.append( "<" ); 66 | } 67 | std::string tmp; 68 | str.append( ad->AttrExprDefStr( tmp ) ); 69 | if( ad->Derived() == LTrue ) { 70 | str.append( ">" ); 71 | } 72 | */ 73 | str.append(ad->Name()); 74 | str.append(" : "); 75 | str.append(ad->TypeName()); 76 | 77 | QString attrText = str.c_str(); 78 | QListWidgetItem * item = new QListWidgetItem(attrText,ui->attrListWidget); 79 | ui->attrListWidget->addItem(item); 80 | 81 | // tests 82 | // BUG SCL: ad->BaseTypeDescriptor() : .cpp undefined 83 | cout << "baseType =" << ad->BaseType() << endl; 84 | cout << "Type =" << ad->Type() << endl; 85 | cout << "Type->Name =" << ad->TypeName() << endl; 86 | cout << "DomainType->Name =" << ad->DomainType()->Name() << endl; 87 | cout << "NonRefType->Name =" << ad->NonRefTypeDescriptor()->Name() << endl; 88 | cout << "ReferentType->Name =" << ad->ReferentType()->Name() << endl; 89 | cout << "Type->Name =" << ad->Type() << endl; 90 | 91 | 92 | const EntityDescriptor * attrEd = dynamic_cast (ad->ReferentType() ); 93 | if (attrEd) 94 | { 95 | // store the EntityDescriptor 96 | void* voidAttrEd=(void*) attrEd; 97 | item->setData(Qt::UserRole,QVariant::fromValue(voidAttrEd) ); 98 | item->setIcon(QIcon(":/type")); 99 | } 100 | else 101 | item->setIcon(QIcon(":/attribute")); 102 | 103 | // cout << str << endl; 104 | attrPtr = ( AttrDescLinkNode * )attrPtr->NextNode(); 105 | } 106 | 107 | 108 | // types 109 | const EntityDescriptorList * subtypeList = &( ( ( EntityDescriptor * )ed )->Subtypes() ); 110 | int subTypeCount = subtypeList->EntryCount(); 111 | cout << "sub type entries =" << subTypeCount << endl; 112 | EntityDescLinkNode * subtypePtr = 113 | ( EntityDescLinkNode * )subtypeList->GetHead(); 114 | while( subtypePtr != 0 ) { 115 | str.clear(); 116 | str.append(subtypePtr->EntityDesc()->Name()); 117 | QString subTypeText = str.c_str(); 118 | 119 | QListWidgetItem * item = new QListWidgetItem(subTypeText,typeListWidget); 120 | typeListWidget->addItem(item); 121 | 122 | EntityDescriptor * subTypeEd = subtypePtr->EntityDesc(); 123 | // store the EntityDescriptor 124 | void* voidSubTypeEd=(void*) subTypeEd; 125 | item->setData(Qt::UserRole,QVariant::fromValue(voidSubTypeEd) ); 126 | item->setIcon(QIcon(":/type")); 127 | 128 | subtypePtr = ( EntityDescLinkNode * )subtypePtr->NextNode(); 129 | } 130 | 131 | 132 | } 133 | 134 | void EntityDescriptorWidget::findEntityDescriptor(QListWidgetItem * item) 135 | { 136 | // MOCHE 137 | EntityDescriptor * desc = (EntityDescriptor *) item->data(Qt::UserRole).value(); 138 | if (desc) 139 | emit entityDescriptorDoubleClicked(desc); 140 | } 141 | -------------------------------------------------------------------------------- /EntityDescriptorWidget.h: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef ENTITYDESCRIPTORWIDGET_H 21 | #define ENTITYDESCRIPTORWIDGET_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace Ui { 28 | class EntityDescriptorWidget; 29 | } 30 | 31 | class EntityDescriptorWidget : public QWidget 32 | { 33 | Q_OBJECT 34 | 35 | public: 36 | explicit EntityDescriptorWidget(QWidget *parent = 0); 37 | ~EntityDescriptorWidget(); 38 | 39 | public slots: 40 | void fill(EntityDescriptor* ed); 41 | void findEntityDescriptor(QListWidgetItem* item); 42 | 43 | signals: 44 | void entityDescriptorDoubleClicked( EntityDescriptor * ); 45 | private: 46 | Ui::EntityDescriptorWidget *ui; 47 | }; 48 | 49 | #endif // ENTITYDESCRIPTORWIDGET_H 50 | -------------------------------------------------------------------------------- /EntityDescriptorWidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | EntityDescriptorWidget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 592 10 | 300 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | name 23 | 24 | 25 | 26 | 27 | 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Qt::Horizontal 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /ExpressTextEdit.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ExpressTextEdit.h" 21 | #include "ExpressSyntaxHighlighter.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | ExpressTextEdit::ExpressTextEdit(Registry ®istry, QWidget *parent) 28 | : QTextEdit(parent) 29 | , m_Registry(registry) 30 | , m_Highlighter ( new ExpressSyntaxHighlighter(this->document())) 31 | { 32 | setMouseTracking(true); 33 | } 34 | 35 | void ExpressTextEdit::fillHighlighterWithTypes(const QStringList &list) 36 | { 37 | m_Highlighter->fillTypes(list); 38 | } 39 | 40 | void ExpressTextEdit::fillHighlighterWithEntities(const QStringList &list) 41 | { 42 | m_Highlighter->fillEntities(list); 43 | } 44 | 45 | void ExpressTextEdit::mouseMoveEvent(QMouseEvent *e) 46 | { 47 | QTextCursor cursor = cursorForPosition(e->pos()); 48 | cursor.select(QTextCursor::WordUnderCursor); 49 | QString wordUnderCursor = cursor.selectedText(); 50 | 51 | const EntityDescriptor * entityDescriptor = m_Registry.FindEntity(wordUnderCursor.toAscii()); 52 | const TypeDescriptor * typeDescriptor = m_Registry.FindType(wordUnderCursor.toAscii()); 53 | if (entityDescriptor ) 54 | { 55 | std::string str; 56 | setToolTip(entityDescriptor->GenerateExpress(str)); 57 | if (QApplication::overrideCursor()==0) 58 | QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); 59 | } 60 | else if(typeDescriptor) 61 | { 62 | std::string str; 63 | setToolTip(typeDescriptor->GenerateExpress(str)); 64 | if (QApplication::overrideCursor()==0) 65 | QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); 66 | } 67 | else 68 | { 69 | setToolTip(QString()); 70 | QApplication::restoreOverrideCursor(); 71 | } 72 | } 73 | 74 | void ExpressTextEdit::mousePressEvent(QMouseEvent *e) 75 | { 76 | if (e->modifiers()==Qt::ControlModifier) 77 | { 78 | QTextEdit::mousePressEvent(e); 79 | navigate(e); 80 | } 81 | } 82 | 83 | void ExpressTextEdit::mouseDoubleClickEvent(QMouseEvent *e) 84 | { 85 | navigate(e); 86 | QTextEdit::mouseDoubleClickEvent(e); 87 | } 88 | 89 | void ExpressTextEdit::leaveEvent(QEvent *e) 90 | { 91 | QApplication::restoreOverrideCursor(); 92 | } 93 | 94 | void ExpressTextEdit::setDescriptor(const TypeDescriptor *typeDescriptor) 95 | { 96 | clear(); 97 | if (typeDescriptor) 98 | { 99 | std::string str; 100 | QString text(typeDescriptor->GenerateExpress(str)); 101 | setPlainText(text); 102 | } 103 | } 104 | 105 | void ExpressTextEdit::navigate(QMouseEvent *e) 106 | { 107 | // QTextCursor cursor = textCursor(); 108 | QTextCursor cursor = cursorForPosition(e->pos()); 109 | cursor.select(QTextCursor::WordUnderCursor); 110 | QString wordUnderCursor = cursor.selectedText(); 111 | 112 | const EntityDescriptor * entityDescriptor = m_Registry.FindEntity(wordUnderCursor.toAscii()); 113 | const TypeDescriptor * typeDescriptor = m_Registry.FindType(wordUnderCursor.toAscii()); 114 | if (entityDescriptor ) 115 | emit descriptorDoubleClicked(entityDescriptor); 116 | else if(typeDescriptor) 117 | emit descriptorDoubleClicked(typeDescriptor); 118 | } 119 | 120 | -------------------------------------------------------------------------------- /ExpressTextEdit.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef EXPRESSTEXTEDIT_H 21 | #define EXPRESSTEXTEDIT_H 22 | 23 | #include 24 | 25 | class Registry; 26 | class EntityDescriptor; 27 | class TypeDescriptor; 28 | class ExpressSyntaxHighlighter; 29 | 30 | class ExpressTextEdit : public QTextEdit 31 | { 32 | Q_OBJECT 33 | public: 34 | explicit ExpressTextEdit(Registry ®istry, QWidget *parent=0); 35 | void fillHighlighterWithTypes(const QStringList &list); 36 | void fillHighlighterWithEntities(const QStringList &list); 37 | 38 | protected: 39 | virtual void mouseMoveEvent(QMouseEvent *e); 40 | virtual void mousePressEvent(QMouseEvent *e); 41 | virtual void mouseDoubleClickEvent(QMouseEvent *e); 42 | virtual void leaveEvent(QEvent *e); 43 | 44 | signals: 45 | void descriptorDoubleClicked(const TypeDescriptor *); 46 | 47 | public slots: 48 | void setDescriptor(const TypeDescriptor * typeDescriptor); 49 | 50 | private: 51 | void navigate(QMouseEvent *e); 52 | 53 | 54 | private: 55 | Registry &m_Registry; 56 | ExpressSyntaxHighlighter * m_Highlighter; 57 | }; 58 | 59 | #endif // EXPRESSTEXTEDIT_H 60 | -------------------------------------------------------------------------------- /ExpressViewDockWidget.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ExpressViewDockWidget.h" 21 | #include "ExpressTextEdit.h" 22 | #include 23 | #include 24 | 25 | ExpressViewDockWidget::ExpressViewDockWidget(QWidget *parent) 26 | : QDockWidget(tr("Express View"), parent) 27 | , m_ToolBar (new QToolBar(this)) 28 | { 29 | // Build ToolBar 30 | setTitleBarWidget(m_ToolBar); 31 | m_ToolBar->setContentsMargins(0, 0, 0, 0); 32 | toggleViewAction()->setIcon(QIcon(":/Express")); 33 | toggleViewAction()->setShortcut( QKeySequence(Qt::Key_F4) ); 34 | 35 | QWidget * toolBarSpacer= new QWidget(m_ToolBar); 36 | toolBarSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); 37 | QAction * hideDockWidgetAction = new QAction(QIcon(":close"), tr("Hide Explorer"), this); 38 | 39 | m_ToolBar->addWidget(toolBarSpacer); 40 | m_ToolBar->addAction(hideDockWidgetAction); 41 | 42 | connect ( hideDockWidgetAction, SIGNAL(triggered()), this, SLOT (hide() ) ); 43 | 44 | // content 45 | setContentsMargins(0,0,-1,0); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /ExpressViewDockWidget.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef EXPRESSVIEWDOCKWIDGET_H 21 | #define EXPRESSVIEWDOCKWIDGET_H 22 | 23 | #include 24 | 25 | class ExpressTextEdit; 26 | class QToolBar; 27 | 28 | class ExpressViewDockWidget : public QDockWidget 29 | { 30 | Q_OBJECT 31 | public: 32 | explicit ExpressViewDockWidget(QWidget *parent = 0); 33 | 34 | signals: 35 | 36 | public slots: 37 | 38 | private: 39 | QToolBar * m_ToolBar; 40 | 41 | }; 42 | 43 | #endif // EXPRESSVIEWDOCKWIDGET_H 44 | -------------------------------------------------------------------------------- /MainWindow.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ui_MainWindow.h" 21 | #include "MainWindow.h" 22 | #include "SchemaTreeDockWidget.h" 23 | #include "textView/ExpressViewDockWidget.h" 24 | #include "textView/ExpressTextEdit.h" 25 | #include "SchemaTree.h" 26 | #include "expressg/ExpressGView.h" 27 | #include "NavigateCommand.h" 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | MainWindow::MainWindow(QWidget *parent) 37 | : QMainWindow(parent) 38 | , ui(new Ui::MainWindow) 39 | , m_UndoStack(new QUndoStack(this)) 40 | , m_Registry( SchemaInit ) 41 | , m_Current(0) 42 | , m_SchemaTree ( new SchemaTree(&m_Registry) ) 43 | , m_SchemaTreeDockWidget (new SchemaTreeDockWidget(m_SchemaTree, this) ) 44 | , m_ExpressViewDockWidget( new ExpressViewDockWidget(this)) 45 | , m_ExpressTextEdit(new ExpressTextEdit(&m_Registry, m_ExpressViewDockWidget)) 46 | , m_ExpressGView (new ExpressGView(this)) 47 | , m_StringListModel(new QStringListModel()) 48 | , m_SearchLineEdit(0) 49 | { 50 | ui->setupUi(this); 51 | 52 | 53 | m_Registry.ResetSchemas(); 54 | const Schema * sc = m_Registry.NextSchema(); 55 | QString title = QApplication::applicationName()+ ": " + QString(sc->Name()); 56 | setWindowTitle( title ); 57 | buildView(); 58 | setCentralWidget(m_ExpressGView); 59 | 60 | connect(m_ExpressGView, SIGNAL(descriptorDoubleClicked(const TypeDescriptor*)) 61 | , this, SLOT(setDescriptorCommand(const TypeDescriptor*))); 62 | connect(m_SchemaTree, SIGNAL(selectedDescriptorChanged(const TypeDescriptor*)) 63 | , this, SLOT(setDescriptorCommand(const TypeDescriptor*))); 64 | connect(m_ExpressTextEdit, SIGNAL(descriptorDoubleClicked(const TypeDescriptor*)) 65 | , this, SLOT(setDescriptorCommand(const TypeDescriptor*))); 66 | 67 | connect(ui->actionFind, SIGNAL(triggered()), this, SLOT (startSearch())); 68 | 69 | QAction * undoAction = m_UndoStack->createUndoAction(this); 70 | QAction * redoAction = m_UndoStack->createRedoAction(this); 71 | undoAction->setIcon(QIcon(":Undo")); 72 | redoAction->setIcon(QIcon(":Redo")); 73 | undoAction->setShortcut(QKeySequence(tr("Ctrl+Z"))); 74 | redoAction->setShortcut(QKeySequence(tr("Ctrl+Y"))); 75 | ui->mainToolBar->addAction(undoAction); 76 | ui->mainToolBar->addAction(redoAction); 77 | ui->menuEdit->insertAction(ui->actionFind,redoAction); 78 | ui->menuEdit->insertAction(redoAction,undoAction); 79 | } 80 | 81 | MainWindow::~MainWindow() 82 | { 83 | delete ui; 84 | } 85 | 86 | QStringList MainWindow::typeList() 87 | { 88 | QStringList list; 89 | const TypeDescriptor * typeDescriptor; 90 | m_Registry.ResetTypes(); 91 | while ( (typeDescriptor= m_Registry.NextType() ) ) 92 | list << typeDescriptor->Name(); 93 | return list; 94 | } 95 | 96 | QStringList MainWindow::entityList() 97 | { 98 | QStringList list; 99 | const EntityDescriptor * entityDescriptor; 100 | m_Registry.ResetEntities(); 101 | while ( (entityDescriptor= m_Registry.NextEntity() ) ) 102 | list << entityDescriptor->Name(); 103 | return list; 104 | } 105 | 106 | void MainWindow::setDescriptor(const TypeDescriptor *descriptor) 107 | { 108 | m_SchemaTree->select(descriptor); 109 | m_ExpressGView->setDescriptor(descriptor); 110 | m_ExpressTextEdit->setDescriptor(descriptor); 111 | } 112 | 113 | void MainWindow::startSearch() 114 | { 115 | m_SearchLineEdit->setFocus(); 116 | m_SearchLineEdit->clear(); 117 | } 118 | 119 | void MainWindow::selectSearchResult(QString highlighted) 120 | { 121 | QList results = m_SchemaTree->findItems(highlighted, Qt::MatchFixedString |Qt::MatchCaseSensitive| Qt::MatchRecursive); 122 | if (!results.isEmpty()) 123 | { 124 | QTreeWidgetItem * item = results.first(); 125 | m_SchemaTree->clearSelection(); 126 | item->setSelected(true); 127 | m_SchemaTree->expandItem(item); 128 | m_SchemaTree->scrollToItem(item); 129 | } 130 | } 131 | 132 | void MainWindow::setDescriptorCommand(const TypeDescriptor *descriptor) 133 | { 134 | 135 | NavigateCommand * navigateCommand = new NavigateCommand(this, m_Current, descriptor); 136 | m_UndoStack->push(navigateCommand); 137 | m_Current = descriptor; 138 | } 139 | 140 | void MainWindow::buildView() 141 | { 142 | addDockWidget(Qt::LeftDockWidgetArea, m_SchemaTreeDockWidget); 143 | ui->menuWindows->addAction(m_SchemaTreeDockWidget->toggleViewAction()); 144 | 145 | m_ExpressViewDockWidget->setWidget(m_ExpressTextEdit); 146 | addDockWidget(Qt::LeftDockWidgetArea, m_ExpressViewDockWidget); 147 | ui->menuWindows->addAction(m_ExpressViewDockWidget->toggleViewAction()); 148 | 149 | // Search 150 | QWidget * searchWidget = new QWidget(ui->menuBar); 151 | m_SearchLineEdit = new QLineEdit(searchWidget); 152 | QLabel * label = new QLabel(searchWidget); 153 | label->setPixmap(QPixmap(":/Find")); 154 | QHBoxLayout * layout = new QHBoxLayout(searchWidget); 155 | layout->addWidget(label); 156 | layout->addWidget(m_SearchLineEdit); 157 | layout->setContentsMargins(0,0,0,0); 158 | searchWidget->setLayout(layout); 159 | ui->menuBar->setCornerWidget(searchWidget); 160 | 161 | m_SchemaTree->fillStringListModel(m_StringListModel); 162 | m_SearchLineEdit->setText("Search"); 163 | QCompleter * completer = new QCompleter(m_StringListModel); 164 | completer->setMaxVisibleItems(10); 165 | completer->setCompletionMode(QCompleter::PopupCompletion); 166 | completer->setCaseSensitivity(Qt::CaseInsensitive); 167 | m_SearchLineEdit->setCompleter(completer); 168 | connect(completer, SIGNAL(highlighted(QString)), this, SLOT(selectSearchResult(QString))); 169 | 170 | } 171 | 172 | -------------------------------------------------------------------------------- /MainWindow.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef MAINWINDOW_H 21 | #define MAINWINDOW_H 22 | 23 | #include 24 | extern void SchemaInit( class Registry & ); 25 | #include 26 | class TypeDescriptor; 27 | 28 | class SchemaTreeDockWidget; 29 | class SchemaTree; 30 | class EntityDescriptorWidget; 31 | class ExpressGView; 32 | class ExpressGScene; 33 | class QLineEdit; 34 | class QStringListModel; 35 | class ExpressViewDockWidget; 36 | class ExpressTextEdit; 37 | class QUndoStack; 38 | 39 | namespace Ui { 40 | class MainWindow; 41 | } 42 | 43 | class MainWindow : public QMainWindow 44 | { 45 | Q_OBJECT 46 | 47 | public: 48 | explicit MainWindow(QWidget *parent = 0); 49 | ~MainWindow(); 50 | QStringList typeList(); 51 | QStringList entityList(); 52 | void setDescriptor(const TypeDescriptor *descriptor); 53 | 54 | private slots: 55 | void startSearch(); 56 | void selectSearchResult(QString highlighted); 57 | void setDescriptorCommand(const TypeDescriptor * descriptor); 58 | 59 | private: 60 | void buildView(); 61 | private: 62 | Ui::MainWindow *ui; 63 | QUndoStack * m_UndoStack; 64 | Registry m_Registry; 65 | const TypeDescriptor * m_Current; 66 | SchemaTree * m_SchemaTree; 67 | SchemaTreeDockWidget * m_SchemaTreeDockWidget; 68 | ExpressViewDockWidget * m_ExpressViewDockWidget; 69 | ExpressTextEdit * m_ExpressTextEdit; 70 | ExpressGView * m_ExpressGView; 71 | QStringListModel * m_StringListModel; 72 | QLineEdit * m_SearchLineEdit; 73 | 74 | }; 75 | 76 | #endif // MAINWINDOW_H 77 | -------------------------------------------------------------------------------- /MainWindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 0 21 | 0 22 | 800 23 | 21 24 | 25 | 26 | 27 | 28 | Windows 29 | 30 | 31 | 32 | 33 | Edit 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | TopToolBarArea 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | :/Find:/Find 53 | 54 | 55 | Find 56 | 57 | 58 | Ctrl+F 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /NavigateCommand.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "NavigateCommand.h" 21 | #include "MainWindow.h" 22 | #include 23 | 24 | #include 25 | using namespace std; 26 | 27 | NavigateCommand::NavigateCommand(MainWindow *controler, const TypeDescriptor *oldDescriptor, const TypeDescriptor *newDescriptor, QUndoCommand *parent) 28 | : QUndoCommand(parent) 29 | , m_Controler(controler) 30 | , m_OldDescriptor(oldDescriptor) 31 | , m_NewDescriptor(newDescriptor) 32 | { 33 | } 34 | 35 | void NavigateCommand::undo() 36 | { 37 | m_Controler->setDescriptor(m_OldDescriptor); 38 | } 39 | 40 | void NavigateCommand::redo() 41 | { 42 | m_Controler->setDescriptor(m_NewDescriptor); 43 | } 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /NavigateCommand.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef NAVIGATECOMMAND_H 21 | #define NAVIGATECOMMAND_H 22 | 23 | #include 24 | class TypeDescriptor; 25 | class MainWindow; 26 | 27 | class NavigateCommand : public QUndoCommand 28 | { 29 | public: 30 | NavigateCommand(MainWindow *controler, const TypeDescriptor *oldDescriptor, const TypeDescriptor *newDescriptor, QUndoCommand *parent=0); 31 | void undo(); 32 | void redo(); 33 | 34 | private: 35 | MainWindow * m_Controler; 36 | const TypeDescriptor *m_OldDescriptor, *m_NewDescriptor; 37 | }; 38 | 39 | #endif // NAVIGATECOMMAND_H 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SCView 2 | 3 | SCView is a Step Express data viewer
4 | SCView stands for [StepCode](http://stepcode.org/mw/index.php?title=STEPcode) View
5 | 6 | [![](https://github.com/LaurentBauer/SCView/wiki/img/SCLView.png)](https://youtu.be/ig9xq1H828M) 7 | 8 | ## Features 9 | 10 | ### One model 11 | * SCView stores one data model : the express schema 12 | * Multi models support may come (?) 13 | 14 | ### 3 views 15 | SCView delivers 3 views of the same model 16 | * The tree view 17 | * The Express-G view : a diagram based representation 18 | * The Express text view 19 | 20 | ### Search / find 21 | * At the top right corner of the window, the find function (Ctrl+F) provides search with completion
22 | 23 | 24 | ### Tree View 25 | 26 | 27 | * The top Item represents the schema. It has two children: 28 | * The list of entities 29 | * The list of types 30 | * Lists display their children 31 | 32 | **Navigation**
33 | Selecting one entity or type in the tree will display the selection in the two other views 34 | 35 | **Show / Hide** with F3 36 | 37 | ### The Express-G view 38 | 39 | 40 | * Delivers a diagram representation of the currently selected Entity
41 | * The composition structure is partially implemented 42 | * The inheritance view is NOT implemented 43 | * other features like cardinality, rules... are NOT implemented 44 | 45 | **Navigation**
46 | Double clicking one entity or type will display the selection in the two other views 47 | 48 | ### The Express Text Editor 49 | 50 | 51 | * Displays the selected entity/type in the Express format 52 | * Has a syntax highlighter 53 | * Is Read only : no edition features ! 54 | * Has mouse tracking over objects and popup as tooltip the express description 55 | * Provides Hypertext-like navigation 56 | 57 | **The Highlighter** 58 | * Types 59 | * Entities 60 | * Simple Types 61 | * Some keywords 62 | 63 | **Navigation**
64 | Double clicking one entity or type will display the selection in the two other views 65 | 66 | **Show / Hide** with F4 67 | 68 | ### Standard undo / redo 69 | * Undo with Ctrl+Z 70 | * Redo with Ctrl+Y 71 | * To navigate backward / forward 72 | 73 | ### Express-G supported features 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 97 | 101 | 102 | 103 | 104 | 105 | 107 | 111 | 112 | 113 | 114 | 115 | 121 | 125 | 126 | 127 | 128 | 129 | 133 | 137 | 138 | 139 |
Types and diagram representation
Type Description Express Definition Express-G Representation
Basic types Keywords
87 |
    88 |
  • INTEGER
  • 89 |
  • REAL
  • 90 |
  • BOOLEAN
  • 91 |
  • LOGICAL
  • 92 |
  • STRING
  • 93 |
  • BINARY
  • 94 |
  • NUMBER
  • 95 |
96 |
98 | Img: Basic type example 100 |
User Defined TYPE label = STRING;
106 | END_TYPE;
108 | Img: Defined type 110 |
SELECT TYPE curve_on_surface = select
116 | (pcurve,
117 | surface_curve,
118 | composite_curve_on_surface);
119 | END_TYPE;
120 |
122 | Img: Select type 124 |
ENUMERATION TYPE marker_type = ENUMERATION OF
130 | (dot, x, plus, asterisk, ring, square, triangle);
131 | END_TYPE; 132 |
134 | Img: Enum type 136 |
140 | 141 | 142 | 143 | ### And that's all for now... 144 | 145 | 146 | ## Dependencies 147 | Based on [STEP-Code](https://github.com/stepcode/stepcode) and [Qt](http://qt-project.org/) 148 | 149 | ## Warning: 150 | * Development version 151 | * Partial implementation of Express, especially Express-G 152 | * Use it for test, DO NOT use it in production / operation 153 | * Made for fun 154 | -------------------------------------------------------------------------------- /SCLDockWidget.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "SCLDockWidget.h" 21 | #include 22 | #include 23 | #include "SchemaTree.h" 24 | 25 | SCLDockWidget::SCLDockWidget(SchemaTree *tree, QWidget *parent) 26 | : QDockWidget ("Tree View", parent) 27 | , m_ToolBar (new QToolBar(this)) 28 | { 29 | 30 | setWidget(tree); 31 | // Build ToolBar 32 | setTitleBarWidget(m_ToolBar); 33 | m_ToolBar->setContentsMargins(0, 0, 0, 0); 34 | toggleViewAction()->setIcon(QIcon(":/Schema")); 35 | toggleViewAction()->setShortcut( QKeySequence(Qt::Key_F3) ); 36 | 37 | QWidget * toolBarSpacer= new QWidget(m_ToolBar); 38 | toolBarSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); 39 | QAction * hideDockWidgetAction = new QAction(QIcon(":close"), tr("Hide Explorer"), this); 40 | 41 | m_ToolBar->addWidget(toolBarSpacer); 42 | m_ToolBar->addAction(hideDockWidgetAction); 43 | 44 | connect ( hideDockWidgetAction, SIGNAL(triggered()), this, SLOT (hide() ) ); 45 | 46 | // content 47 | setContentsMargins(0,0,-1,0); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /SCLDockWidget.h: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef SCLDOCKWIDGET_H 21 | #define SCLDOCKWIDGET_H 22 | 23 | #include 24 | class QToolBar; 25 | class SchemaTree; 26 | 27 | class SCLDockWidget : public QDockWidget 28 | { 29 | Q_OBJECT 30 | public: 31 | explicit SCLDockWidget(SchemaTree * tree, QWidget *parent = 0); 32 | 33 | signals: 34 | 35 | public slots: 36 | 37 | private: 38 | QToolBar *m_ToolBar; 39 | }; 40 | 41 | #endif // SCLDOCKWIDGET_H 42 | -------------------------------------------------------------------------------- /SCLView.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2012-04-07T21:40:49 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui opengl 8 | 9 | TARGET = SCLView 10 | TEMPLATE = app 11 | 12 | STEPCODE_DIR = C:/prog/STEP/SCL0-5 13 | STEPCODE_BUILD_DIR = C:/prog/STEP/SCL0-5/ap214e3 14 | 15 | 16 | win32:LIBS += $${STEPCODE_BUILD_DIR}/bin/libsdai_AP214E3_2010.dll \ 17 | $${STEPCODE_BUILD_DIR}/bin/libstepcore.dll \ 18 | $${STEPCODE_BUILD_DIR}/bin/libstepdai.dll \ 19 | $${STEPCODE_BUILD_DIR}/bin/libsteputils.dll \ 20 | $${STEPCODE_BUILD_DIR}/bin/libexpress.dll \ 21 | $${STEPCODE_BUILD_DIR}/bin/libstepeditor.dll 22 | 23 | INCLUDEPATH += $${STEPCODE_BUILD_DIR}/AP214E3_2010 \ 24 | $${STEPCODE_BUILD_DIR}/include \ 25 | $${STEPCODE_DIR}/include \ 26 | $${STEPCODE_DIR}/src/cleditor \ 27 | $${STEPCODE_DIR}/src/clutils \ 28 | $${STEPCODE_DIR}/src/clstepcore \ 29 | $${STEPCODE_DIR}/src/cldai 30 | 31 | 32 | SOURCES += main.cpp\ 33 | MainWindow.cpp \ 34 | EntityDescriptorWidget.cpp \ 35 | manhattanstyle.cpp \ 36 | styleanimator.cpp \ 37 | expressg/ExpressGView.cpp \ 38 | expressg/ExpressGScene.cpp \ 39 | expressg/EntityItem.cpp \ 40 | expressg/TypeItem.cpp \ 41 | expressg/LinkItem.cpp \ 42 | expressg/ExpressgRectItem.cpp \ 43 | textView/ExpressViewDockWidget.cpp \ 44 | textView/ExpressTextEdit.cpp \ 45 | textView/ExpressSyntaxHighlighter.cpp \ 46 | SchemaTree.cpp \ 47 | NavigateCommand.cpp \ 48 | SchemaTreeDockWidget.cpp 49 | 50 | HEADERS += MainWindow.h \ 51 | EntityDescriptorWidget.h \ 52 | manhattanstyle.h \ 53 | styleanimator.h \ 54 | expressg/ExpressGView.h \ 55 | expressg/ExpressGScene.h \ 56 | expressg/EntityItem.h \ 57 | expressg/TypeItem.h \ 58 | expressg/LinkItem.h \ 59 | expressg/ExpressgRectItem.h \ 60 | textView/ExpressViewDockWidget.h \ 61 | textView/ExpressTextEdit.h \ 62 | textView/ExpressSyntaxHighlighter.h \ 63 | SchemaTree.h \ 64 | NavigateCommand.h \ 65 | SchemaTreeDockWidget.h 66 | 67 | FORMS += MainWindow.ui \ 68 | EntityDescriptorWidget.ui 69 | 70 | RESOURCES += \ 71 | sclview.qrc 72 | 73 | win32:CONFIG *= dll 74 | win32 { 75 | # Location libraries 76 | LIB_DIR = C:/prog/STEP/SCL0-5/ap214e3/bin 77 | } 78 | -------------------------------------------------------------------------------- /SchemaTree.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "SchemaTree.h" 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | using namespace std; 27 | 28 | enum itemType { 29 | EntityDescriptorItemType 30 | , TypeDescriptorItemType 31 | }; 32 | 33 | 34 | SchemaTree::SchemaTree(Registry *registry, QWidget *parent) 35 | : QTreeWidget(parent) 36 | , m_Registry( registry ) 37 | , m_EntityIcon(":/Entity") 38 | , m_TypeIcon(":/Type") 39 | { 40 | 41 | // L&F 42 | setAlternatingRowColors(true); 43 | setHeaderHidden(true); 44 | 45 | // Root : The Schema 46 | m_Registry->ResetSchemas(); 47 | const Schema * schema = m_Registry->NextSchema(); 48 | QTreeWidgetItem * rootItem = new QTreeWidgetItem (this); 49 | rootItem->setText(0, schema->Name()); 50 | rootItem->setIcon(0, QIcon(":/Schema")); 51 | 52 | 53 | //Fill Entities 54 | // Root for Entities 55 | QTreeWidgetItem * entitiesItem = new QTreeWidgetItem (rootItem); 56 | entitiesItem->setText(0,tr("Entities") ); 57 | entitiesItem->setIcon(0, m_EntityIcon); 58 | // all entities 59 | const EntityDescriptor * entityDescriptor; 60 | while ( (entityDescriptor= m_Registry->NextEntity() ) ) 61 | { 62 | QTreeWidgetItem * entityItem = new QTreeWidgetItem(entitiesItem, EntityDescriptorItemType); 63 | entityItem->setText(0,entityDescriptor->Name()); 64 | entityItem->setIcon(0,m_EntityIcon); 65 | void* voidEntityDescriptor=(void*) entityDescriptor; 66 | entityItem->setData(0,Qt::UserRole,QVariant::fromValue(voidEntityDescriptor) ); 67 | m_DescriptorToItem.insert(voidEntityDescriptor, entityItem); 68 | } 69 | 70 | //Fill Types 71 | // Root for types 72 | QTreeWidgetItem * typesItem = new QTreeWidgetItem (rootItem); 73 | typesItem->setText(0,tr("Types") ); 74 | typesItem->setIcon(0, m_TypeIcon); 75 | // all types 76 | const TypeDescriptor * typeDescriptor; 77 | while ( (typeDescriptor= m_Registry->NextType() ) ) 78 | { 79 | QTreeWidgetItem * typeItem = new QTreeWidgetItem(typesItem, TypeDescriptorItemType); 80 | typeItem->setText(0,typeDescriptor->Name()); 81 | typeItem->setIcon (0,m_TypeIcon); 82 | void* voidTypeDescriptor=(void*) typeDescriptor; 83 | typeItem->setData(0,Qt::UserRole,QVariant::fromValue(voidTypeDescriptor) ); 84 | m_DescriptorToItem.insert(voidTypeDescriptor, typeItem); 85 | } 86 | 87 | sortItems(0,Qt::AscendingOrder); 88 | connect (this, SIGNAL(itemSelectionChanged()), this, SLOT(findSelection())); 89 | } 90 | 91 | void SchemaTree::fillStringListModel(QStringListModel *model) 92 | { 93 | QHash ::const_iterator it ; 94 | QStringList list; 95 | for (it = m_DescriptorToItem.constBegin(); it != m_DescriptorToItem.constEnd(); ++it) 96 | list << it.value()->text(0); 97 | model->setStringList(list); 98 | } 99 | 100 | void SchemaTree::findSelection() 101 | { 102 | if (selectedItems().count()>0) 103 | { 104 | QTreeWidgetItem * item = selectedItems().first(); 105 | int itemType = item->type(); 106 | if ((itemType==EntityDescriptorItemType) || (itemType==TypeDescriptorItemType) ) 107 | { 108 | TypeDescriptor * desc = (TypeDescriptor *) item->data(0,Qt::UserRole).value(); 109 | if (desc) 110 | emit selectedDescriptorChanged(desc); 111 | } 112 | } 113 | } 114 | 115 | void SchemaTree::select(const TypeDescriptor *td) 116 | { 117 | blockSignals(true); 118 | if (m_DescriptorToItem.contains(td)) 119 | { 120 | clearSelection(); 121 | QTreeWidgetItem * item = m_DescriptorToItem.value(td); 122 | item->setSelected(true); 123 | if (selectedItems().size() >0) 124 | scrollToItem(selectedItems().at(0)); 125 | } 126 | blockSignals(false); 127 | } 128 | 129 | -------------------------------------------------------------------------------- /SchemaTree.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef ENTITYTYPELIST_H 21 | #define ENTITYTYPELIST_H 22 | 23 | #include 24 | #include 25 | #include 26 | class Registry; 27 | class TypeDescriptor; 28 | 29 | class QStringListModel; 30 | 31 | // EntityTypeList : actually is the EntityDescriptorList... should be renamed 32 | class SchemaTree : public QTreeWidget 33 | { 34 | Q_OBJECT 35 | public: 36 | explicit SchemaTree(Registry * registry, QWidget *parent = 0); 37 | void fillStringListModel(QStringListModel * model); 38 | 39 | signals: 40 | void selectedDescriptorChanged(const TypeDescriptor *); 41 | 42 | public slots: 43 | void findSelection(); 44 | void select( const TypeDescriptor *td); 45 | 46 | private: 47 | Registry * m_Registry; 48 | QHash m_DescriptorToItem; 49 | QIcon m_EntityIcon; 50 | QIcon m_TypeIcon; 51 | }; 52 | 53 | #endif // ENTITYTYPELIST_H 54 | -------------------------------------------------------------------------------- /SchemaTreeDockWidget.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "SchemaTreeDockWidget.h" 21 | #include 22 | #include 23 | #include "SchemaTree.h" 24 | 25 | SchemaTreeDockWidget::SchemaTreeDockWidget(SchemaTree *tree, QWidget *parent) 26 | : QDockWidget ("Tree View", parent) 27 | , m_ToolBar (new QToolBar(this)) 28 | { 29 | 30 | setWidget(tree); 31 | // Build ToolBar 32 | setTitleBarWidget(m_ToolBar); 33 | m_ToolBar->setContentsMargins(0, 0, 0, 0); 34 | toggleViewAction()->setIcon(QIcon(":/Schema")); 35 | toggleViewAction()->setShortcut( QKeySequence(Qt::Key_F3) ); 36 | 37 | QWidget * toolBarSpacer= new QWidget(m_ToolBar); 38 | toolBarSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); 39 | QAction * hideDockWidgetAction = new QAction(QIcon(":close"), tr("Hide Explorer"), this); 40 | 41 | m_ToolBar->addWidget(toolBarSpacer); 42 | m_ToolBar->addAction(hideDockWidgetAction); 43 | 44 | connect ( hideDockWidgetAction, SIGNAL(triggered()), this, SLOT (hide() ) ); 45 | 46 | // content 47 | setContentsMargins(0,0,-1,0); 48 | } 49 | 50 | -------------------------------------------------------------------------------- /SchemaTreeDockWidget.h: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef SCLDOCKWIDGET_H 21 | #define SCLDOCKWIDGET_H 22 | 23 | #include 24 | class QToolBar; 25 | class SchemaTree; 26 | 27 | class SchemaTreeDockWidget : public QDockWidget 28 | { 29 | Q_OBJECT 30 | public: 31 | explicit SchemaTreeDockWidget(SchemaTree * tree, QWidget *parent = 0); 32 | 33 | signals: 34 | 35 | public slots: 36 | 37 | private: 38 | QToolBar *m_ToolBar; 39 | }; 40 | 41 | #endif // SCLDOCKWIDGET_H 42 | -------------------------------------------------------------------------------- /expressg/EntityItem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/expressg/EntityItem.cpp -------------------------------------------------------------------------------- /expressg/EntityItem.h: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | #ifndef ENTITYITEM_H 22 | #define ENTITYITEM_H 23 | 24 | #include 25 | 26 | class EntityDescriptor; 27 | 28 | class EntityItem : public QGraphicsRectItem 29 | { 30 | 31 | public: 32 | enum { Type = UserType + 1 }; 33 | explicit EntityItem(const EntityDescriptor *entityDescriptor, QGraphicsItem *parent=0, QPointF pos=QPointF()); 34 | inline const EntityDescriptor * entityDescriptor() {return m_ED; } 35 | inline int type() const { return Type; } // Enable the use of qgraphicsitem_cast with this item. 36 | 37 | private: 38 | const EntityDescriptor * m_ED; 39 | }; 40 | 41 | #endif // ENTITYITEM_H 42 | -------------------------------------------------------------------------------- /expressg/ExpressGScene.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ExpressGScene.h" 21 | #include "EntityItem.h" 22 | #include "TypeItem.h" 23 | 24 | #include 25 | using namespace std; 26 | 27 | ExpressGScene::ExpressGScene(QObject *parent) : 28 | QGraphicsScene(parent) 29 | { 30 | } 31 | 32 | QGraphicsItem *ExpressGScene::setDescriptor(const TypeDescriptor *td) 33 | { 34 | clear(); 35 | if (td) 36 | { 37 | const EntityDescriptor *ed = dynamic_cast (td); 38 | if (ed) 39 | { 40 | EntityItem * edItem = new EntityItem(ed); 41 | edItem->setPos(0.0,0.0); 42 | addItem(edItem); 43 | return edItem; 44 | } 45 | else 46 | { 47 | TypeItem * typeItem = new TypeItem(td); 48 | typeItem->setPos(0.0,0.0); 49 | addItem(typeItem); 50 | return typeItem; 51 | } 52 | } 53 | else return 0; 54 | } 55 | 56 | void ExpressGScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *mouseEvent) 57 | { 58 | if (!selectedItems().isEmpty()) 59 | { 60 | QGraphicsItem * selItem = selectedItems().first(); 61 | EntityItem * entityItem; 62 | TypeItem * typeItem; 63 | if ( (entityItem = qgraphicsitem_cast (selItem) ) ) 64 | emit descriptorDoubleClicked ( entityItem->entityDescriptor() ); 65 | else if ( ( typeItem = qgraphicsitem_cast (selItem) ) ) 66 | emit descriptorDoubleClicked( typeItem->typeDescriptor() ); 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /expressg/ExpressGScene.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef EXPRESSGSCENE_H 21 | #define EXPRESSGSCENE_H 22 | 23 | #include 24 | class EntityDescriptor; 25 | class TypeDescriptor; 26 | 27 | class ExpressGScene : public QGraphicsScene 28 | { 29 | Q_OBJECT 30 | public: 31 | explicit ExpressGScene(QObject *parent = 0); 32 | QGraphicsItem* setDescriptor(const TypeDescriptor *td); 33 | 34 | protected: 35 | virtual void mouseDoubleClickEvent ( QGraphicsSceneMouseEvent * mouseEvent ); 36 | // virtual mousePressEvent(QGraphicsSceneMouseEvent *event); 37 | 38 | signals: 39 | void descriptorDoubleClicked( const TypeDescriptor * ); 40 | 41 | public slots: 42 | 43 | private: 44 | 45 | }; 46 | 47 | #endif // EXPRESSGSCENE_H 48 | -------------------------------------------------------------------------------- /expressg/ExpressGView.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ExpressGView.h" 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | using namespace std; 27 | 28 | ExpressGView::ExpressGView(QWidget *parent) 29 | : QGraphicsView(parent) 30 | , m_Scene() 31 | { 32 | setViewport(new QGLWidget(parent)); 33 | setScene(&m_Scene); 34 | setBackgroundBrush(QColor(54,54,76)); 35 | setDragMode(QGraphicsView::ScrollHandDrag); 36 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 37 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 38 | 39 | connect (&m_Scene, SIGNAL( descriptorDoubleClicked( const TypeDescriptor * ) ), this, SIGNAL(descriptorDoubleClicked(const TypeDescriptor*))); 40 | 41 | } 42 | 43 | void ExpressGView::setDescriptor(const TypeDescriptor *td) 44 | { 45 | reframeOn( m_Scene.setDescriptor(td) ); 46 | } 47 | 48 | void ExpressGView::reframeOn(QGraphicsItem * rootItem) 49 | { 50 | // first we "enlarge" the scene, to allow more scrolling space 51 | const QRectF itemsRect = m_Scene.itemsBoundingRect(); 52 | m_Scene.setSceneRect( itemsRect.x()-itemsRect.width()*0.5, itemsRect.y()-itemsRect.height()*0.5, 2.0*itemsRect.width(), 2.0*itemsRect.height() ); 53 | 54 | if (rootItem) 55 | ensureVisible(rootItem); 56 | } 57 | -------------------------------------------------------------------------------- /expressg/ExpressGView.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef EXPRESSGVIEW_H 21 | #define EXPRESSGVIEW_H 22 | 23 | #include 24 | #include 25 | #include "ExpressGScene.h" 26 | 27 | 28 | class ExpressGView : public QGraphicsView 29 | { 30 | Q_OBJECT 31 | public: 32 | explicit ExpressGView(QWidget *parent = 0); 33 | 34 | protected: 35 | //virtual void mousePressEvent(QMouseEvent *event); 36 | //virtual void mouseMoveEvent(QMouseEvent *event); 37 | 38 | signals: 39 | void descriptorDoubleClicked( const TypeDescriptor * ); 40 | 41 | public slots: 42 | void setDescriptor (const TypeDescriptor * td); 43 | 44 | private: 45 | void reframeOn(QGraphicsItem *rootItem); 46 | 47 | private: 48 | ExpressGScene m_Scene; 49 | 50 | }; 51 | 52 | #endif // EXPRESSGVIEW_H 53 | -------------------------------------------------------------------------------- /expressg/ExpressgRectItem.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ExpressgRectItem.h" 21 | #include 22 | #include 23 | 24 | ExpressgRectItem::ExpressgRectItem(const QString & text, bool hasLeftRect, bool hasRightRect, bool isDashed, QGraphicsRectItem * parent) 25 | : QGraphicsRectItem(parent) 26 | { 27 | qreal xLeft=0.0; 28 | 29 | QPen pen(Qt::white); 30 | if (isDashed) 31 | { 32 | pen.setStyle(Qt::CustomDashLine); 33 | QVector dashes; 34 | dashes << 6 << 4; 35 | pen.setDashPattern(dashes); 36 | } 37 | setPen(pen); 38 | setBrush(Qt::transparent); 39 | 40 | if (hasLeftRect) xLeft = 20.0; 41 | 42 | QGraphicsTextItem * textItem = new QGraphicsTextItem (text, this); 43 | 44 | qreal xRight = xLeft+15; 45 | textItem->setPos(xRight,10.0); 46 | textItem->setDefaultTextColor(Qt::white); 47 | qreal textWidth = textItem->boundingRect().width(); 48 | if (textWidth<85.0) textWidth=85.0; 49 | xRight+=xLeft+textWidth+15.0; // 15 = margin after text 50 | 51 | if (hasLeftRect) 52 | { 53 | QGraphicsLineItem * leftRectLine = new QGraphicsLineItem(xLeft, 0.0, xLeft, 40.0, this); 54 | leftRectLine->setPen(pen); 55 | } 56 | 57 | if (hasRightRect) 58 | { 59 | QGraphicsLineItem * rightRectLine = new QGraphicsLineItem(xRight, 0.0, xRight, 40.0, this); 60 | rightRectLine->setPen(pen); 61 | xRight+=20.0; 62 | } 63 | 64 | setRect( 0.0, 0.0,xRight,40.0); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /expressg/ExpressgRectItem.h: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef EXPRESSGRECTITEM_H 21 | #define EXPRESSGRECTITEM_H 22 | 23 | #include 24 | 25 | class ExpressgRectItem : public QGraphicsRectItem 26 | { 27 | public: 28 | ExpressgRectItem(const QString & text, bool hasLeftRect, bool hasRightRect, bool isDashed, QGraphicsRectItem * parent); 29 | }; 30 | 31 | #endif // EXPRESSGRECTITEM_H 32 | -------------------------------------------------------------------------------- /expressg/LinkItem.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "LinkItem.h" 21 | #include 22 | #include 23 | #include 24 | 25 | LinkItem::LinkItem(const AttrDescriptor * attrDescriptor, bool attributeIsOptional, QPointF pos, QGraphicsItem *parent) 26 | : QGraphicsRectItem(parent) 27 | { 28 | qreal x = pos.x(); 29 | qreal y = pos.y(); 30 | 31 | QString name(attrDescriptor->Name()); 32 | if (attrDescriptor->IsAggrType()) 33 | { 34 | QString rightSide (attrDescriptor->TypeName()); 35 | rightSide = rightSide.section(']',0,0); 36 | name += " : " + rightSide + "]"; 37 | } 38 | 39 | QGraphicsTextItem * textItem = new QGraphicsTextItem(name, this); 40 | textItem->setDefaultTextColor(Qt::white); 41 | textItem->setPos( x + 10.0, y-18.0); 42 | 43 | qreal w = textItem->boundingRect().width(); 44 | QGraphicsLineItem * lineItem = new QGraphicsLineItem(x, y, x+w+20.0, y, this); 45 | if (attributeIsOptional) 46 | { 47 | QPen pen(Qt::CustomDashLine); 48 | pen.setBrush(QColor(Qt::white)); 49 | QVector dashes; 50 | dashes << 6 << 4; 51 | pen.setDashPattern(dashes); 52 | lineItem->setPen(pen); 53 | } 54 | else lineItem->setPen(QPen(Qt::white)); 55 | QGraphicsEllipseItem * circle = new QGraphicsEllipseItem(x+w+20.0,y-5.0,10.0,10.0, this); 56 | circle->setBrush(QBrush(Qt::white)); 57 | 58 | setRect(childrenBoundingRect()); 59 | setPen(Qt::NoPen); 60 | } 61 | -------------------------------------------------------------------------------- /expressg/LinkItem.h: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef LINKITEM_H 21 | #define LINKITEM_H 22 | 23 | #include 24 | class AttrDescriptor; 25 | 26 | class LinkItem : public QGraphicsRectItem 27 | { 28 | public: 29 | enum { Type = UserType + 2 }; 30 | explicit LinkItem(const AttrDescriptor * attrDescriptor, bool attributeIsOptional, QPointF pos=QPointF(), QGraphicsItem *parent=0); 31 | inline int type() const { return Type; } // Enable the use of qgraphicsitem_cast with this item. 32 | 33 | signals: 34 | 35 | public slots: 36 | 37 | }; 38 | 39 | #endif // LINKITEM_H 40 | -------------------------------------------------------------------------------- /expressg/TypeItem.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | 21 | #include "TypeItem.h" 22 | #include 23 | #include 24 | 25 | TypeItem::TypeItem(const TypeDescriptor *typeDescriptor, QGraphicsItem *parent) 26 | : QGraphicsRectItem(parent) 27 | , m_TypeDesriptor(typeDescriptor) 28 | , m_RightSymbol(new QGraphicsRectItem(this)) 29 | { 30 | int childType = typeDescriptor->Type(); 31 | 32 | bool isBasicType=(typeDescriptor->ReferentType()==0); 33 | bool isSelectType = (childType==sdaiSELECT); 34 | bool isEnumType = (childType==sdaiENUMERATION); 35 | 36 | bool drawLeftRect=isSelectType; 37 | bool drawRightRect=( (!isSelectType) && isBasicType ) || isEnumType; 38 | bool isDashed=(!isBasicType) || isSelectType || isEnumType; 39 | 40 | setFlag(QGraphicsItem::ItemIsSelectable, true); 41 | qreal xLeft=0.0; 42 | QPen pen(Qt::white); 43 | if (isDashed) 44 | { 45 | pen.setStyle(Qt::CustomDashLine); 46 | QVector dashes; 47 | dashes << 6 << 4; 48 | pen.setDashPattern(dashes); 49 | } 50 | setPen(pen); 51 | setBrush(Qt::transparent); 52 | 53 | if (drawLeftRect) xLeft = 20.0; 54 | 55 | QGraphicsTextItem * textItem = new QGraphicsTextItem (typeDescriptor->Name(), this); 56 | 57 | qreal xRight = xLeft+15; 58 | textItem->setPos(xRight,10.0); 59 | textItem->setDefaultTextColor(Qt::white); 60 | qreal textWidth = textItem->boundingRect().width(); 61 | if (textWidth<85.0) textWidth=85.0; 62 | xRight+=xLeft+textWidth+15.0; // 15 = margin after text 63 | 64 | if (drawLeftRect) 65 | { 66 | QGraphicsLineItem * leftRectLine = new QGraphicsLineItem(xLeft, 0.0, xLeft, 40.0, this); 67 | leftRectLine->setPen(pen); 68 | } 69 | 70 | if (drawRightRect) 71 | { 72 | QGraphicsLineItem * rightRectLine = new QGraphicsLineItem(xRight, 0.0, xRight, 40.0, this); 73 | rightRectLine->setPen(pen); 74 | xRight+=20.0; 75 | } 76 | 77 | setRect( 0.0, 0.0,xRight,40.0); 78 | /* 79 | setBrush(QColor(Qt::white)); 80 | 81 | std::string str; 82 | str.append(td->BaseTypeName()); 83 | QString text = str.c_str(); 84 | QGraphicsTextItem * textItem = new QGraphicsTextItem (text, this); 85 | 86 | // geom: 87 | textItem->setPos(15.0,10.0); 88 | qreal rectWidth = textItem->boundingRect().width(); 89 | if (rectWidth<85.0) rectWidth=85.0; 90 | setRect( 0.0, 0.0,rectWidth+45.0,40.0); 91 | m_RightSymbol->setRect(rectWidth+30.0, 0.0, 15.0, 40.0); 92 | */ 93 | } 94 | 95 | -------------------------------------------------------------------------------- /expressg/TypeItem.h: -------------------------------------------------------------------------------- 1 | /* This file is part of [To be named], a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef TYPEITEM_H 21 | #define TYPEITEM_H 22 | 23 | #include 24 | #include 25 | 26 | class TypeItem : public QGraphicsRectItem 27 | { 28 | public: 29 | TypeItem(const TypeDescriptor * typeDescriptor , QGraphicsItem *parent=0); 30 | inline const TypeDescriptor * typeDescriptor() {return m_TypeDesriptor; } 31 | 32 | private: 33 | const TypeDescriptor * m_TypeDesriptor; 34 | QGraphicsRectItem * m_RightSymbol; 35 | 36 | }; 37 | 38 | #endif // TYPEITEM_H 39 | -------------------------------------------------------------------------------- /icones/Express.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/Express.png -------------------------------------------------------------------------------- /icones/ListView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/ListView.png -------------------------------------------------------------------------------- /icones/SCLView.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 23 | 27 | 31 | 32 | 34 | 38 | 42 | 43 | 45 | 49 | 53 | 54 | 65 | 75 | 85 | 96 | 106 | 116 | 126 | 136 | 137 | 155 | 164 | 165 | 167 | 168 | 170 | image/svg+xml 171 | 173 | 174 | 175 | 176 | 177 | 181 | 191 | 201 | 209 | 220 | 228 | 236 | 244 | 254 | 260 | Grrg G - grgrERGR 287 | 298 | 299 | 300 | -------------------------------------------------------------------------------- /icones/Schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/Schema.png -------------------------------------------------------------------------------- /icones/TreeView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/TreeView.png -------------------------------------------------------------------------------- /icones/WhiteRect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/WhiteRect.png -------------------------------------------------------------------------------- /icones/attribute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/attribute.png -------------------------------------------------------------------------------- /icones/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/close.png -------------------------------------------------------------------------------- /icones/find.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/find.png -------------------------------------------------------------------------------- /icones/redo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/redo.png -------------------------------------------------------------------------------- /icones/type.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/type.png -------------------------------------------------------------------------------- /icones/undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaurentBauer/SCView/2bc33ee740292c69140d8737c389c0bdf4aadac5/icones/undo.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include 21 | #include "MainWindow.h" 22 | #include "manhattanstyle.h" 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | QApplication a(argc, argv); 27 | QString name = QApplication::style()->objectName(); 28 | QApplication::setStyle(new ManhattanStyle(name)); 29 | a.setApplicationName("SCView"); 30 | a.setApplicationVersion("V0.1"); 31 | a.setOrganizationName("To_be_named.org"); 32 | MainWindow w; 33 | w.show(); 34 | 35 | return a.exec(); 36 | } 37 | -------------------------------------------------------------------------------- /manhattanstyle.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Qt Software Information (qt-info@nokia.com) 8 | ** 9 | ** Commercial Usage 10 | ** 11 | ** Licensees holding valid Qt Commercial licenses may use this file in 12 | ** accordance with the Qt Commercial License Agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and Nokia. 15 | ** 16 | ** GNU Lesser General Public License Usage 17 | ** 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** If you are unsure which license is appropriate for your use, please 26 | ** contact the sales department at qt-sales@nokia.com. 27 | ** 28 | **************************************************************************/ 29 | 30 | // Orginal file comes from an old version of Qt creator. Don't remember which one. Something around V1.2 31 | // Small modifications should have been tagged with "// LOLO" 32 | 33 | 34 | #include "manhattanstyle.h" 35 | #include "styleanimator.h" 36 | 37 | #include 38 | #include 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | 61 | // #include 62 | 63 | // We define a currently unused state for indicating animations 64 | #define State_Animating 0x00000040 65 | 66 | // Because designer needs to disable this for widget previews 67 | // we have a custom property that is inherited 68 | bool styleEnabled(const QWidget *widget) 69 | { 70 | const QWidget *p = widget; 71 | while (p) { 72 | if (p->property("_q_custom_style_disabled").toBool()) 73 | return false; 74 | p = p->parentWidget(); 75 | } 76 | return true; 77 | } 78 | 79 | // Consider making this a QStyle state 80 | bool panelWidget(const QWidget *widget) 81 | { 82 | const QWidget *p = widget; 83 | 84 | while (p) { 85 | if (qobject_cast(p) && styleEnabled(p)) 86 | return true; 87 | else if (qobject_cast(p) && styleEnabled(p)) 88 | return true; 89 | else if (qobject_cast(p) && styleEnabled(p)) 90 | return true; 91 | p = p->parentWidget(); 92 | } 93 | return false; 94 | } 95 | 96 | class ManhattanStylePrivate 97 | { 98 | public: 99 | ManhattanStylePrivate(const QString &baseStyleName) 100 | { 101 | style = QStyleFactory::create(baseStyleName); 102 | // QTC_ASSERT(style, /**/); 103 | buttonImage_pressed = QImage(":/core/images/pushbutton_pressed.png"); 104 | buttonImage = QImage(":/core/images/pushbutton.png"); 105 | 106 | // lineeditImage = QImage(":/core/images/inputfield.png"); // LOLO 107 | lineeditImage = QImage(":WhiteRect"); 108 | lineeditImage_disabled = QImage(":/core/images/inputfield_disabled.png"); 109 | } 110 | 111 | ~ManhattanStylePrivate() 112 | { 113 | delete style; 114 | style = 0; 115 | } 116 | 117 | void init(); 118 | 119 | public: 120 | QStyle *style; 121 | QImage buttonImage; 122 | QImage buttonImage_pressed; 123 | QImage lineeditImage; 124 | QImage lineeditImage_disabled; 125 | 126 | StyleAnimator animator; 127 | }; 128 | 129 | ManhattanStyle::ManhattanStyle(const QString &baseStyleName) 130 | : QWindowsStyle(), d(new ManhattanStylePrivate(baseStyleName)) 131 | { 132 | } 133 | 134 | ManhattanStyle::~ManhattanStyle() 135 | { 136 | delete d; 137 | d = 0; 138 | } 139 | 140 | // Draws a CSS-like border image where the defined borders are not stretched 141 | void drawCornerImage(const QImage &img, QPainter *painter, QRect rect, 142 | int left = 0, int top = 0, int right = 0, 143 | int bottom = 0) 144 | { 145 | QSize size = img.size(); 146 | if (top > 0) { //top 147 | painter->drawImage(QRect(rect.left() + left, rect.top(), rect.width() -right - left, top), img, 148 | QRect(left, 0, size.width() -right - left, top)); 149 | if (left > 0) //top-left 150 | painter->drawImage(QRect(rect.left(), rect.top(), left, top), img, 151 | QRect(0, 0, left, top)); 152 | if (right > 0) //top-right 153 | painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top(), right, top), img, 154 | QRect(size.width() - right, 0, right, top)); 155 | } 156 | //left 157 | if (left > 0) 158 | painter->drawImage(QRect(rect.left(), rect.top()+top, left, rect.height() - top - bottom), img, 159 | QRect(0, top, left, size.height() - bottom - top)); 160 | //center 161 | painter->drawImage(QRect(rect.left() + left, rect.top()+top, rect.width() -right - left, 162 | rect.height() - bottom - top), img, 163 | QRect(left, top, size.width() -right -left, 164 | size.height() - bottom - top)); 165 | if (right > 0) //right 166 | painter->drawImage(QRect(rect.left() +rect.width() - right, rect.top()+top, right, rect.height() - top - bottom), img, 167 | QRect(size.width() - right, top, right, size.height() - bottom - top)); 168 | if (bottom > 0) { //bottom 169 | painter->drawImage(QRect(rect.left() +left, rect.top() + rect.height() - bottom, 170 | rect.width() - right - left, bottom), img, 171 | QRect(left, size.height() - bottom, 172 | size.width() - right - left, bottom)); 173 | if (left > 0) //bottom-left 174 | painter->drawImage(QRect(rect.left(), rect.top() + rect.height() - bottom, left, bottom), img, 175 | QRect(0, size.height() - bottom, left, bottom)); 176 | if (right > 0) //bottom-right 177 | painter->drawImage(QRect(rect.left() + rect.width() - right, rect.top() + rect.height() - bottom, right, bottom), img, 178 | QRect(size.width() - right, size.height() - bottom, right, bottom)); 179 | } 180 | } 181 | 182 | QPixmap ManhattanStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const 183 | { 184 | QPixmap result; 185 | result = d->style->generatedIconPixmap(iconMode, pixmap, opt); 186 | return result; 187 | } 188 | 189 | int ManhattanStyle::layoutSpacingImplementation(QSizePolicy::ControlType control1, 190 | QSizePolicy::ControlType control2, 191 | Qt::Orientation orientation, 192 | const QStyleOption * option , 193 | const QWidget * widget ) const 194 | { 195 | return d->style->layoutSpacing(control1, control2, orientation, option, widget); 196 | 197 | } 198 | 199 | QSize ManhattanStyle::sizeFromContents(ContentsType type, const QStyleOption *option, 200 | const QSize &size, const QWidget *widget) const 201 | { 202 | QSize newSize = d->style->sizeFromContents(type, option, size, widget); 203 | 204 | if (type == CT_Splitter && widget && widget->property("minisplitter").toBool()) 205 | return QSize(1, 1); 206 | else if (type == CT_ComboBox && panelWidget(widget)) 207 | newSize += QSize(14, 0); 208 | return newSize; 209 | } 210 | 211 | QRect ManhattanStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const 212 | { 213 | QRect rect; 214 | rect = d->style->subElementRect(element, option, widget); 215 | return rect; 216 | } 217 | 218 | QRect ManhattanStyle::subControlRect(ComplexControl control, const QStyleOptionComplex *option, 219 | SubControl subControl, const QWidget *widget) const 220 | { 221 | QRect rect; 222 | rect = d->style->subControlRect(control, option, subControl, widget); 223 | return rect; 224 | } 225 | 226 | QStyle::SubControl ManhattanStyle::hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, 227 | const QPoint &pos, const QWidget *widget) const 228 | { 229 | SubControl result = QStyle::SC_None; 230 | result = d->style->hitTestComplexControl(control, option, pos, widget); 231 | return result; 232 | } 233 | 234 | int ManhattanStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const 235 | { 236 | int retval = 0; 237 | retval = d->style->pixelMetric(metric, option, widget); 238 | switch (metric) { 239 | case PM_SplitterWidth: 240 | if (widget && widget->property("minisplitter").toBool()) 241 | retval = 1; 242 | break; 243 | case PM_ToolBarIconSize: 244 | if (panelWidget(widget)) 245 | retval = 16; 246 | break; 247 | case PM_MenuPanelWidth: 248 | case PM_MenuBarHMargin: 249 | case PM_MenuBarVMargin: 250 | case PM_ToolBarFrameWidth: 251 | if (panelWidget(widget)) 252 | retval = 1; 253 | break; 254 | case PM_ButtonShiftVertical: 255 | case PM_ButtonShiftHorizontal: 256 | case PM_MenuBarPanelWidth: 257 | case PM_ToolBarItemMargin: 258 | case PM_ToolBarItemSpacing: 259 | if (panelWidget(widget)) 260 | retval = 0; 261 | break; 262 | case PM_DefaultFrameWidth: 263 | if (qobject_cast(widget) && panelWidget(widget)) 264 | return 1; 265 | break; 266 | default: 267 | break; 268 | } 269 | return retval; 270 | } 271 | 272 | QPalette ManhattanStyle::standardPalette() const 273 | { 274 | QPalette result; 275 | result = d->style->standardPalette(); 276 | return result; 277 | } 278 | 279 | void ManhattanStyle::polish(QApplication *app) 280 | { 281 | d->style->polish(app); 282 | } 283 | 284 | void ManhattanStyle::unpolish(QApplication *app) 285 | { 286 | d->style->unpolish(app); 287 | } 288 | 289 | QPalette panelPalette(const QPalette &oldPalette) 290 | { 291 | QColor color = ManhattanStyle::panelTextColor(); 292 | QPalette pal = oldPalette; 293 | pal.setBrush(QPalette::All, QPalette::WindowText, color); 294 | pal.setBrush(QPalette::All, QPalette::ButtonText, color); 295 | pal.setBrush(QPalette::All, QPalette::Foreground, color); 296 | color.setAlpha(100); 297 | pal.setBrush(QPalette::Disabled, QPalette::WindowText, color); 298 | pal.setBrush(QPalette::Disabled, QPalette::ButtonText, color); 299 | pal.setBrush(QPalette::Disabled, QPalette::Foreground, color); 300 | return pal; 301 | } 302 | 303 | void ManhattanStyle::polish(QWidget *widget) 304 | { 305 | d->style->polish(widget); 306 | 307 | // OxygenStyle forces a rounded widget mask on toolbars 308 | if (d->style->inherits("OxygenStyle")) { 309 | if (qobject_cast(widget)) 310 | widget->removeEventFilter(d->style); 311 | } 312 | if (panelWidget(widget)) { 313 | if (qobject_cast(widget)) { 314 | widget->setAttribute(Qt::WA_Hover); 315 | widget->setMaximumHeight(navigationWidgetHeight() - 2); 316 | widget->setAttribute(Qt::WA_Hover); 317 | } 318 | else if (qobject_cast(widget)) { 319 | widget->setAttribute(Qt::WA_Hover); 320 | widget->setMaximumHeight(navigationWidgetHeight() - 2); 321 | } 322 | else if (qobject_cast(widget)) 323 | widget->setPalette(panelPalette(widget->palette())); 324 | else if (qobject_cast(widget)) 325 | widget->setMinimumHeight(navigationWidgetHeight()); 326 | else if (qobject_cast(widget)) 327 | widget->setFixedHeight(navigationWidgetHeight() + 2); 328 | else if (qobject_cast(widget)) { 329 | widget->setMaximumHeight(navigationWidgetHeight() - 2); 330 | widget->setAttribute(Qt::WA_Hover); 331 | } 332 | } 333 | } 334 | 335 | void ManhattanStyle::unpolish(QWidget *widget) 336 | { 337 | d->style->unpolish(widget); 338 | if (panelWidget(widget)) { 339 | if (qobject_cast(widget)) 340 | widget->setAttribute(Qt::WA_Hover, false); 341 | else if (qobject_cast(widget)) 342 | widget->setAttribute(Qt::WA_Hover, false); 343 | else if (qobject_cast(widget)) 344 | widget->setAttribute(Qt::WA_Hover, false); 345 | } 346 | } 347 | 348 | void ManhattanStyle::polish(QPalette &pal) 349 | { 350 | d->style->polish(pal); 351 | } 352 | 353 | QIcon ManhattanStyle::standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, 354 | const QWidget *widget) const 355 | { 356 | QIcon icon; 357 | switch (standardIcon) { 358 | case QStyle::SP_TitleBarCloseButton: 359 | case QStyle::SP_ToolBarHorizontalExtensionButton: 360 | return QIcon(standardPixmap(standardIcon, option, widget)); 361 | default: 362 | icon = d->style->standardIcon(standardIcon, option, widget); 363 | } 364 | return icon; 365 | } 366 | 367 | QPixmap ManhattanStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, 368 | const QWidget *widget) const 369 | { 370 | if (widget && !panelWidget(widget)) 371 | return d->style->standardPixmap(standardPixmap, opt, widget); 372 | 373 | QPixmap pixmap; 374 | switch (standardPixmap) { 375 | case QStyle::SP_ToolBarHorizontalExtensionButton: { 376 | static const QPixmap extButton(":extension"); 377 | pixmap = extButton; 378 | } 379 | break; 380 | case QStyle::SP_TitleBarCloseButton: { 381 | // static const QPixmap closeButton(":/core/images/closebutton.png"); // original of Qt 382 | static const QPixmap closeButton(":closetab"); // LOLO 383 | pixmap = closeButton; 384 | } 385 | break; 386 | default: 387 | pixmap = d->style->standardPixmap(standardPixmap, opt, widget); 388 | } 389 | return pixmap; 390 | } 391 | 392 | 393 | int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, 394 | QStyleHintReturn *returnData) const 395 | { 396 | int ret = d->style->styleHint(hint, option, widget, returnData); 397 | switch (hint) { 398 | // Make project explorer alternate rows all the way 399 | case QStyle::SH_ItemView_PaintAlternatingRowColorsForEmptyArea: 400 | if (widget && widget->property("AlternateEmpty").toBool()) 401 | ret = true; 402 | break; 403 | case QStyle::SH_EtchDisabledText: 404 | if (panelWidget(widget)) 405 | ret = false; 406 | break; 407 | default: 408 | break; 409 | } 410 | return ret; 411 | } 412 | 413 | void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, 414 | QPainter *painter, const QWidget *widget) const 415 | { 416 | if (!panelWidget(widget)) 417 | return d->style->drawPrimitive(element, option, painter, widget); 418 | 419 | bool animating = (option->state & State_Animating); 420 | int state = option->state; 421 | QRect rect = option->rect; 422 | QRect oldRect; 423 | QRect newRect; 424 | if (widget && (element == PE_PanelButtonTool) && !animating) { 425 | QWidget *w = const_cast (widget); 426 | int oldState = w->property("_q_stylestate").toInt(); 427 | oldRect = w->property("_q_stylerect").toRect(); 428 | newRect = w->rect(); 429 | w->setProperty("_q_stylestate", (int)option->state); 430 | w->setProperty("_q_stylerect", w->rect()); 431 | 432 | // Determine the animated transition 433 | bool doTransition = ((state & State_On) != (oldState & State_On) || 434 | (state & State_MouseOver) != (oldState & State_MouseOver)); 435 | if (oldRect != newRect) 436 | { 437 | doTransition = false; 438 | d->animator.stopAnimation(widget); 439 | } 440 | 441 | if (doTransition) { 442 | QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); 443 | QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied); 444 | Animation *anim = d->animator.widgetAnimation(widget); 445 | QStyleOption opt = *option; 446 | opt.state = (QStyle::State)oldState; 447 | opt.state |= (State)State_Animating; 448 | startImage.fill(0); 449 | Transition *t = new Transition; 450 | t->setWidget(w); 451 | QPainter startPainter(&startImage); 452 | if (!anim) { 453 | drawPrimitive(element, &opt, &startPainter, widget); 454 | } else { 455 | anim->paint(&startPainter, &opt); 456 | d->animator.stopAnimation(widget); 457 | } 458 | QStyleOption endOpt = *option; 459 | endOpt.state |= (State)State_Animating; 460 | t->setStartImage(startImage); 461 | d->animator.startAnimation(t); 462 | endImage.fill(0); 463 | QPainter endPainter(&endImage); 464 | drawPrimitive(element, &endOpt, &endPainter, widget); 465 | t->setEndImage(endImage); 466 | t->setDuration(130); 467 | t->setStartTime(QTime::currentTime()); 468 | } 469 | } 470 | 471 | switch (element) { 472 | case PE_PanelLineEdit: 473 | { 474 | painter->save(); 475 | if (option->state & State_Enabled) 476 | drawCornerImage(d->lineeditImage, painter, option->rect, 2, 2, 2, 2); 477 | else 478 | drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 2, 2, 2, 2); 479 | 480 | if (option->state & State_HasFocus || option->state & State_MouseOver) { 481 | QColor hover = baseColor(); 482 | if (state & State_HasFocus) 483 | hover.setAlpha(100); 484 | else 485 | hover.setAlpha(50); 486 | 487 | painter->setPen(QPen(hover, 1)); 488 | painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2)); 489 | } 490 | painter->restore(); 491 | } 492 | break; 493 | 494 | case PE_FrameStatusBarItem: 495 | break; 496 | 497 | case PE_PanelButtonTool: { 498 | Animation *anim = d->animator.widgetAnimation(widget); 499 | if (!animating && anim) { 500 | anim->paint(painter, option); 501 | } else { 502 | bool pressed = option->state & State_Sunken || option->state & State_On; 503 | QColor shadow(0, 0, 0, 30); 504 | painter->setPen(shadow); 505 | if (pressed) { 506 | QColor shade(0, 0, 0, 40); 507 | painter->fillRect(rect, shade); 508 | painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0)); 509 | painter->drawLine(rect.topLeft(), rect.bottomLeft()); 510 | painter->drawLine(rect.topRight(), rect.bottomRight()); 511 | // painter->drawLine(rect.bottomLeft() + QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); 512 | QColor highlight(255, 255, 255, 30); 513 | painter->setPen(highlight); 514 | } 515 | else if (option->state & State_Enabled && 516 | option->state & State_MouseOver) { 517 | QColor lighter(255, 255, 255, 37); 518 | painter->fillRect(rect, lighter); 519 | } 520 | } 521 | } 522 | break; 523 | 524 | case PE_PanelStatusBar: 525 | { 526 | painter->save(); 527 | QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom())); 528 | QColor startColor = shadowColor().darker(164); 529 | QColor endColor = baseColor().darker(130); 530 | grad.setColorAt(0, startColor); 531 | grad.setColorAt(1, endColor); 532 | painter->fillRect(option->rect, grad); 533 | painter->setPen(QColor(255, 255, 255, 60)); 534 | painter->drawLine(rect.topLeft() + QPoint(0,1), 535 | rect.topRight()+ QPoint(0,1)); 536 | painter->setPen(borderColor().darker(110)); 537 | painter->drawLine(rect.topLeft(), rect.topRight()); 538 | painter->restore(); 539 | } 540 | break; 541 | 542 | case PE_IndicatorToolBarSeparator: 543 | { 544 | QColor separatorColor = borderColor(); 545 | separatorColor.setAlpha(100); 546 | painter->setPen(separatorColor); 547 | const int margin = 6; 548 | if (option->state & State_Horizontal) { 549 | const int offset = rect.width()/2; 550 | painter->drawLine(rect.bottomLeft().x() + offset, 551 | rect.bottomLeft().y() - margin, 552 | rect.topLeft().x() + offset, 553 | rect.topLeft().y() + margin); 554 | } else { //Draw vertical separator 555 | const int offset = rect.height()/2; 556 | painter->setPen(QPen(option->palette.background().color().darker(110))); 557 | painter->drawLine(rect.topLeft().x() + margin , 558 | rect.topLeft().y() + offset, 559 | rect.topRight().x() - margin, 560 | rect.topRight().y() + offset); 561 | } 562 | } 563 | break; 564 | 565 | case PE_IndicatorToolBarHandle: 566 | { 567 | bool horizontal = option->state & State_Horizontal; 568 | painter->save(); 569 | QPainterPath path; 570 | int x = option->rect.x() + horizontal ? 2 : 6; 571 | int y = option->rect.y() + horizontal ? 6 : 2; 572 | static const int RectHeight = 2; 573 | if (horizontal) { 574 | while (y < option->rect.height() - RectHeight - 6) { 575 | path.moveTo(x, y); 576 | path.addRect(x, y, RectHeight, RectHeight); 577 | y += 6; 578 | } 579 | } else { 580 | while (x < option->rect.width() - RectHeight - 6) { 581 | path.moveTo(x, y); 582 | path.addRect(x, y, RectHeight, RectHeight); 583 | x += 6; 584 | } 585 | } 586 | 587 | painter->setPen(Qt::NoPen); 588 | QColor dark = borderColor(); 589 | dark.setAlphaF(0.4); 590 | 591 | QColor light = baseColor(); 592 | light.setAlphaF(0.4); 593 | 594 | painter->fillPath(path, light); 595 | painter->save(); 596 | painter->translate(1, 1); 597 | painter->fillPath(path, dark); 598 | painter->restore(); 599 | painter->translate(3, 3); 600 | painter->fillPath(path, light); 601 | painter->translate(1, 1); 602 | painter->fillPath(path, dark); 603 | painter->restore(); 604 | } 605 | break; 606 | case PE_IndicatorArrowUp: 607 | case PE_IndicatorArrowDown: 608 | case PE_IndicatorArrowRight: 609 | case PE_IndicatorArrowLeft: 610 | { 611 | // From windowsstyle but modified to enable AA 612 | if (option->rect.width() <= 1 || option->rect.height() <= 1) 613 | break; 614 | 615 | QRect r = option->rect; 616 | int size = qMin(r.height(), r.width()); 617 | QPixmap pixmap; 618 | QString pixmapName; 619 | pixmapName.sprintf("%s-%s-%d-%d-%d-%lld", 620 | "$qt_ia", metaObject()->className(), 621 | uint(option->state), element, 622 | size, option->palette.cacheKey()); 623 | if (!QPixmapCache::find(pixmapName, pixmap)) { 624 | int border = size/5; 625 | int sqsize = 2*(size/2); 626 | QImage image(sqsize, sqsize, QImage::Format_ARGB32); 627 | image.fill(Qt::transparent); 628 | QPainter imagePainter(&image); 629 | imagePainter.setRenderHint(QPainter::Antialiasing, true); 630 | imagePainter.translate(0.5, 0.5); 631 | QPolygon a; 632 | switch (element) { 633 | case PE_IndicatorArrowUp: 634 | a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2); 635 | break; 636 | case PE_IndicatorArrowDown: 637 | a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2); 638 | break; 639 | case PE_IndicatorArrowRight: 640 | a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); 641 | break; 642 | case PE_IndicatorArrowLeft: 643 | a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border); 644 | break; 645 | default: 646 | break; 647 | } 648 | 649 | int bsx = 0; 650 | int bsy = 0; 651 | 652 | if (option->state & State_Sunken) { 653 | bsx = pixelMetric(PM_ButtonShiftHorizontal); 654 | bsy = pixelMetric(PM_ButtonShiftVertical); 655 | } 656 | 657 | QRect bounds = a.boundingRect(); 658 | int sx = sqsize / 2 - bounds.center().x() - 1; 659 | int sy = sqsize / 2 - bounds.center().y() - 1; 660 | imagePainter.translate(sx + bsx, sy + bsy); 661 | 662 | if (!(option->state & State_Enabled)) { 663 | QColor foreGround(150, 150, 150, 150); 664 | imagePainter.setBrush(option->palette.mid().color()); 665 | imagePainter.setPen(option->palette.mid().color()); 666 | } else { 667 | QColor shadow(0, 0, 0, 100); 668 | imagePainter.translate(0, 1); 669 | imagePainter.setPen(shadow); 670 | imagePainter.setBrush(shadow); 671 | QColor foreGround(255, 255, 255, 210); 672 | imagePainter.drawPolygon(a); 673 | imagePainter.translate(0, -1); 674 | imagePainter.setPen(foreGround); 675 | imagePainter.setBrush(foreGround); 676 | } 677 | imagePainter.drawPolygon(a); 678 | imagePainter.end(); 679 | pixmap = QPixmap::fromImage(image); 680 | QPixmapCache::insert(pixmapName, pixmap); 681 | } 682 | int xOffset = r.x() + (r.width() - size)/2; 683 | int yOffset = r.y() + (r.height() - size)/2; 684 | painter->drawPixmap(xOffset, yOffset, pixmap); 685 | } 686 | break; 687 | 688 | default: 689 | d->style->drawPrimitive(element, option, painter, widget); 690 | break; 691 | } 692 | } 693 | 694 | void ManhattanStyle::drawControl(ControlElement element, const QStyleOption *option, 695 | QPainter *painter, const QWidget *widget) const 696 | { 697 | if (!panelWidget(widget)) 698 | return d->style->drawControl(element, option, painter, widget); 699 | 700 | switch (element) { 701 | case CE_MenuBarItem: 702 | painter->save(); 703 | if (const QStyleOptionMenuItem *mbi = qstyleoption_cast(option)) { 704 | QColor highlightOutline = borderColor().lighter(120); 705 | bool act = mbi->state & State_Selected && mbi->state & State_Sunken; 706 | bool dis = !(mbi->state & State_Enabled); 707 | menuGradient(painter, option->rect, option->rect); 708 | QStyleOptionMenuItem item = *mbi; 709 | item.rect = mbi->rect; 710 | QPalette pal = mbi->palette; 711 | pal.setBrush(QPalette::ButtonText, dis ? Qt::gray : Qt::black); 712 | item.palette = pal; 713 | QCommonStyle::drawControl(element, &item, painter, widget); 714 | QRect r = option->rect; 715 | 716 | if (act) { 717 | // Fill| 718 | QColor cbaseColor = baseColor(); 719 | QLinearGradient grad(option->rect.topLeft(), option->rect.bottomLeft()); 720 | grad.setColorAt(0, cbaseColor.lighter(120)); 721 | grad.setColorAt(1, cbaseColor.lighter(130)); 722 | painter->fillRect(option->rect.adjusted(1, 1, -1, 0), grad); 723 | 724 | // Outline 725 | painter->setPen(QPen(highlightOutline, 0)); 726 | painter->drawLine(QPoint(r.left(), r.top() + 1), QPoint(r.left(), r.bottom())); 727 | painter->drawLine(QPoint(r.right(), r.top() + 1), QPoint(r.right(), r.bottom())); 728 | painter->drawLine(QPoint(r.left() + 1, r.top()), QPoint(r.right() - 1, r.top())); 729 | highlightOutline.setAlpha(60); 730 | painter->setPen(QPen(highlightOutline, 0)); 731 | painter->drawPoint(r.topLeft()); 732 | painter->drawPoint(r.topRight()); 733 | 734 | QPalette pal = mbi->palette; 735 | uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; 736 | if (!styleHint(SH_UnderlineShortcut, mbi, widget)) 737 | alignment |= Qt::TextHideMnemonic; 738 | pal.setBrush(QPalette::Text, dis ? Qt::gray : QColor(0, 0, 0, 60)); 739 | drawItemText(painter, item.rect.translated(0, 1), alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); 740 | pal.setBrush(QPalette::Text, dis ? Qt::gray : Qt::white); 741 | drawItemText(painter, item.rect, alignment, pal, mbi->state & State_Enabled, mbi->text, QPalette::Text); 742 | } 743 | } 744 | painter->restore(); 745 | break; 746 | 747 | case CE_ComboBoxLabel: 748 | if (const QStyleOptionComboBox *cb = qstyleoption_cast(option)) { 749 | if (panelWidget(widget)) { 750 | QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget); 751 | QPalette customPal = cb->palette; 752 | 753 | if (!cb->currentIcon.isNull()) { 754 | QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal 755 | : QIcon::Disabled; 756 | QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, mode); 757 | QRect iconRect(editRect); 758 | iconRect.setWidth(cb->iconSize.width() + 4); 759 | iconRect = alignedRect(cb->direction, 760 | Qt::AlignLeft | Qt::AlignVCenter, 761 | iconRect.size(), editRect); 762 | if (cb->editable) 763 | painter->fillRect(iconRect, customPal.brush(QPalette::Base)); 764 | drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap); 765 | 766 | if (cb->direction == Qt::RightToLeft) 767 | editRect.translate(-4 - cb->iconSize.width(), 0); 768 | else 769 | editRect.translate(cb->iconSize.width() + 4, 0); 770 | 771 | // Reserve some space for the down-arrow 772 | editRect.adjust(0, 0, -13, 0); 773 | } 774 | 775 | customPal.setBrush(QPalette::All, QPalette::ButtonText, QColor(0, 0, 0, 70)); 776 | 777 | QString text = option->fontMetrics.elidedText(cb->currentText, Qt::ElideRight, editRect.width()); 778 | drawItemText(painter, editRect.translated(0, 1), 779 | visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter), 780 | customPal, cb->state & State_Enabled, text, QPalette::ButtonText); 781 | customPal.setBrush(QPalette::All, QPalette::ButtonText, panelTextColor()); 782 | drawItemText(painter, editRect, 783 | visualAlignment(option->direction, Qt::AlignLeft | Qt::AlignVCenter), 784 | customPal, cb->state & State_Enabled, text, QPalette::ButtonText); 785 | } else { 786 | d->style->drawControl(element, option, painter, widget); 787 | } 788 | } 789 | break; 790 | 791 | case CE_SizeGrip: { 792 | painter->save(); 793 | QColor dark = Qt::white; 794 | dark.setAlphaF(0.1); 795 | int x, y, w, h; 796 | option->rect.getRect(&x, &y, &w, &h); 797 | int sw = qMin(h, w); 798 | if (h > w) 799 | painter->translate(0, h - w); 800 | else 801 | painter->translate(w - h, 0); 802 | int sx = x; 803 | int sy = y; 804 | int s = 4; 805 | painter->setPen(dark); 806 | if (option->direction == Qt::RightToLeft) { 807 | sx = x + sw; 808 | for (int i = 0; i < 4; ++i) { 809 | painter->drawLine(x, sy, sx, sw); 810 | sx -= s; 811 | sy += s; 812 | } 813 | } else { 814 | for (int i = 0; i < 4; ++i) { 815 | painter->drawLine(sx, sw, sw, sy); 816 | sx += s; 817 | sy += s; 818 | } 819 | } 820 | painter->restore(); 821 | } 822 | break; 823 | 824 | case CE_MenuBarEmptyArea: { 825 | menuGradient(painter, option->rect, option->rect); 826 | painter->save(); 827 | painter->setPen(borderColor()); 828 | painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight()); 829 | painter->restore(); 830 | } 831 | break; 832 | 833 | case CE_ToolBar: 834 | { 835 | QString key; 836 | key.sprintf("mh_toolbar %d %d %d", option->rect.width(), option->rect.height(), baseColor().rgb());; 837 | 838 | QPixmap pixmap; 839 | QPainter *p = painter; 840 | QRect rect = option->rect; 841 | if (usePixmapCache() && !QPixmapCache::find(key, pixmap)) { 842 | pixmap = QPixmap(option->rect.size()); 843 | p = new QPainter(&pixmap); 844 | rect = QRect(0, 0, option->rect.width(), option->rect.height()); 845 | } 846 | 847 | bool horizontal = option->state & State_Horizontal; 848 | // Map offset for global window gradient 849 | QPoint offset = widget->window()->mapToGlobal(option->rect.topLeft()) - 850 | widget->mapToGlobal(option->rect.topLeft()); 851 | QRect gradientSpan; 852 | if (widget) { 853 | gradientSpan = QRect(offset, widget->window()->size()); 854 | } 855 | if (horizontal) 856 | horizontalGradient(p, gradientSpan, rect); 857 | else 858 | verticalGradient(p, gradientSpan, rect); 859 | 860 | painter->setPen(borderColor()); 861 | 862 | if (horizontal) { 863 | // Note: This is a hack to determine if the 864 | // toolbar should draw the top or bottom outline 865 | // (needed for the find toolbar for instance) 866 | QColor lighter(255, 255, 255, 40); 867 | if (widget && widget->property("topBorder").toBool()) { 868 | p->drawLine(rect.topLeft(), rect.topRight()); 869 | p->setPen(lighter); 870 | p->drawLine(rect.topLeft() + QPoint(0, 1), rect.topRight() + QPoint(0, 1)); 871 | } else { 872 | p->drawLine(rect.bottomLeft(), rect.bottomRight()); 873 | p->setPen(lighter); 874 | p->drawLine(rect.topLeft(), rect.topRight()); 875 | } 876 | } else { 877 | p->drawLine(rect.topLeft(), rect.bottomLeft()); 878 | p->drawLine(rect.topRight(), rect.bottomRight()); 879 | } 880 | 881 | if (usePixmapCache() && !QPixmapCache::find(key, pixmap)) { 882 | painter->drawPixmap(rect.topLeft(), pixmap); 883 | p->end(); 884 | delete p; 885 | QPixmapCache::insert(key, pixmap); 886 | } 887 | } 888 | break; 889 | 890 | default: 891 | d->style->drawControl(element, option, painter, widget); 892 | break; 893 | } 894 | } 895 | 896 | void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, 897 | QPainter *painter, const QWidget *widget) const 898 | { 899 | if (!panelWidget(widget)) 900 | return d->style->drawComplexControl(control, option, painter, widget); 901 | 902 | QRect rect = option->rect; 903 | switch (control) { 904 | case CC_ToolButton: 905 | if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast(option)) { 906 | QString buttonType = widget->property("type").toString(); 907 | QRect button, menuarea; 908 | button = subControlRect(control, toolbutton, SC_ToolButton, widget); 909 | menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget); 910 | 911 | State bflags = toolbutton->state; 912 | if (bflags & State_AutoRaise) { 913 | if (!(bflags & State_MouseOver)) { 914 | bflags &= ~State_Raised; 915 | } 916 | } 917 | 918 | State mflags = bflags; 919 | if (toolbutton->state & State_Sunken) { 920 | if (toolbutton->activeSubControls & SC_ToolButton) 921 | bflags |= State_Sunken; 922 | if (toolbutton->activeSubControls & SC_ToolButtonMenu) 923 | mflags |= State_Sunken; 924 | } 925 | 926 | QStyleOption tool(0); 927 | tool.palette = toolbutton->palette; 928 | if (toolbutton->subControls & SC_ToolButton) { 929 | if (buttonType == "dockbutton") { 930 | tool.rect = button; 931 | tool.state = bflags; 932 | drawPrimitive(PE_PanelButtonTool, &tool, painter, widget); 933 | } else { // paint status bar button style 934 | if (bflags & State_Sunken || bflags & State_On) 935 | drawCornerImage(d->buttonImage_pressed, painter, option->rect, 2, 2, 2, 2); 936 | else if (bflags & State_Enabled) { 937 | #ifndef Q_WS_MAC 938 | if (bflags & State_MouseOver) { 939 | drawCornerImage(d->buttonImage, painter, option->rect, 2, 2, 2, 2); 940 | QColor shade(255, 255, 255, 50); 941 | painter->fillRect(button.adjusted(1, 1, -1, -1), shade); 942 | } 943 | #endif 944 | } 945 | 946 | } 947 | } 948 | 949 | if (toolbutton->state & State_HasFocus) { 950 | QStyleOptionFocusRect fr; 951 | fr.QStyleOption::operator=(*toolbutton); 952 | fr.rect.adjust(3, 3, -3, -3); 953 | if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup) 954 | fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator, 955 | toolbutton, widget), 0); 956 | QPen oldPen = painter->pen(); 957 | QColor focusColor = panelTextColor(); 958 | focusColor.setAlpha(120); 959 | QPen outline(focusColor, 1); 960 | outline.setStyle(Qt::DotLine); 961 | painter->setPen(outline); 962 | QRect r = option->rect.adjusted(2, 2, -2, -2); 963 | painter->drawRect(r); 964 | painter->setPen(oldPen); 965 | } 966 | 967 | QStyleOptionToolButton label = *toolbutton; 968 | label.palette = panelPalette(option->palette); 969 | int fw = pixelMetric(PM_DefaultFrameWidth, option, widget); 970 | label.rect = button.adjusted(fw, fw, -fw, -fw); 971 | drawControl(CE_ToolButtonLabel, &label, painter, widget); 972 | 973 | if (toolbutton->subControls & SC_ToolButtonMenu) { 974 | tool.state = mflags; 975 | tool.rect = menuarea.adjusted(1, 1, -1, -1); 976 | if (mflags & (State_Sunken | State_On | State_Raised)) { 977 | painter->setPen(Qt::gray); 978 | painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft()); 979 | if (mflags & (State_Sunken)) { 980 | QColor shade(0, 0, 0, 50); 981 | painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); 982 | } 983 | #ifndef Q_WS_MAC 984 | else if (mflags & (State_MouseOver)) { 985 | QColor shade(255, 255, 255, 50); 986 | painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade); 987 | } 988 | #endif 989 | } 990 | tool.rect = tool.rect.adjusted(2, 2, -2, -2); 991 | drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget); 992 | } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) { 993 | int arrowSize = 6; 994 | QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1); 995 | QStyleOptionToolButton newBtn = *toolbutton; 996 | newBtn.palette = panelPalette(option->palette); 997 | newBtn.rect = QRect(ir.right() - arrowSize - 1, 998 | ir.height() - arrowSize - 2, arrowSize, arrowSize); 999 | drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget); 1000 | } 1001 | } 1002 | break; 1003 | 1004 | case CC_ComboBox: 1005 | if (const QStyleOptionComboBox *cb = qstyleoption_cast(option)) { 1006 | painter->save(); 1007 | bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull(); 1008 | bool reverse = option->direction == Qt::RightToLeft; 1009 | 1010 | // Draw tool button 1011 | QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight()); 1012 | grad.setColorAt(0, QColor(255, 255, 255, 20)); 1013 | grad.setColorAt(0.4, QColor(255, 255, 255, 60)); 1014 | grad.setColorAt(0.7, QColor(255, 255, 255, 50)); 1015 | grad.setColorAt(1, QColor(255, 255, 255, 40)); 1016 | painter->setPen(QPen(grad, 0)); 1017 | painter->drawLine(rect.topRight(), rect.bottomRight()); 1018 | grad.setColorAt(0, QColor(0, 0, 0, 30)); 1019 | grad.setColorAt(0.4, QColor(0, 0, 0, 70)); 1020 | grad.setColorAt(0.7, QColor(0, 0, 0, 70)); 1021 | grad.setColorAt(1, QColor(0, 0, 0, 40)); 1022 | painter->setPen(QPen(grad, 0)); 1023 | if (!reverse) 1024 | painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0)); 1025 | else 1026 | painter->drawLine(rect.topLeft(), rect.bottomLeft()); 1027 | QStyleOption toolbutton = *option; 1028 | if (isEmpty) 1029 | toolbutton.state &= ~(State_Enabled | State_Sunken); 1030 | painter->save(); 1031 | painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0)); 1032 | drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget); 1033 | painter->restore(); 1034 | // Draw arrow 1035 | int menuButtonWidth = 12; 1036 | int left = !reverse ? rect.right() - menuButtonWidth : rect.left(); 1037 | int right = !reverse ? rect.right() : rect.left() + menuButtonWidth; 1038 | QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9); 1039 | if (option->state & State_On) 1040 | arrowRect.translate(d->style->pixelMetric(PM_ButtonShiftHorizontal, option, widget), 1041 | d->style->pixelMetric(PM_ButtonShiftVertical, option, widget)); 1042 | 1043 | QStyleOption arrowOpt = *option; 1044 | arrowOpt.rect = arrowRect; 1045 | if (isEmpty) 1046 | arrowOpt.state &= ~(State_Enabled | State_Sunken); 1047 | 1048 | if (styleHint(SH_ComboBox_Popup, option, widget)) { 1049 | arrowOpt.rect.translate(0, -3); 1050 | drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget); 1051 | arrowOpt.rect.translate(0, 6); 1052 | drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); 1053 | } else { 1054 | drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget); 1055 | } 1056 | painter->restore(); 1057 | } 1058 | break; 1059 | default: 1060 | d->style->drawComplexControl(control, option, painter, widget); 1061 | break; 1062 | } 1063 | } 1064 | 1065 | // Mac style reimplements this to control the 1066 | // focus widget among other things 1067 | bool ManhattanStyle::event(QEvent *e) 1068 | { 1069 | Q_ASSERT(d->style); 1070 | return d->style->event(e); 1071 | } 1072 | 1073 | // Clamps float color values within (0, 255) 1074 | static int clamp(float x) 1075 | { 1076 | const int val = x > 255 ? 255 : static_cast(x); 1077 | return val < 0 ? 0 : val; 1078 | } 1079 | 1080 | QColor ManhattanStyle::shadowColor() 1081 | { 1082 | QColor result = baseColor(); 1083 | result.setHsv(result.hue(), 1084 | clamp(result.saturation() * 1.1), 1085 | clamp(result.value() * 0.70)); 1086 | return result; 1087 | } 1088 | 1089 | QColor ManhattanStyle::highlightColor() 1090 | { 1091 | QColor result = baseColor(); 1092 | result.setHsv(result.hue(), 1093 | clamp(result.saturation()), 1094 | clamp(result.value() * 1.16)); 1095 | return result; 1096 | } 1097 | 1098 | QColor ManhattanStyle::borderColor() 1099 | { 1100 | QColor result = baseColor(); 1101 | result.setHsv(result.hue(), 1102 | result.saturation(), 1103 | result.value() / 2); 1104 | return result; 1105 | } 1106 | 1107 | static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50) 1108 | { 1109 | const int maxFactor = 100; 1110 | QColor tmp = colorA; 1111 | tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor); 1112 | tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor); 1113 | tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor); 1114 | return tmp; 1115 | } 1116 | 1117 | 1118 | void ManhattanStyle::menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) 1119 | { 1120 | QString key; 1121 | key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(), clipRect.width(), 1122 | clipRect.height(), baseColor().rgb());; 1123 | QPixmap pixmap; 1124 | QPainter *p = painter; 1125 | QRect rect = clipRect; 1126 | if (usePixmapCache() && !QPixmapCache::find(key, pixmap)) { 1127 | pixmap = QPixmap(clipRect.size()); 1128 | p = new QPainter(&pixmap); 1129 | rect = QRect(0, 0, clipRect.width(), clipRect.height()); 1130 | } 1131 | 1132 | QLinearGradient grad(spanRect.topLeft(), spanRect.bottomLeft()); 1133 | QColor menuColor = mergedColors(baseColor(), QColor(240, 240, 240), 25); 1134 | grad.setColorAt(0, menuColor.lighter(112)); 1135 | grad.setColorAt(1, menuColor); 1136 | p->fillRect(rect, grad); 1137 | 1138 | if (usePixmapCache() && !QPixmapCache::find(key, pixmap)) { 1139 | painter->drawPixmap(clipRect.topLeft(), pixmap); 1140 | p->end(); 1141 | delete p; 1142 | QPixmapCache::insert(key, pixmap); 1143 | } 1144 | } 1145 | 1146 | 1147 | void ManhattanStyle::verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) 1148 | { 1149 | QString key; 1150 | key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(), clipRect.width(), 1151 | clipRect.height(), baseColor().rgb());; 1152 | QPixmap pixmap; 1153 | QPainter *p = painter; 1154 | QRect rect = clipRect; 1155 | if (usePixmapCache() && !QPixmapCache::find(key, pixmap)) { 1156 | pixmap = QPixmap(clipRect.size()); 1157 | p = new QPainter(&pixmap); 1158 | rect = QRect(0, 0, clipRect.width(), clipRect.height()); 1159 | } 1160 | 1161 | QColor base = baseColor(); 1162 | QLinearGradient grad(spanRect.topRight(), spanRect.topLeft()); 1163 | grad.setColorAt(0, highlightColor()); 1164 | grad.setColorAt(0.301, base); 1165 | grad.setColorAt(1, shadowColor()); 1166 | p->fillRect(rect, grad); 1167 | 1168 | QColor light(255, 255, 255, 80); 1169 | p->setPen(light); 1170 | p->drawLine(rect.topRight() - QPoint(1, 0), rect.bottomRight() - QPoint(1, 0)); 1171 | 1172 | if (usePixmapCache() && !QPixmapCache::find(key, pixmap)) { 1173 | painter->drawPixmap(clipRect.topLeft(), pixmap); 1174 | p->end(); 1175 | delete p; 1176 | QPixmapCache::insert(key, pixmap); 1177 | } 1178 | 1179 | } 1180 | 1181 | void ManhattanStyle::horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect) 1182 | { 1183 | QString key; 1184 | key.sprintf("mh_toolbar %d %d %d %d %d", spanRect.width(), spanRect.height(), 1185 | clipRect.width(), clipRect.height(), baseColor().rgb()); 1186 | QPixmap pixmap; 1187 | QPainter *p = painter; 1188 | QRect rect = clipRect; 1189 | if (usePixmapCache() && !QPixmapCache::find(key, pixmap)) { 1190 | pixmap = QPixmap(clipRect.size()); 1191 | p = new QPainter(&pixmap); 1192 | rect = QRect(0, 0, clipRect.width(), clipRect.height()); 1193 | } 1194 | 1195 | QColor base = baseColor(); 1196 | QLinearGradient grad(rect.topLeft(), rect.bottomLeft()); 1197 | 1198 | grad.setColorAt(0, highlightColor().lighter(120)); 1199 | grad.setColorAt(0.4, highlightColor()); 1200 | grad.setColorAt(0.401, base); 1201 | grad.setColorAt(1, shadowColor()); 1202 | p->fillRect(rect, grad); 1203 | 1204 | QLinearGradient shadowGradient(spanRect.topLeft(), spanRect.topRight()); 1205 | shadowGradient.setColorAt(0, QColor(0, 0, 0, 30)); 1206 | QColor highlight = highlightColor().lighter(130); 1207 | highlight.setAlpha(100); 1208 | shadowGradient.setColorAt(0.7, highlight); 1209 | shadowGradient.setColorAt(1, QColor(0, 0, 0, 40)); 1210 | p->fillRect(rect, shadowGradient); 1211 | 1212 | if (usePixmapCache() && !QPixmapCache::find(key, pixmap)) { 1213 | painter->drawPixmap(clipRect.topLeft(), pixmap); 1214 | p->end(); 1215 | delete p; 1216 | QPixmapCache::insert(key, pixmap); 1217 | } 1218 | } 1219 | 1220 | -------------------------------------------------------------------------------- /manhattanstyle.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Qt Software Information (qt-info@nokia.com) 8 | ** 9 | ** Commercial Usage 10 | ** 11 | ** Licensees holding valid Qt Commercial licenses may use this file in 12 | ** accordance with the Qt Commercial License Agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and Nokia. 15 | ** 16 | ** GNU Lesser General Public License Usage 17 | ** 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** If you are unsure which license is appropriate for your use, please 26 | ** contact the sales department at qt-sales@nokia.com. 27 | ** 28 | **************************************************************************/ 29 | 30 | // Orginal file comes from an old version of Qt creator. Don't remember which one. Something around V1.2 31 | // Small modifications should have been tagged with "// LOLO" 32 | 33 | #ifndef MANHATTANSTYLE_H 34 | #define MANHATTANSTYLE_H 35 | 36 | #include 37 | #include 38 | 39 | 40 | QT_BEGIN_NAMESPACE 41 | class QLinearGradient; 42 | class QBrush; 43 | QT_END_NAMESPACE 44 | 45 | class ManhattanStylePrivate; 46 | 47 | class ManhattanStyle : public QWindowsStyle 48 | { 49 | Q_OBJECT; 50 | 51 | public: 52 | ManhattanStyle(const QString &); 53 | 54 | ~ManhattanStyle(); 55 | 56 | void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const; 57 | void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = 0) const; 58 | void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget = 0) const; 59 | 60 | QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const; 61 | QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const; 62 | QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const; 63 | 64 | SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget = 0) const; 65 | QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget = 0) const; 66 | int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const; 67 | QRect itemRect(QPainter *p, const QRect &r, int flags, bool enabled, const QPixmap *pixmap, const QString &text, int len = -1) const; 68 | QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const; 69 | 70 | int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const; 71 | 72 | QPalette standardPalette() const; 73 | 74 | void polish(QWidget *widget); 75 | void polish(QPalette &pal); 76 | void polish(QApplication *app); 77 | 78 | void unpolish(QWidget *widget); 79 | void unpolish(QApplication *app); 80 | 81 | protected: 82 | bool event(QEvent *e); 83 | 84 | protected Q_SLOTS: 85 | QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const; 86 | int layoutSpacingImplementation(QSizePolicy::ControlType control1, 87 | QSizePolicy::ControlType control2, 88 | Qt::Orientation orientation, 89 | const QStyleOption *option = 0, 90 | const QWidget *widget = 0) const; 91 | 92 | public: 93 | // Height of the project explorer navigation bar 94 | static int navigationWidgetHeight() { return 24; } 95 | // static qreal sidebarFontSize(); 96 | // static QPalette sidebarFontPalette(const QPalette &original); 97 | 98 | // This is our color table, all colors derive from baseColor 99 | static QColor baseColor(){ return QColor(0x7579a8); } // Qt : 79629c // LOLO : 7579a8 or a99bd0 100 | static QColor panelTextColor() { return Qt::white; } 101 | static QColor highlightColor(); 102 | static QColor shadowColor(); 103 | static QColor borderColor(); 104 | static QColor buttonTextColor() { return QColor(0x4c4c4c); } 105 | 106 | // Sets the base color and makes sure all top level widgets are updated 107 | static void setBaseColor(const QColor &color); 108 | 109 | // Gradients used for panels 110 | static void horizontalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); 111 | static void verticalGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); 112 | static void menuGradient(QPainter *painter, const QRect &spanRect, const QRect &clipRect); 113 | 114 | // Pixmap cache should only be enabled for X11 due to slow gradients 115 | static bool usePixmapCache() { return false; } // lolo : false. Original:true 116 | 117 | 118 | 119 | 120 | 121 | private: 122 | ManhattanStylePrivate *d; 123 | Q_DISABLE_COPY(ManhattanStyle) 124 | 125 | }; 126 | 127 | #endif // MANHATTANSTYLE_H 128 | -------------------------------------------------------------------------------- /sclview.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icones/attribute.png 4 | icones/type.png 5 | icones/close.png 6 | icones/Schema.png 7 | icones/WhiteRect.png 8 | icones/find.png 9 | icones/Express.png 10 | icones/redo.png 11 | icones/undo.png 12 | 13 | 14 | -------------------------------------------------------------------------------- /styleanimator.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Qt Software Information (qt-info@nokia.com) 8 | ** 9 | ** Commercial Usage 10 | ** 11 | ** Licensees holding valid Qt Commercial licenses may use this file in 12 | ** accordance with the Qt Commercial License Agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and Nokia. 15 | ** 16 | ** GNU Lesser General Public License Usage 17 | ** 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** If you are unsure which license is appropriate for your use, please 26 | ** contact the sales department at qt-sales@nokia.com. 27 | ** 28 | **************************************************************************/ 29 | 30 | #include "styleanimator.h" 31 | 32 | #include 33 | 34 | Animation * StyleAnimator::widgetAnimation(const QWidget *widget) const 35 | { 36 | if (!widget) 37 | return 0; 38 | foreach (Animation *a, animations) { 39 | if (a->widget() == widget) 40 | return a; 41 | } 42 | return 0; 43 | } 44 | 45 | void Animation::paint(QPainter *painter, const QStyleOption *option) 46 | { 47 | Q_UNUSED(option); 48 | Q_UNUSED(painter); 49 | } 50 | 51 | void Animation::drawBlendedImage(QPainter *painter, QRect rect, float alpha) 52 | { 53 | if (m_secondaryImage.isNull() || m_primaryImage.isNull()) 54 | return; 55 | 56 | if (m_tempImage.isNull()) 57 | m_tempImage = m_secondaryImage; 58 | 59 | const int a = qRound(alpha*256); 60 | const int ia = 256 - a; 61 | const int sw = m_primaryImage.width(); 62 | const int sh = m_primaryImage.height(); 63 | const int bpl = m_primaryImage.bytesPerLine(); 64 | switch (m_primaryImage.depth()) { 65 | case 32: 66 | { 67 | uchar *mixed_data = m_tempImage.bits(); 68 | const uchar *back_data = m_primaryImage.bits(); 69 | const uchar *front_data = m_secondaryImage.bits(); 70 | for (int sy = 0; sy < sh; sy++) { 71 | quint32 *mixed = (quint32*)mixed_data; 72 | const quint32* back = (const quint32*)back_data; 73 | const quint32* front = (const quint32*)front_data; 74 | for (int sx = 0; sx < sw; sx++) { 75 | quint32 bp = back[sx]; 76 | quint32 fp = front[sx]; 77 | mixed[sx] = qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8, 78 | (qGreen(bp)*ia + qGreen(fp)*a)>>8, 79 | (qBlue(bp)*ia + qBlue(fp)*a)>>8, 80 | (qAlpha(bp)*ia + qAlpha(fp)*a)>>8); 81 | } 82 | mixed_data += bpl; 83 | back_data += bpl; 84 | front_data += bpl; 85 | } 86 | } 87 | default: 88 | break; 89 | } 90 | painter->drawImage(rect, m_tempImage); 91 | } 92 | 93 | void Transition::paint(QPainter *painter, const QStyleOption *option) 94 | { 95 | float alpha = 1.0; 96 | if (m_duration > 0) { 97 | QTime current = QTime::currentTime(); 98 | 99 | if (m_startTime > current) 100 | m_startTime = current; 101 | 102 | int timeDiff = m_startTime.msecsTo(current); 103 | alpha = timeDiff/(float)m_duration; 104 | if (timeDiff > m_duration) { 105 | m_running = false; 106 | alpha = 1.0; 107 | } 108 | } 109 | else { 110 | m_running = false; 111 | } 112 | drawBlendedImage(painter, option->rect, alpha); 113 | } 114 | 115 | void StyleAnimator::timerEvent(QTimerEvent *) 116 | { 117 | for (int i = animations.size() - 1 ; i >= 0 ; --i) { 118 | if (animations[i]->widget()) 119 | animations[i]->widget()->update(); 120 | 121 | if (!animations[i]->widget() || 122 | !animations[i]->widget()->isEnabled() || 123 | !animations[i]->widget()->isVisible() || 124 | animations[i]->widget()->window()->isMinimized() || 125 | !animations[i]->running()) 126 | { 127 | Animation *a = animations.takeAt(i); 128 | delete a; 129 | } 130 | } 131 | if (animations.size() == 0 && animationTimer.isActive()) { 132 | animationTimer.stop(); 133 | } 134 | } 135 | 136 | void StyleAnimator::stopAnimation(const QWidget *w) 137 | { 138 | for (int i = animations.size() - 1 ; i >= 0 ; --i) { 139 | if (animations[i]->widget() == w) { 140 | Animation *a = animations.takeAt(i); 141 | delete a; 142 | break; 143 | } 144 | } 145 | } 146 | 147 | void StyleAnimator::startAnimation(Animation *t) 148 | { 149 | stopAnimation(t->widget()); 150 | animations.append(t); 151 | if (animations.size() > 0 && !animationTimer.isActive()) { 152 | animationTimer.start(35, this); 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /styleanimator.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | ** 3 | ** This file is part of Qt Creator 4 | ** 5 | ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 6 | ** 7 | ** Contact: Qt Software Information (qt-info@nokia.com) 8 | ** 9 | ** Commercial Usage 10 | ** 11 | ** Licensees holding valid Qt Commercial licenses may use this file in 12 | ** accordance with the Qt Commercial License Agreement provided with the 13 | ** Software or, alternatively, in accordance with the terms contained in 14 | ** a written agreement between you and Nokia. 15 | ** 16 | ** GNU Lesser General Public License Usage 17 | ** 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser 19 | ** General Public License version 2.1 as published by the Free Software 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the 21 | ** packaging of this file. Please review the following information to 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 24 | ** 25 | ** If you are unsure which license is appropriate for your use, please 26 | ** contact the sales department at qt-sales@nokia.com. 27 | ** 28 | **************************************************************************/ 29 | 30 | #ifndef ANIMATION_H 31 | #define ANIMATION_H 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | /* 41 | * This is a set of helper classes to allow for widget animations in 42 | * the style. Its mostly taken from Vista style so it should be fully documented 43 | * there. 44 | * 45 | */ 46 | 47 | class Animation 48 | { 49 | public : 50 | Animation() : m_running(true) { } 51 | virtual ~Animation() { } 52 | QWidget * widget() const { return m_widget; } 53 | bool running() const { return m_running; } 54 | const QTime &startTime() const { return m_startTime; } 55 | void setRunning(bool val) { m_running = val; } 56 | void setWidget(QWidget *widget) { m_widget = widget; } 57 | void setStartTime(const QTime &startTime) { m_startTime = startTime; } 58 | virtual void paint(QPainter *painter, const QStyleOption *option); 59 | 60 | protected: 61 | void drawBlendedImage(QPainter *painter, QRect rect, float value); 62 | QTime m_startTime; 63 | QPointer m_widget; 64 | QImage m_primaryImage; 65 | QImage m_secondaryImage; 66 | QImage m_tempImage; 67 | bool m_running; 68 | }; 69 | 70 | // Handles state transition animations 71 | class Transition : public Animation 72 | { 73 | public : 74 | Transition() : Animation() {} 75 | virtual ~Transition() {} 76 | void setDuration(int duration) { m_duration = duration; } 77 | void setStartImage(const QImage &image) { m_primaryImage = image; } 78 | void setEndImage(const QImage &image) { m_secondaryImage = image; } 79 | virtual void paint(QPainter *painter, const QStyleOption *option); 80 | int duration() const { return m_duration; } 81 | int m_duration; //set time in ms to complete a state transition 82 | }; 83 | 84 | class StyleAnimator : public QObject 85 | { 86 | Q_OBJECT; 87 | 88 | public: 89 | StyleAnimator(QObject *parent = 0) : QObject(parent) {} 90 | 91 | void timerEvent(QTimerEvent *); 92 | void startAnimation(Animation *); 93 | void stopAnimation(const QWidget *); 94 | Animation* widgetAnimation(const QWidget *) const; 95 | 96 | private: 97 | QBasicTimer animationTimer; 98 | QList animations; 99 | }; 100 | 101 | #endif // ANIMATION_H 102 | -------------------------------------------------------------------------------- /textView/ExpressSyntaxHighlighter.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ExpressSyntaxHighlighter.h" 21 | 22 | #include 23 | using namespace std; 24 | 25 | ExpressSyntaxHighlighter::ExpressSyntaxHighlighter(QTextDocument *parent) : 26 | QSyntaxHighlighter(parent) 27 | { 28 | HighlightingRule rule; 29 | 30 | keywordFormat.setForeground(QColor(0,0,128)); 31 | //keywordFormat.setFontWeight(QFont::Bold); 32 | QStringList keywordPatterns; 33 | keywordPatterns << "\\bTYPE\\b" << "\\bEND_TYPE\\b" 34 | << "\\bENUMERATION OF\\b" 35 | << "\\bSELECT\\b" 36 | << "\\bENTITY\\b" << "\\bEND_ENTITY\\b" 37 | << "\\bABSTRACT\\b" 38 | << "\\bSUBTYPE OF\\b" << "\\bSUPERTYPE\\b" << "\\bSUPERTYPE OF\\b" << "\\bONEOF\\b" 39 | << "\\bDERIVE\\b" 40 | << "\\bOPTIONAL\\b" 41 | // << "\\bWHERE\\b" << "\\bEND_RULE\\b" 42 | ; 43 | foreach (const QString &pattern, keywordPatterns) 44 | { 45 | rule.pattern = QRegExp(pattern, Qt::CaseInsensitive); 46 | rule.format = keywordFormat; 47 | highlightingRules.append(rule); 48 | } 49 | 50 | primitiveFormat.setForeground(QColor(128,128,0)); 51 | 52 | // StringList and foreach not YET necessary since there is only ONE pattern 53 | // but what will be tomorrow? 54 | QStringList primitivePatterns; 55 | // the regexp: 56 | // starts with a word \\b 57 | // that can be INTEGER|REAL... 58 | // it is followed (?= 59 | // by 0 or 1 ?: 60 | // ; or whitespace ;|\\s 61 | primitivePatterns << "\\b(INTEGER|REAL|BOOLEAN|LOGICAL|STRING|BINARY|NUMBER)(?=(?:;|\\s))" ; 62 | 63 | foreach (const QString &pattern, primitivePatterns) 64 | { 65 | rule.pattern = QRegExp(pattern, Qt::CaseInsensitive); 66 | rule.format = primitiveFormat; 67 | highlightingRules.append(rule); 68 | } 69 | } 70 | 71 | void ExpressSyntaxHighlighter::fillTypes(const QStringList &list) 72 | { 73 | HighlightingRule rule; 74 | 75 | typeFormat.setForeground(QColor(128,0,0)); 76 | QStringList typePatterns; 77 | int typeCount =list.count(); 78 | for (int i=0; i= 0) 120 | { 121 | int length = expression.matchedLength(); 122 | setFormat(index, length, rule.format); 123 | index = expression.indexIn(text, index + length); 124 | } 125 | } 126 | setCurrentBlockState(0); 127 | } 128 | 129 | /* from Part 11: 130 | // Express keyword list: 131 | abstract aggregate alias array 132 | as bag based_on begin 133 | binary boolean by case 134 | constant derive else end 135 | end_alias end_case end_constant end_entity 136 | end_function end_if end_local end_procedure 137 | end_repeat end_rule end_schema end_subtype_constraint 138 | end_type entity enumeration escape 139 | extensible fixed for from 140 | function generic generic_entity if 141 | integer inverse list local 142 | logical number of oneof 143 | optional otherwise procedure query 144 | real renamed reference repeat 145 | return rule schema select 146 | set skip string subtype 147 | subtype constraint supertype then to 148 | total_over type unique until 149 | use var where while 150 | with 151 | 152 | // operators 153 | and andor div in 154 | like mod not or 155 | xor 156 | 157 | //constants 158 | ? self const e pi 159 | false true unknown 160 | 161 | //functions 162 | abs acos asin atan 163 | blength cos exists exp 164 | format hibound hiindex length 165 | lobound log log2 log10 166 | loindex nvl odd rolesof 167 | sin sizeof sqrt tan 168 | typeof usedin value value_in 169 | value unique 170 | 171 | // procedures 172 | insert remove 173 | */ 174 | -------------------------------------------------------------------------------- /textView/ExpressSyntaxHighlighter.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef EXPRESSSYNTAXHIGHLIGHTER_H 21 | #define EXPRESSSYNTAXHIGHLIGHTER_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class QTextDocument; 28 | 29 | class ExpressSyntaxHighlighter : public QSyntaxHighlighter 30 | { 31 | Q_OBJECT 32 | public: 33 | explicit ExpressSyntaxHighlighter(QTextDocument *parent = 0); 34 | void fillTypes(const QStringList & list); 35 | void fillEntities(const QStringList & list); 36 | protected: 37 | void highlightBlock(const QString &text); 38 | 39 | signals: 40 | 41 | public slots: 42 | 43 | 44 | private: 45 | struct HighlightingRule 46 | { 47 | QRegExp pattern; 48 | QTextCharFormat format; 49 | }; 50 | QVector highlightingRules; 51 | 52 | QTextCharFormat keywordFormat; 53 | QTextCharFormat primitiveFormat; 54 | QTextCharFormat typeFormat; 55 | QTextCharFormat entityFormat; 56 | 57 | }; 58 | 59 | #endif // EXPRESSSYNTAXHIGHLIGHTER_H 60 | -------------------------------------------------------------------------------- /textView/ExpressTextEdit.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ExpressTextEdit.h" 21 | #include "ExpressSyntaxHighlighter.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | using namespace std; 29 | 30 | ExpressTextEdit::ExpressTextEdit(Registry *registry, QWidget *parent) 31 | : QTextEdit(parent) 32 | , m_Registry(registry) 33 | , m_Highlighter ( new ExpressSyntaxHighlighter(this->document())) 34 | { 35 | setMouseTracking(true); 36 | 37 | // fill Highlighter with types 38 | QStringList list; 39 | const TypeDescriptor * typeDescriptor; 40 | m_Registry->ResetTypes(); 41 | while ( (typeDescriptor= m_Registry->NextType() ) ) 42 | list << typeDescriptor->Name(); 43 | m_Highlighter->fillTypes(list); 44 | 45 | // fill Highlighter with types 46 | list.clear(); 47 | const EntityDescriptor * entityDescriptor; 48 | m_Registry->ResetEntities(); 49 | while ( (entityDescriptor= m_Registry->NextEntity() ) ) 50 | list << entityDescriptor->Name(); 51 | m_Highlighter->fillEntities(list); 52 | } 53 | 54 | ExpressTextEdit::~ExpressTextEdit() 55 | { 56 | delete m_Highlighter; 57 | } 58 | 59 | void ExpressTextEdit::mouseMoveEvent(QMouseEvent *e) 60 | { 61 | QTextCursor cursor = cursorForPosition(e->pos()); 62 | cursor.select(QTextCursor::WordUnderCursor); 63 | QString wordUnderCursor = cursor.selectedText(); 64 | 65 | const EntityDescriptor * entityDescriptor = m_Registry->FindEntity(wordUnderCursor.toAscii()); 66 | const TypeDescriptor * typeDescriptor = m_Registry->FindType(wordUnderCursor.toAscii()); 67 | if (entityDescriptor ) 68 | { 69 | std::string str; 70 | setToolTip(entityDescriptor->GenerateExpress(str)); 71 | if (QApplication::overrideCursor()==0) 72 | QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); 73 | } 74 | else if(typeDescriptor) 75 | { 76 | std::string str; 77 | setToolTip(typeDescriptor->GenerateExpress(str)); 78 | if (QApplication::overrideCursor()==0) 79 | QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor)); 80 | } 81 | else 82 | { 83 | setToolTip(QString()); 84 | QApplication::restoreOverrideCursor(); 85 | } 86 | } 87 | 88 | void ExpressTextEdit::mousePressEvent(QMouseEvent *e) 89 | { 90 | if (e->modifiers()==Qt::ControlModifier) 91 | { 92 | QTextEdit::mousePressEvent(e); 93 | navigate(e); 94 | } 95 | } 96 | 97 | void ExpressTextEdit::mouseDoubleClickEvent(QMouseEvent *e) 98 | { 99 | navigate(e); 100 | QTextEdit::mouseDoubleClickEvent(e); 101 | } 102 | 103 | void ExpressTextEdit::leaveEvent(QEvent *e) 104 | { 105 | QApplication::restoreOverrideCursor(); 106 | } 107 | 108 | void ExpressTextEdit::setDescriptor(const TypeDescriptor *typeDescriptor) 109 | { 110 | clear(); 111 | if (typeDescriptor) 112 | { 113 | std::string str; 114 | QString text(typeDescriptor->GenerateExpress(str)); 115 | setPlainText(text); 116 | } 117 | } 118 | 119 | void ExpressTextEdit::navigate(QMouseEvent *e) 120 | { 121 | // QTextCursor cursor = textCursor(); 122 | QTextCursor cursor = cursorForPosition(e->pos()); 123 | cursor.select(QTextCursor::WordUnderCursor); 124 | QString wordUnderCursor = cursor.selectedText(); 125 | 126 | const EntityDescriptor * entityDescriptor = m_Registry->FindEntity(wordUnderCursor.toAscii()); 127 | const TypeDescriptor * typeDescriptor = m_Registry->FindType(wordUnderCursor.toAscii()); 128 | // TODO : ?????????!!!!!!!!!!!!???????? 129 | if (entityDescriptor ) 130 | emit descriptorDoubleClicked(entityDescriptor); 131 | else if(typeDescriptor) 132 | emit descriptorDoubleClicked(typeDescriptor); 133 | } 134 | 135 | -------------------------------------------------------------------------------- /textView/ExpressTextEdit.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef EXPRESSTEXTEDIT_H 21 | #define EXPRESSTEXTEDIT_H 22 | 23 | #include 24 | 25 | class Registry; 26 | class EntityDescriptor; 27 | class TypeDescriptor; 28 | class ExpressSyntaxHighlighter; 29 | 30 | class ExpressTextEdit : public QTextEdit 31 | { 32 | Q_OBJECT 33 | public: 34 | explicit ExpressTextEdit(Registry *registry, QWidget *parent=0); 35 | ~ExpressTextEdit(); 36 | 37 | protected: 38 | virtual void mouseMoveEvent(QMouseEvent *e); 39 | virtual void mousePressEvent(QMouseEvent *e); 40 | virtual void mouseDoubleClickEvent(QMouseEvent *e); 41 | virtual void leaveEvent(QEvent *e); 42 | 43 | signals: 44 | void descriptorDoubleClicked(const TypeDescriptor *); 45 | 46 | public slots: 47 | void setDescriptor(const TypeDescriptor * typeDescriptor); 48 | 49 | private: 50 | void navigate(QMouseEvent *e); 51 | 52 | 53 | private: 54 | Registry * m_Registry; 55 | ExpressSyntaxHighlighter * m_Highlighter; 56 | }; 57 | 58 | #endif // EXPRESSTEXTEDIT_H 59 | -------------------------------------------------------------------------------- /textView/ExpressViewDockWidget.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #include "ExpressViewDockWidget.h" 21 | #include "ExpressTextEdit.h" 22 | #include 23 | #include 24 | 25 | ExpressViewDockWidget::ExpressViewDockWidget(QWidget *parent) 26 | : QDockWidget(tr("Express View"), parent) 27 | , m_ToolBar (new QToolBar(this)) 28 | { 29 | // Build ToolBar 30 | setTitleBarWidget(m_ToolBar); 31 | m_ToolBar->setContentsMargins(0, 0, 0, 0); 32 | toggleViewAction()->setIcon(QIcon(":/Express")); 33 | toggleViewAction()->setShortcut( QKeySequence(Qt::Key_F4) ); 34 | 35 | QWidget * toolBarSpacer= new QWidget(m_ToolBar); 36 | toolBarSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); 37 | QAction * hideDockWidgetAction = new QAction(QIcon(":close"), tr("Hide Explorer"), this); 38 | 39 | m_ToolBar->addWidget(toolBarSpacer); 40 | m_ToolBar->addAction(hideDockWidgetAction); 41 | 42 | connect ( hideDockWidgetAction, SIGNAL(triggered()), this, SLOT (hide() ) ); 43 | 44 | // content 45 | setContentsMargins(0,0,-1,0); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /textView/ExpressViewDockWidget.h: -------------------------------------------------------------------------------- 1 | /* This file is part of SCView, a STEP-Express viewer based on StepCode 2 | Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public 6 | License as published by the Free Software Foundation; version 2 7 | of the License. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public License 15 | along with this library; see the file COPYING.LIB. If not, write to 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 | Boston, MA 02110-1301, USA. 18 | */ 19 | 20 | #ifndef EXPRESSVIEWDOCKWIDGET_H 21 | #define EXPRESSVIEWDOCKWIDGET_H 22 | 23 | #include 24 | 25 | class ExpressTextEdit; 26 | class QToolBar; 27 | 28 | class ExpressViewDockWidget : public QDockWidget 29 | { 30 | Q_OBJECT 31 | public: 32 | explicit ExpressViewDockWidget(QWidget *parent = 0); 33 | 34 | signals: 35 | 36 | public slots: 37 | 38 | private: 39 | QToolBar * m_ToolBar; 40 | 41 | }; 42 | 43 | #endif // EXPRESSVIEWDOCKWIDGET_H 44 | --------------------------------------------------------------------------------