Wed, 04 Jun 2014 01:43:21 +0300
- added primitives toolbox
changelog.txt | file | annotate | diff | comparison | revisions | |
src/addObjectDialog.cc | file | annotate | diff | comparison | revisions | |
src/glRenderer.cc | file | annotate | diff | comparison | revisions | |
src/glRenderer.h | file | annotate | diff | comparison | revisions | |
src/main.cc | file | annotate | diff | comparison | revisions | |
src/mainWindow.cc | file | annotate | diff | comparison | revisions | |
src/mainWindow.h | file | annotate | diff | comparison | revisions | |
src/primitives.cc | file | annotate | diff | comparison | revisions | |
ui/ldforge.ui | file | annotate | diff | comparison | revisions |
--- a/changelog.txt Tue Jun 03 20:28:10 2014 +0300 +++ b/changelog.txt Wed Jun 04 01:43:21 2014 +0300 @@ -36,6 +36,7 @@ + - Made the coordinate rounding precision configurable. + - Inverting a subfile now detects whether the subfile is flat and flips it if it is instead of naively invertnexting everything. + - Added an action for opening the subfiles pointed to by selected references as editable documents. ++ - Added a toolbox for primitives. These primitives can be dragged and dropped into the main viewport. - - The camera is now changed to the top one if switching to draw mode while using the free camera instead of disabling the draw mode. - - The color selector now uses the color's edge color for the borders instead of black.
--- a/src/addObjectDialog.cc Tue Jun 03 20:28:10 2014 +0300 +++ b/src/addObjectDialog.cc Wed Jun 04 01:43:21 2014 +0300 @@ -37,22 +37,6 @@ // ============================================================================= // -class SubfileListItem : public QTreeWidgetItem -{ - PROPERTY (public, Primitive*, primitive, setPrimitive, STOCK_WRITE) - - public: - SubfileListItem (QTreeWidgetItem* parent, Primitive* info) : - QTreeWidgetItem (parent), - m_primitive (info) {} - - SubfileListItem (QTreeWidget* parent, Primitive* info) : - QTreeWidgetItem (parent), - m_primitive (info) {} -}; - -// ============================================================================= -// AddObjectDialog::AddObjectDialog (const LDObjectType type, LDObjectPtr obj, QWidget* parent) : QDialog (parent) { @@ -116,27 +100,7 @@ coordCount = 3; tw_subfileList = new QTreeWidget(); tw_subfileList->setHeaderLabel (tr ("Primitives")); - - for (PrimitiveCategory* cat : g_PrimitiveCategories) - { - SubfileListItem* parentItem = new SubfileListItem (tw_subfileList, null); - parentItem->setText (0, cat->name()); - QList<QTreeWidgetItem*> subfileItems; - - for (Primitive& prim : cat->prims) - { - SubfileListItem* item = new SubfileListItem (parentItem, &prim); - item->setText (0, format ("%1 - %2", prim.name, prim.title)); - subfileItems << item; - - // If this primitive is the one the current object points to, - // select it by default - if (obj && obj.staticCast<LDSubfile>()->fileInfo()->name() == prim.name) - tw_subfileList->setCurrentItem (item); - } - - tw_subfileList->addTopLevelItem (parentItem); - } + populatePrimitives (tw_subfileList, (obj != null ? obj.staticCast<LDSubfile>()->fileInfo()->name() : "")); connect (tw_subfileList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_subfileTypeChanged())); lb_subfileName = new QLabel ("File:");
--- a/src/glRenderer.cc Tue Jun 03 20:28:10 2014 +0300 +++ b/src/glRenderer.cc Wed Jun 04 01:43:21 2014 +0300 @@ -126,11 +126,11 @@ m_toolTipTimer = new QTimer (this); m_toolTipTimer->setSingleShot (true); m_isCameraMoving = false; - connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); - m_thickBorderPen = QPen (QColor (0, 0, 0, 208), 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); m_thinBorderPen = m_thickBorderPen; m_thinBorderPen.setWidth (1); + setAcceptDrops (true); + connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); // Init camera icons for (ECamera cam = EFirstCamera; cam < ENumCameras; ++cam) @@ -2177,3 +2177,26 @@ update(); } +void GLRenderer::dragEnterEvent (QDragEnterEvent* ev) +{ + if (g_win != null && ev->source() == g_win->getPrimitivesTree() && g_win->getPrimitivesTree()->currentItem() != null) + ev->acceptProposedAction(); +} + +void GLRenderer::dropEvent (QDropEvent* ev) +{ + if (g_win != null && ev->source() == g_win->getPrimitivesTree()) + { + QString primName = static_cast<SubfileListItem*> (g_win->getPrimitivesTree()->currentItem())->primitive()->name; + LDSubfilePtr ref = spawn<LDSubfile>(); + ref->setColor (maincolor); + ref->setFileInfo (getDocument (primName)); + ref->setPosition (g_origin); + ref->setTransform (g_identity); + LDDocument::current()->insertObj (g_win->getInsertionPoint(), ref); + ref->select(); + g_win->buildObjList(); + g_win->R()->refresh(); + ev->acceptProposedAction(); + } +}
--- a/src/glRenderer.h Tue Jun 03 20:28:10 2014 +0300 +++ b/src/glRenderer.h Wed Jun 04 01:43:21 2014 +0300 @@ -187,6 +187,8 @@ protected: void contextMenuEvent (QContextMenuEvent* ev); + void dragEnterEvent (QDragEnterEvent* ev); + void dropEvent (QDropEvent* ev); void initializeGL(); void keyPressEvent (QKeyEvent* ev); void keyReleaseEvent (QKeyEvent* ev);
--- a/src/main.cc Tue Jun 03 20:28:10 2014 +0300 +++ b/src/main.cc Wed Jun 04 01:43:21 2014 +0300 @@ -64,6 +64,7 @@ LDPaths::initPaths(); initColors(); + loadPrimitives(); MainWindow* win = new MainWindow; newFile(); win->show(); @@ -77,6 +78,5 @@ Config::save(); } - loadPrimitives(); return app.exec(); }
--- a/src/mainWindow.cc Tue Jun 03 20:28:10 2014 +0300 +++ b/src/mainWindow.cc Wed Jun 04 01:43:21 2014 +0300 @@ -48,6 +48,7 @@ #include "messageLog.h" #include "configuration.h" #include "ui_ldforge.h" +#include "primitives.h" static bool g_isSelectionLocked = false; @@ -84,6 +85,11 @@ connect (ui->objectList, SIGNAL (itemDoubleClicked (QListWidgetItem*)), this, SLOT (slot_editObject (QListWidgetItem*))); connect (m_tabs, SIGNAL (currentChanged(int)), this, SLOT (changeCurrentFile())); + if (getActivePrimitiveScanner() != null) + connect (getActivePrimitiveScanner(), SIGNAL (workDone()), this, SLOT (updatePrimitives())); + else + updatePrimitives(); + m_msglog = new MessageManager; m_msglog->setRenderer (R()); m_renderer->setMessageLog (m_msglog); @@ -991,6 +997,13 @@ // ============================================================================= // +void MainWindow::updatePrimitives() +{ + populatePrimitives (ui->primitives); +} + +// ============================================================================= +// QImage imageFromScreencap (uchar* data, int w, int h) { // GL and Qt formats have R and B swapped. Also, GL flips Y - correct it as well. @@ -1016,3 +1029,29 @@ { return color() == null; } + +void populatePrimitives (QTreeWidget* tw, QString const& selectByDefault) +{ + tw->clear(); + + for (PrimitiveCategory* cat : g_PrimitiveCategories) + { + SubfileListItem* parentItem = new SubfileListItem (tw, null); + parentItem->setText (0, cat->name()); + QList<QTreeWidgetItem*> subfileItems; + + for (Primitive& prim : cat->prims) + { + SubfileListItem* item = new SubfileListItem (parentItem, &prim); + item->setText (0, format ("%1 - %2", prim.name, prim.title)); + subfileItems << item; + + // If this primitive is the one the current object points to, + // select it by default + if (selectByDefault == prim.name) + tw->setCurrentItem (item); + } + + tw->addTopLevelItem (parentItem); + } +}
--- a/src/mainWindow.h Tue Jun 03 20:28:10 2014 +0300 +++ b/src/mainWindow.h Wed Jun 04 01:43:21 2014 +0300 @@ -34,6 +34,7 @@ class QComboBox; class QProgressBar; class Ui_LDForgeUI; +class Primitive; // Stuff for dialogs #define IMPLEMENT_DIALOG_BUTTONS \ @@ -188,7 +189,13 @@ void endAction(); + inline QTreeWidget* getPrimitivesTree() const + { + return ui->primitives; + } + public slots: + void updatePrimitives(); void changeCurrentFile(); void slot_action(); void slot_actionNew(); @@ -373,3 +380,21 @@ } } } + +// ============================================================================= +// +class SubfileListItem : public QTreeWidgetItem +{ + PROPERTY (public, Primitive*, primitive, setPrimitive, STOCK_WRITE) + + public: + SubfileListItem (QTreeWidgetItem* parent, Primitive* info) : + QTreeWidgetItem (parent), + m_primitive (info) {} + + SubfileListItem (QTreeWidget* parent, Primitive* info) : + QTreeWidgetItem (parent), + m_primitive (info) {} +}; + +void populatePrimitives (QTreeWidget* tw, const QString& selectByDefault = QString());
--- a/src/primitives.cc Tue Jun 03 20:28:10 2014 +0300 +++ b/src/primitives.cc Wed Jun 04 01:43:21 2014 +0300 @@ -73,6 +73,9 @@ if (line.endsWith ("\n")) line.chop (1); + if (line.endsWith ("\r")) + line.chop (1); + int space = line.indexOf (" "); if (space == -1)
--- a/ui/ldforge.ui Tue Jun 03 20:28:10 2014 +0300 +++ b/ui/ldforge.ui Wed Jun 04 01:43:21 2014 +0300 @@ -38,16 +38,68 @@ </widget> </item> <item> - <widget class="QListWidget" name="objectList"> - <property name="sizePolicy"> - <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> + <widget class="QToolBox" name="toolBox"> + <property name="currentIndex"> + <number>0</number> </property> - <property name="selectionMode"> - <enum>QAbstractItemView::ExtendedSelection</enum> - </property> + <widget class="QWidget" name="pageDocument"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>233</width> + <height>436</height> + </rect> + </property> + <attribute name="label"> + <string>Document</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QListWidget" name="objectList"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ExtendedSelection</enum> + </property> + </widget> + </item> + </layout> + </widget> + <widget class="QWidget" name="pagePrimitives"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>233</width> + <height>436</height> + </rect> + </property> + <attribute name="label"> + <string>Primitives</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QTreeWidget" name="primitives"> + <property name="dragDropMode"> + <enum>QAbstractItemView::DragOnly</enum> + </property> + <attribute name="headerVisible"> + <bool>false</bool> + </attribute> + <column> + <property name="text"> + <string notr="true">1</string> + </property> + </column> + </widget> + </item> + </layout> + </widget> </widget> </item> </layout> @@ -60,7 +112,7 @@ <x>0</x> <y>0</y> <width>1010</width> - <height>24</height> + <height>25</height> </rect> </property> <widget class="QMenu" name="menuFile">