# HG changeset patch # User Santeri Piippo # Date 1401835401 -10800 # Node ID fe1b83f6ba82d32cd4a32f1ff318216a3825b2b9 # Parent 4b7306f52bb5e47c48ed60bd17204c4d84c55934 - added primitives toolbox diff -r 4b7306f52bb5 -r fe1b83f6ba82 changelog.txt --- 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. diff -r 4b7306f52bb5 -r fe1b83f6ba82 src/addObjectDialog.cc --- 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 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()->fileInfo()->name() == prim.name) - tw_subfileList->setCurrentItem (item); - } - - tw_subfileList->addTopLevelItem (parentItem); - } + populatePrimitives (tw_subfileList, (obj != null ? obj.staticCast()->fileInfo()->name() : "")); connect (tw_subfileList, SIGNAL (itemSelectionChanged()), this, SLOT (slot_subfileTypeChanged())); lb_subfileName = new QLabel ("File:"); diff -r 4b7306f52bb5 -r fe1b83f6ba82 src/glRenderer.cc --- 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 (g_win->getPrimitivesTree()->currentItem())->primitive()->name; + LDSubfilePtr ref = spawn(); + 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(); + } +} diff -r 4b7306f52bb5 -r fe1b83f6ba82 src/glRenderer.h --- 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); diff -r 4b7306f52bb5 -r fe1b83f6ba82 src/main.cc --- 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(); } diff -r 4b7306f52bb5 -r fe1b83f6ba82 src/mainWindow.cc --- 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 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); + } +} diff -r 4b7306f52bb5 -r fe1b83f6ba82 src/mainWindow.h --- 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()); diff -r 4b7306f52bb5 -r fe1b83f6ba82 src/primitives.cc --- 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) diff -r 4b7306f52bb5 -r fe1b83f6ba82 ui/ldforge.ui --- 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 @@ - - - - 0 - 0 - + + + 0 - - QAbstractItemView::ExtendedSelection - + + + + 0 + 0 + 233 + 436 + + + + Document + + + + + + + 0 + 0 + + + + QAbstractItemView::ExtendedSelection + + + + + + + + + 0 + 0 + 233 + 436 + + + + Primitives + + + + + + QAbstractItemView::DragOnly + + + false + + + + 1 + + + + + + @@ -60,7 +112,7 @@ 0 0 1010 - 24 + 25