World Editor UI reshuffling + WDraggableSpinBox improvements

This commit is contained in:
parax0 2015-07-28 23:19:25 -04:00
parent c16c0899bf
commit 7c2c1c9088
4 changed files with 328 additions and 59 deletions

View File

@ -14,7 +14,10 @@
<string>Prime World Editor</string> <string>Prime World Editor</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
</property> </property>
@ -28,7 +31,290 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="CEditorGLWidget" name="MainViewport" native="true"/> <widget class="CEditorGLWidget" name="MainViewport" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<zorder>YLabel</zorder>
<zorder>YSpinBox</zorder>
<zorder>XSpinBox</zorder>
<zorder>XLabel</zorder>
<zorder>ZSpinBox</zorder>
<zorder>ZLabel</zorder>
</widget>
</item>
<item>
<widget class="QFrame" name="BottomFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QFrame" name="SelectionInfoFrame">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>200</width>
<height>16777215</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="midLineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="SelectionInfoLabel">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="midLineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="XLabel">
<property name="text">
<string>X:</string>
</property>
</widget>
</item>
<item>
<widget class="WDraggableSpinBox" name="XSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>70</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-1000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="YLabel">
<property name="text">
<string>Y:</string>
</property>
</widget>
</item>
<item>
<widget class="WDraggableSpinBox" name="YSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-1000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ZLabel">
<property name="text">
<string>Z:</string>
</property>
</widget>
</item>
<item>
<widget class="WDraggableSpinBox" name="ZSpinBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>70</width>
<height>16777215</height>
</size>
</property>
<property name="decimals">
<number>4</number>
</property>
<property name="minimum">
<double>-1000000.000000000000000</double>
</property>
<property name="maximum">
<double>1000000.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="Line" name="BottomFrameDivider">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Speed:</string>
</property>
</widget>
</item>
<item>
<widget class="WDraggableSpinBox" name="CamSpeedSpinBox">
<property name="maximumSize">
<size>
<width>50</width>
<height>16777215</height>
</size>
</property>
<property name="frame">
<bool>true</bool>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="minimum">
<double>0.010000000000000</double>
</property>
<property name="maximum">
<double>10.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="BottomFrameSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -143,52 +429,6 @@
</attribute> </attribute>
<widget class="QWidget" name="MainDockContents"> <widget class="QWidget" name="MainDockContents">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QFrame" name="SelectionInfoFrame">
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="midLineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="SelectionInfoLabel">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="midLineWidth">
<number>0</number>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item> <item>
<widget class="QTabWidget" name="TabWidget"> <widget class="QTabWidget" name="TabWidget">
<property name="tabPosition"> <property name="tabPosition">
@ -609,6 +849,11 @@
<header>WorldEditor/WInstancesTab.h</header> <header>WorldEditor/WInstancesTab.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>WDraggableSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>WDraggableSpinBox.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../Icons.qrc"/> <include location="../Icons.qrc"/>

View File

@ -1,6 +1,7 @@
#include "WDraggableSpinBox.h" #include "WDraggableSpinBox.h"
#include <QMouseEvent> #include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QMouseEvent>
WDraggableSpinBox::WDraggableSpinBox(QWidget *parent) : QDoubleSpinBox(parent) WDraggableSpinBox::WDraggableSpinBox(QWidget *parent) : QDoubleSpinBox(parent)
{ {
@ -8,19 +9,17 @@ WDraggableSpinBox::WDraggableSpinBox(QWidget *parent) : QDoubleSpinBox(parent)
mDefaultValue = value(); mDefaultValue = value();
setMinimum(-1000000.0); setMinimum(-1000000.0);
setMaximum(1000000.0); setMaximum(1000000.0);
setDecimals(4);
} }
WDraggableSpinBox::~WDraggableSpinBox() WDraggableSpinBox::~WDraggableSpinBox()
{ {
} }
void WDraggableSpinBox::mousePressEvent(QMouseEvent *Event) void WDraggableSpinBox::mousePressEvent(QMouseEvent*)
{ {
mBeingDragged = true; mBeingDragged = true;
mBeenDragged = false; mBeenDragged = false;
mInitialY = Event->y(); mLastY = QCursor::pos().y();
mInitialValue = value();
} }
void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event) void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event)
@ -36,6 +35,11 @@ void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event)
else else
stepDown(); stepDown();
} }
else
{
setCursor(Qt::ArrowCursor);
}
} }
else if (Event->button() == Qt::RightButton) else if (Event->button() == Qt::RightButton)
@ -44,12 +48,32 @@ void WDraggableSpinBox::mouseReleaseEvent(QMouseEvent *Event)
} }
} }
void WDraggableSpinBox::mouseMoveEvent(QMouseEvent *Event) void WDraggableSpinBox::mouseMoveEvent(QMouseEvent*)
{ {
if (mBeingDragged) if (mBeingDragged)
{ {
double DragAmount = (singleStep() / 10.0) * (mInitialY - Event->y()); QPoint cursorPos = QCursor::pos();
setValue(mInitialValue + DragAmount);
if (DragAmount != 0) mBeenDragged = true; // Update value
double DragAmount = (singleStep() / 10.0) * (mLastY - cursorPos.y());
setValue(value() + DragAmount);
// Wrap cursor
int screenHeight = QApplication::desktop()->screenGeometry().height();
if (cursorPos.y() == screenHeight - 1)
QCursor::setPos(cursorPos.x(), 1);
if (cursorPos.y() == 0)
QCursor::setPos(cursorPos.x(), screenHeight - 2);
// Set cursor shape
if (DragAmount != 0)
{
mBeenDragged = true;
setCursor(Qt::SizeVerCursor);
}
// Update last Y
mLastY = QCursor::pos().y();
} }
} }

View File

@ -8,9 +8,8 @@ class WDraggableSpinBox : public QDoubleSpinBox
Q_OBJECT Q_OBJECT
bool mBeingDragged; bool mBeingDragged;
bool mBeenDragged; bool mBeenDragged;
double mInitialValue;
double mDefaultValue; double mDefaultValue;
int mInitialY; int mLastY;
public: public:
explicit WDraggableSpinBox(QWidget *parent = 0); explicit WDraggableSpinBox(QWidget *parent = 0);

View File

@ -130,6 +130,7 @@ void WPropertyEditor::CreateEditor()
CFloatProperty *pFloatCast = static_cast<CFloatProperty*>(mpProperty); CFloatProperty *pFloatCast = static_cast<CFloatProperty*>(mpProperty);
WDraggableSpinBox *pDraggableSpinBox = new WDraggableSpinBox(this); WDraggableSpinBox *pDraggableSpinBox = new WDraggableSpinBox(this);
pDraggableSpinBox->setDecimals(4);
pDraggableSpinBox->setValue(pFloatCast->Get()); pDraggableSpinBox->setValue(pFloatCast->Get());
mUI.EditorWidget = pDraggableSpinBox; mUI.EditorWidget = pDraggableSpinBox;