Removed some unused classes from Editor/Controls
Signed-off-by: Chris Galvan <chgalvan@amazon.com>
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_CONTROLS_CONSOLESCBMFC_H
|
||||
#define CRYINCLUDE_EDITOR_CONTROLS_CONSOLESCBMFC_H
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QtWidgets/QLineEdit>
|
||||
#include <QtWidgets/QTextEdit>
|
||||
#include <QtWidgets/QPushButton>
|
||||
|
||||
#include "ConsoleSCB.h"
|
||||
#endif
|
||||
|
||||
class QMenu;
|
||||
class ConsoleWidget;
|
||||
class QFocusEvent;
|
||||
|
||||
namespace Ui {
|
||||
class ConsoleMFC;
|
||||
}
|
||||
|
||||
namespace MFC
|
||||
{
|
||||
|
||||
struct ConsoleLine
|
||||
{
|
||||
QString text;
|
||||
bool newLine;
|
||||
};
|
||||
typedef std::deque<ConsoleLine> Lines;
|
||||
|
||||
class ConsoleLineEdit
|
||||
: public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConsoleLineEdit(QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* ev) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent* ev) override;
|
||||
void keyPressEvent(QKeyEvent* ev) override;
|
||||
bool event(QEvent* ev) override;
|
||||
|
||||
signals:
|
||||
void variableEditorRequested();
|
||||
void setWindowTitle(const QString&);
|
||||
|
||||
private:
|
||||
void DisplayHistory(bool bForward);
|
||||
QStringList m_history;
|
||||
unsigned int m_historyIndex;
|
||||
bool m_bReusedHistory;
|
||||
};
|
||||
|
||||
class ConsoleTextEdit
|
||||
: public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ConsoleTextEdit(QWidget* parent = nullptr);
|
||||
};
|
||||
|
||||
class CConsoleSCB
|
||||
: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CConsoleSCB(QWidget* parent = nullptr);
|
||||
~CConsoleSCB();
|
||||
|
||||
static void RegisterViewClass();
|
||||
void SetInputFocus();
|
||||
void AddToConsole(const QString& text, bool bNewLine);
|
||||
void FlushText();
|
||||
void showPopupAndSetTitle();
|
||||
QSize sizeHint() const override;
|
||||
QSize minimumSizeHint() const override;
|
||||
static CConsoleSCB* GetCreatedInstance();
|
||||
|
||||
static void AddToPendingLines(const QString& text, bool bNewLine); // call this function instead of AddToConsole() until an instance of CConsoleSCB exists to prevent messages from getting lost
|
||||
|
||||
public Q_SLOTS:
|
||||
void OnStyleSettingsChanged();
|
||||
|
||||
private Q_SLOTS:
|
||||
void showVariableEditor();
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::ConsoleMFC> ui;
|
||||
int m_richEditTextLength;
|
||||
|
||||
Lines m_lines;
|
||||
static Lines s_pendingLines;
|
||||
|
||||
QList<QColor> m_colorTable;
|
||||
SEditorSettings::ConsoleColorTheme m_backgroundTheme;
|
||||
};
|
||||
|
||||
} // namespace MFC
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_CONTROLS_CONSOLESCB_H
|
||||
|
||||
@@ -1,132 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ConsoleMFC</class>
|
||||
<widget class="QWidget" name="Console">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>120</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Ignored">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Console</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="container2" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoFillBackground">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="button">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="MFC::ConsoleLineEdit" name="lineEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MFC::ConsoleLineEdit</class>
|
||||
<extends>QLineEdit</extends>
|
||||
<header>ConsoleSCBMFC.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="ConsoleSCB.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "HotTrackingTreeCtrl.h"
|
||||
|
||||
// Qt
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
CHotTrackingTreeCtrl::CHotTrackingTreeCtrl(QWidget* parent)
|
||||
: QTreeWidget(parent)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
m_hHoverItem = nullptr;
|
||||
}
|
||||
|
||||
void CHotTrackingTreeCtrl::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
QTreeWidgetItem* hItem = itemAt(event->pos());
|
||||
|
||||
if (m_hHoverItem != nullptr)
|
||||
{
|
||||
QFont font = m_hHoverItem->font(0);
|
||||
font.setBold(false);
|
||||
m_hHoverItem->setFont(0, font);
|
||||
m_hHoverItem = nullptr;
|
||||
}
|
||||
|
||||
if (hItem != nullptr)
|
||||
{
|
||||
QFont font = hItem->font(0);
|
||||
font.setBold(true);
|
||||
hItem->setFont(0, font);
|
||||
m_hHoverItem = hItem;
|
||||
}
|
||||
|
||||
QTreeWidget::mouseMoveEvent(event);
|
||||
}
|
||||
|
||||
#include <Controls/moc_HotTrackingTreeCtrl.cpp>
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_CONTROLS_HOTTRACKINGTREECTRL_H
|
||||
#define CRYINCLUDE_EDITOR_CONTROLS_HOTTRACKINGTREECTRL_H
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QTreeWidget>
|
||||
#endif
|
||||
|
||||
class CHotTrackingTreeCtrl
|
||||
: public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CHotTrackingTreeCtrl(QWidget* parent = 0);
|
||||
virtual ~CHotTrackingTreeCtrl(){};
|
||||
|
||||
protected:
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
|
||||
private:
|
||||
QTreeWidgetItem* m_hHoverItem;
|
||||
};
|
||||
#endif // CRYINCLUDE_EDITOR_CONTROLS_HOTTRACKINGTREECTRL_H
|
||||
@@ -1,567 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "ImageListCtrl.h"
|
||||
|
||||
// Qt
|
||||
#include <QPainter>
|
||||
#include <QScrollBar>
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CImageListCtrl::CImageListCtrl(QWidget* parent)
|
||||
: QAbstractItemView(parent)
|
||||
, m_itemSize(60, 60)
|
||||
, m_borderSize(4, 4)
|
||||
, m_style(DefaultStyle)
|
||||
{
|
||||
setItemDelegate(new QImageListDelegate(this));
|
||||
setAutoFillBackground(false);
|
||||
|
||||
QPalette p = palette();
|
||||
p.setColor(QPalette::Highlight, QColor(255, 55, 50));
|
||||
setPalette(p);
|
||||
|
||||
horizontalScrollBar()->setRange(0, 0);
|
||||
verticalScrollBar()->setRange(0, 0);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CImageListCtrl::~CImageListCtrl()
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
CImageListCtrl::ListStyle CImageListCtrl::Style() const
|
||||
{
|
||||
return m_style;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CImageListCtrl::SetStyle(ListStyle style)
|
||||
{
|
||||
m_style = style;
|
||||
scheduleDelayedItemsLayout();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
const QSize& CImageListCtrl::ItemSize() const
|
||||
{
|
||||
return m_itemSize;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CImageListCtrl::SetItemSize(QSize size)
|
||||
{
|
||||
Q_ASSERT(size.isValid());
|
||||
m_itemSize = size;
|
||||
scheduleDelayedItemsLayout();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
const QSize& CImageListCtrl::BorderSize() const
|
||||
{
|
||||
return m_borderSize;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CImageListCtrl::SetBorderSize(QSize size)
|
||||
{
|
||||
Q_ASSERT(size.isValid());
|
||||
m_borderSize = size;
|
||||
scheduleDelayedItemsLayout();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QModelIndexList CImageListCtrl::ItemsInRect(const QRect& rect) const
|
||||
{
|
||||
QModelIndexList list;
|
||||
|
||||
if (!model())
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
QHash<int, QRect>::const_iterator i;
|
||||
QHash<int, QRect>::const_iterator c = m_geometry.cend();
|
||||
for (i = m_geometry.cbegin(); i != c; ++i)
|
||||
{
|
||||
if (i.value().intersects(rect))
|
||||
{
|
||||
list << model()->index(i.key(), 0, rootIndex());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CImageListCtrl::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QAbstractItemView::paintEvent(event);
|
||||
|
||||
if (!model())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int rowCount = model()->rowCount();
|
||||
|
||||
if (m_geometry.isEmpty() && rowCount)
|
||||
{
|
||||
updateGeometries();
|
||||
}
|
||||
|
||||
QPainter painter(viewport());
|
||||
painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
|
||||
painter.setBackground(palette().window());
|
||||
painter.setFont(font());
|
||||
|
||||
QStyleOptionViewItem option;
|
||||
option.palette = palette();
|
||||
option.font = font();
|
||||
option.fontMetrics = fontMetrics();
|
||||
option.decorationAlignment = Qt::AlignCenter;
|
||||
|
||||
const QRect visibleRect(QPoint(horizontalOffset(), verticalOffset()), viewport()->contentsRect().size());
|
||||
|
||||
painter.translate(-horizontalOffset(), -verticalOffset());
|
||||
|
||||
for (int r = 0; r < rowCount; ++r)
|
||||
{
|
||||
const QModelIndex& index = model()->index(r, 0, rootIndex());
|
||||
|
||||
option.rect = m_geometry.value(r);
|
||||
if (!option.rect.intersects(visibleRect))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
option.state = QStyle::State_None;
|
||||
|
||||
if (selectionModel()->isSelected(index))
|
||||
{
|
||||
option.state |= QStyle::State_Selected;
|
||||
}
|
||||
|
||||
if (currentIndex() == index)
|
||||
{
|
||||
option.state |= QStyle::State_HasFocus;
|
||||
}
|
||||
|
||||
QAbstractItemDelegate* idt = itemDelegate(index);
|
||||
idt->paint(&painter, option, index);
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CImageListCtrl::rowsInserted(const QModelIndex& parent, int start, int end)
|
||||
{
|
||||
QAbstractItemView::rowsInserted(parent, start, end);
|
||||
|
||||
if (isVisible())
|
||||
{
|
||||
scheduleDelayedItemsLayout();
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CImageListCtrl::updateGeometries()
|
||||
{
|
||||
ClearItemGeometries();
|
||||
|
||||
if (!model())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int rowCount = model()->rowCount();
|
||||
|
||||
const int nPageHorz = viewport()->width();
|
||||
const int nPageVert = viewport()->height();
|
||||
|
||||
if (nPageHorz == 0 || nPageVert == 0 || rowCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int x = m_borderSize.width();
|
||||
int y = m_borderSize.height();
|
||||
|
||||
const int nItemWidth = m_itemSize.width() + m_borderSize.width();
|
||||
|
||||
if (m_style == HorizontalStyle)
|
||||
{
|
||||
for (int row = 0; row < rowCount; ++row)
|
||||
{
|
||||
m_geometry.insert(row, QRect(QPoint(x, y), m_itemSize));
|
||||
x += nItemWidth;
|
||||
}
|
||||
|
||||
horizontalScrollBar()->setPageStep(viewport()->width());
|
||||
horizontalScrollBar()->setRange(0, x - viewport()->width());
|
||||
}
|
||||
else
|
||||
{
|
||||
const int nTextHeight = fontMetrics().height();
|
||||
const int nItemHeight = m_itemSize.height() + m_borderSize.height() + nTextHeight;
|
||||
|
||||
int nNumOfHorzItems = nPageHorz / nItemWidth;
|
||||
if (nNumOfHorzItems <= 0)
|
||||
{
|
||||
nNumOfHorzItems = 1;
|
||||
}
|
||||
|
||||
for (int row = 0; row < rowCount; ++row)
|
||||
{
|
||||
m_geometry.insert(row, QRect(QPoint(x, y), m_itemSize));
|
||||
|
||||
if ((row + 1) % nNumOfHorzItems == 0)
|
||||
{
|
||||
y += nItemHeight;
|
||||
x = m_borderSize.width();
|
||||
}
|
||||
else
|
||||
{
|
||||
x += nItemWidth;
|
||||
}
|
||||
}
|
||||
|
||||
verticalScrollBar()->setPageStep(viewport()->height());
|
||||
verticalScrollBar()->setRange(0, (y + nItemHeight) - viewport()->height());
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QModelIndex CImageListCtrl::indexAt(const QPoint& point) const
|
||||
{
|
||||
if (!model())
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
const QPoint p = point +
|
||||
QPoint(horizontalOffset(), verticalOffset());
|
||||
|
||||
QHash<int, QRect>::const_iterator i;
|
||||
QHash<int, QRect>::const_iterator c = m_geometry.cend();
|
||||
for (i = m_geometry.cbegin(); i != c; ++i)
|
||||
{
|
||||
if (i.value().contains(p))
|
||||
{
|
||||
return model()->index(i.key(), 0, rootIndex());
|
||||
}
|
||||
}
|
||||
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CImageListCtrl::scrollTo(const QModelIndex& index, ScrollHint hint)
|
||||
{
|
||||
if (!index.isValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QRect rect = m_geometry.value(index.row());
|
||||
|
||||
switch (hint)
|
||||
{
|
||||
case EnsureVisible:
|
||||
if (horizontalOffset() > rect.right())
|
||||
{
|
||||
horizontalScrollBar()->setValue(rect.left());
|
||||
}
|
||||
else if ((horizontalOffset() + viewport()->width()) < rect.left())
|
||||
{
|
||||
horizontalScrollBar()->setValue(rect.right() - viewport()->width());
|
||||
}
|
||||
|
||||
if (verticalOffset() > rect.bottom())
|
||||
{
|
||||
verticalScrollBar()->setValue(rect.top());
|
||||
}
|
||||
else if ((verticalOffset() + viewport()->height()) < rect.top())
|
||||
{
|
||||
verticalScrollBar()->setValue(rect.bottom() - viewport()->height());
|
||||
}
|
||||
break;
|
||||
|
||||
case PositionAtTop:
|
||||
horizontalScrollBar()->setValue(rect.left());
|
||||
verticalScrollBar()->setValue(rect.top());
|
||||
break;
|
||||
|
||||
case PositionAtBottom:
|
||||
horizontalScrollBar()->setValue(rect.right() - viewport()->width());
|
||||
verticalScrollBar()->setValue(rect.bottom() - viewport()->height());
|
||||
break;
|
||||
|
||||
case PositionAtCenter:
|
||||
horizontalScrollBar()->setValue(rect.center().x() - (viewport()->width() / 2));
|
||||
verticalScrollBar()->setValue(rect.center().y() - (viewport()->height() / 2));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QRect CImageListCtrl::visualRect(const QModelIndex& index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
{
|
||||
return QRect();
|
||||
}
|
||||
|
||||
|
||||
if (!m_geometry.contains(index.row()))
|
||||
{
|
||||
return QRect();
|
||||
}
|
||||
|
||||
return m_geometry.value(index.row())
|
||||
.translated(-horizontalOffset(), -verticalOffset());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QRect CImageListCtrl::ItemGeometry(const QModelIndex& index) const
|
||||
{
|
||||
Q_ASSERT(index.model() == model());
|
||||
Q_ASSERT(m_geometry.contains(index.row()));
|
||||
|
||||
return m_geometry.value(index.row());
|
||||
}
|
||||
|
||||
void CImageListCtrl::SetItemGeometry(const QModelIndex& index, const QRect& rect)
|
||||
{
|
||||
Q_ASSERT(index.model() == model());
|
||||
m_geometry.insert(index.row(), rect);
|
||||
update(rect);
|
||||
}
|
||||
|
||||
void CImageListCtrl::ClearItemGeometries()
|
||||
{
|
||||
m_geometry.clear();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int CImageListCtrl::horizontalOffset() const
|
||||
{
|
||||
return horizontalScrollBar()->value();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
int CImageListCtrl::verticalOffset() const
|
||||
{
|
||||
return verticalScrollBar()->value();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
bool CImageListCtrl::isIndexHidden([[maybe_unused]] const QModelIndex& index) const
|
||||
{
|
||||
return false; /* not supported */
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QModelIndex CImageListCtrl::moveCursor(CursorAction cursorAction, [[maybe_unused]] Qt::KeyboardModifiers modifiers)
|
||||
{
|
||||
if (!model())
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
const int rowCount = model()->rowCount();
|
||||
|
||||
if (0 == rowCount)
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
switch (cursorAction)
|
||||
{
|
||||
case MoveHome:
|
||||
return model()->index(0, 0, rootIndex());
|
||||
|
||||
case MoveEnd:
|
||||
return model()->index(rowCount - 1, 0, rootIndex());
|
||||
|
||||
case MovePrevious:
|
||||
{
|
||||
QModelIndex current = currentIndex();
|
||||
if (current.isValid())
|
||||
{
|
||||
return model()->index((current.row() - 1) % rowCount, 0, rootIndex());
|
||||
}
|
||||
} break;
|
||||
|
||||
case MoveNext:
|
||||
{
|
||||
QModelIndex current = currentIndex();
|
||||
if (current.isValid())
|
||||
{
|
||||
return model()->index((current.row() + 1) % rowCount, 0, rootIndex());
|
||||
}
|
||||
} break;
|
||||
|
||||
case MoveUp:
|
||||
case MoveDown:
|
||||
case MoveLeft:
|
||||
case MoveRight:
|
||||
case MovePageUp:
|
||||
case MovePageDown:
|
||||
/* TODO */
|
||||
break;
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CImageListCtrl::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags)
|
||||
{
|
||||
if (!model())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const QRect lrect =
|
||||
rect.translated(horizontalOffset(), verticalOffset());
|
||||
|
||||
QHash<int, QRect>::const_iterator i;
|
||||
QHash<int, QRect>::const_iterator c = m_geometry.cend();
|
||||
for (i = m_geometry.cbegin(); i != c; ++i)
|
||||
{
|
||||
if (i.value().intersects(lrect))
|
||||
{
|
||||
selectionModel()->select(model()->index(i.key(), 0, rootIndex()), flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QRegion CImageListCtrl::visualRegionForSelection(const QItemSelection& selection) const
|
||||
{
|
||||
QRegion region;
|
||||
|
||||
foreach(const QModelIndex &index, selection.indexes())
|
||||
{
|
||||
region += visualRect(index);
|
||||
}
|
||||
|
||||
return region;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QImageListDelegate::QImageListDelegate(QObject* parent)
|
||||
: QAbstractItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void QImageListDelegate::paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->setFont(option.font);
|
||||
|
||||
if (option.rect.isValid())
|
||||
{
|
||||
painter->setClipRect(option.rect);
|
||||
}
|
||||
|
||||
QRect innerRect = option.rect.adjusted(1, 1, -1, -1);
|
||||
|
||||
QRect textRect(innerRect.left(), innerRect.bottom() - option.fontMetrics.height(),
|
||||
innerRect.width(), option.fontMetrics.height() + 1);
|
||||
|
||||
/* fill item background */
|
||||
|
||||
painter->fillRect(option.rect, option.palette.color(QPalette::Base));
|
||||
|
||||
/* draw image */
|
||||
|
||||
if (index.data(Qt::DecorationRole).isValid())
|
||||
{
|
||||
const QPixmap& p = index.data(Qt::DecorationRole).value<QPixmap>();
|
||||
if (p.isNull() || p.size() == QSize(1, 1))
|
||||
{
|
||||
emit InvalidPixmapGenerated(index);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->drawPixmap(innerRect, p);
|
||||
}
|
||||
}
|
||||
|
||||
/* draw text */
|
||||
|
||||
const QColor trColor = option.palette.color(QPalette::Shadow);
|
||||
painter->fillRect(textRect, (option.state & QStyle::State_Selected) ?
|
||||
trColor.lighter() : trColor);
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
{
|
||||
painter->setPen(QPen(option.palette.color(QPalette::HighlightedText)));
|
||||
|
||||
QFont f = painter->font();
|
||||
f.setBold(true);
|
||||
painter->setFont(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setPen(QPen(option.palette.color(QPalette::Text)));
|
||||
}
|
||||
|
||||
painter->drawText(textRect, index.data(Qt::DisplayRole).toString(),
|
||||
QTextOption(option.decorationAlignment));
|
||||
|
||||
painter->setPen(QPen(option.palette.color(QPalette::Shadow)));
|
||||
painter->drawRect(textRect);
|
||||
|
||||
/* draw border */
|
||||
|
||||
if (option.state & QStyle::State_Selected)
|
||||
{
|
||||
QPen pen(option.palette.color(QPalette::Highlight));
|
||||
pen.setWidth(2);
|
||||
painter->setPen(pen);
|
||||
painter->drawRect(innerRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter->setPen(QPen(option.palette.color(QPalette::Shadow)));
|
||||
painter->drawRect(option.rect);
|
||||
}
|
||||
|
||||
if (option.state & QStyle::State_HasFocus)
|
||||
{
|
||||
QPen pen(Qt::DotLine);
|
||||
pen.setColor(option.palette.color(QPalette::AlternateBase));
|
||||
painter->setPen(pen);
|
||||
painter->drawRect(option.rect);
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QSize QImageListDelegate::sizeHint(const QStyleOptionViewItem& option,
|
||||
[[maybe_unused]] const QModelIndex& index) const
|
||||
{
|
||||
return option.rect.size();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
QVector<int> QImageListDelegate::paintingRoles() const
|
||||
{
|
||||
return QVector<int>() << Qt::DecorationRole << Qt::DisplayRole;
|
||||
}
|
||||
|
||||
#include <Controls/moc_ImageListCtrl.cpp>
|
||||
@@ -1,97 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_CONTROLS_IMAGELISTCTRL_H
|
||||
#define CRYINCLUDE_EDITOR_CONTROLS_IMAGELISTCTRL_H
|
||||
#pragma once
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QAbstractItemView>
|
||||
|
||||
#include <QHash>
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Custom control to display list of images.
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
class CImageListCtrl
|
||||
: public QAbstractItemView
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ListStyle
|
||||
{
|
||||
DefaultStyle,
|
||||
HorizontalStyle
|
||||
};
|
||||
|
||||
public:
|
||||
CImageListCtrl(QWidget* parent = nullptr);
|
||||
~CImageListCtrl();
|
||||
|
||||
ListStyle Style() const;
|
||||
void SetStyle(ListStyle style);
|
||||
|
||||
const QSize& ItemSize() const;
|
||||
void SetItemSize(QSize size);
|
||||
|
||||
const QSize& BorderSize() const;
|
||||
void SetBorderSize(QSize size);
|
||||
|
||||
// Get all items inside specified rectangle.
|
||||
QModelIndexList ItemsInRect(const QRect& rect) const;
|
||||
|
||||
QModelIndex indexAt(const QPoint& point) const override;
|
||||
void scrollTo(const QModelIndex& index, ScrollHint hint = EnsureVisible) override;
|
||||
QRect visualRect(const QModelIndex& index) const override;
|
||||
|
||||
protected:
|
||||
QRect ItemGeometry(const QModelIndex& index) const;
|
||||
void SetItemGeometry(const QModelIndex& index, const QRect& rect);
|
||||
void ClearItemGeometries();
|
||||
|
||||
int horizontalOffset() const override;
|
||||
int verticalOffset() const override;
|
||||
bool isIndexHidden(const QModelIndex& index) const override;
|
||||
QModelIndex moveCursor(CursorAction cursorAction, Qt::KeyboardModifiers modifiers) override;
|
||||
void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags flags) override;
|
||||
QRegion visualRegionForSelection(const QItemSelection& selection) const override;
|
||||
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
void rowsInserted(const QModelIndex& parent, int start, int end) override;
|
||||
|
||||
void updateGeometries() override;
|
||||
|
||||
private:
|
||||
QHash<int, QRect> m_geometry;
|
||||
QSize m_itemSize;
|
||||
QSize m_borderSize;
|
||||
ListStyle m_style;
|
||||
};
|
||||
|
||||
class QImageListDelegate
|
||||
: public QAbstractItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
signals:
|
||||
void InvalidPixmapGenerated(const QModelIndex& index) const;
|
||||
public:
|
||||
QImageListDelegate(QObject* parent = nullptr);
|
||||
|
||||
void paint(QPainter* painter,
|
||||
const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const override;
|
||||
|
||||
QSize sizeHint(const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index) const override;
|
||||
|
||||
QVector<int> paintingRoles() const override;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_CONTROLS_IMAGELISTCTRL_H
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "MultiMonHelper.h"
|
||||
|
||||
// Qt
|
||||
#include <QScreen>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void ClipOrCenterRectToMonitor(QRect *prc, const UINT flags)
|
||||
{
|
||||
const QScreen* currentScreen = nullptr;
|
||||
QRect rc;
|
||||
|
||||
Q_ASSERT(prc);
|
||||
|
||||
const auto screens = qApp->screens();
|
||||
for (auto screen : screens)
|
||||
{
|
||||
if (screen->geometry().contains(prc->center()))
|
||||
{
|
||||
currentScreen = screen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentScreen)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const int w = prc->width();
|
||||
const int h = prc->height();
|
||||
|
||||
if (flags & MONITOR_WORKAREA)
|
||||
{
|
||||
rc = currentScreen->availableGeometry();
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = currentScreen->geometry();
|
||||
}
|
||||
|
||||
// center or clip the passed rect to the monitor rect
|
||||
if (flags & MONITOR_CENTER)
|
||||
{
|
||||
prc->setLeft(rc.left() + (rc.right() - rc.left() - w) / 2);
|
||||
prc->setTop(rc.top() + (rc.bottom() - rc.top() - h) / 2);
|
||||
prc->setRight(prc->left() + w);
|
||||
prc->setBottom(prc->top() + h);
|
||||
}
|
||||
else
|
||||
{
|
||||
prc->setLeft(qMax(rc.left(), qMin(rc.right() - w, prc->left())));
|
||||
prc->setTop(qMax(rc.top(), qMin(rc.bottom() - h, prc->top())));
|
||||
prc->setRight(prc->left() + w);
|
||||
prc->setBottom(prc->top() + h);
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_CONTROLS_MULTIMONHELPER_H
|
||||
#define CRYINCLUDE_EDITOR_CONTROLS_MULTIMONHELPER_H
|
||||
#pragma once
|
||||
|
||||
// Taken from: http://msdn.microsoft.com/en-us/library/dd162826(v=vs.85).aspx
|
||||
#define MONITOR_CENTER 0x0001 // center rect to monitor
|
||||
#define MONITOR_CLIP 0x0000 // clip rect to monitor
|
||||
#define MONITOR_WORKAREA 0x0002 // use monitor work area
|
||||
#define MONITOR_AREA 0x0000 // use monitor entire area
|
||||
|
||||
//
|
||||
// ClipOrCenterRectToMonitor
|
||||
//
|
||||
// The most common problem apps have when running on a
|
||||
// multimonitor system is that they "clip" or "pin" windows
|
||||
// based on the SM_CXSCREEN and SM_CYSCREEN system metrics.
|
||||
// Because of app compatibility reasons these system metrics
|
||||
// return the size of the primary monitor.
|
||||
//
|
||||
// This shows how you use the multi-monitor functions
|
||||
// to do the same thing.
|
||||
//
|
||||
// params:
|
||||
// prc : pointer to QRect to modify
|
||||
// flags : some combination of the MONITOR_* flags above
|
||||
//
|
||||
// example:
|
||||
//
|
||||
// ClipOrCenterRectToMonitor(&aRect, MONITOR_CLIP | MONITOR_WORKAREA);
|
||||
//
|
||||
// Takes parameter pointer to RECT "aRect" and flags MONITOR_CLIP | MONITOR_WORKAREA
|
||||
// This will modify aRect without resizing it so that it remains within the on-screen boundaries.
|
||||
void ClipOrCenterRectToMonitor(QRect *prc, const UINT flags);
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_CONTROLS_MULTIMONHELPER_H
|
||||
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "NumberCtrl.h"
|
||||
|
||||
|
||||
QNumberCtrl::QNumberCtrl(QWidget* parent)
|
||||
: QDoubleSpinBox(parent)
|
||||
, m_bMouseDown(false)
|
||||
, m_bDragged(false)
|
||||
, m_bUndoEnabled(false)
|
||||
, m_prevValue(0)
|
||||
{
|
||||
connect(this, &QAbstractSpinBox::editingFinished, this, &QNumberCtrl::onEditingFinished);
|
||||
}
|
||||
|
||||
void QNumberCtrl::changeEvent(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::EnabledChange)
|
||||
{
|
||||
setButtonSymbols(isEnabled() ? UpDownArrows : NoButtons);
|
||||
}
|
||||
|
||||
QDoubleSpinBox::changeEvent(event);
|
||||
}
|
||||
|
||||
|
||||
void QNumberCtrl::SetRange(double newMin, double newMax)
|
||||
{
|
||||
// Avoid setting this value if its close to the current value, because otherwise qt will pump events into the queue to redraw/etc.
|
||||
if ( (!AZ::IsClose(this->minimum(), newMin, DBL_EPSILON)) || (!AZ::IsClose(this->maximum(), newMax, DBL_EPSILON)) )
|
||||
{
|
||||
setRange(newMin, newMax);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QNumberCtrl::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
emit mousePressed();
|
||||
|
||||
m_bMouseDown = true;
|
||||
m_bDragged = false;
|
||||
m_mousePos = event->pos();
|
||||
|
||||
if (m_bUndoEnabled && !CUndo::IsRecording())
|
||||
{
|
||||
GetIEditor()->BeginUndo();
|
||||
}
|
||||
|
||||
emit dragStarted();
|
||||
|
||||
grabMouse();
|
||||
}
|
||||
|
||||
QDoubleSpinBox::mousePressEvent(event);
|
||||
}
|
||||
|
||||
void QNumberCtrl::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
QDoubleSpinBox::mouseReleaseEvent(event);
|
||||
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
m_bMouseDown = m_bDragged = false;
|
||||
|
||||
emit valueUpdated();
|
||||
emit valueChanged();
|
||||
|
||||
if (m_bUndoEnabled && CUndo::IsRecording())
|
||||
{
|
||||
GetIEditor()->AcceptUndo(m_undoText);
|
||||
}
|
||||
|
||||
emit dragFinished();
|
||||
|
||||
releaseMouse();
|
||||
|
||||
m_prevValue = value();
|
||||
|
||||
emit mouseReleased();
|
||||
}
|
||||
}
|
||||
|
||||
void QNumberCtrl::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
QDoubleSpinBox::mousePressEvent(event);
|
||||
|
||||
if (m_bMouseDown)
|
||||
{
|
||||
m_bDragged = true;
|
||||
|
||||
int dy = event->pos().y() - m_mousePos.y();
|
||||
setValue(value() - singleStep() * dy);
|
||||
|
||||
emit valueUpdated();
|
||||
|
||||
m_mousePos = event->pos();
|
||||
}
|
||||
}
|
||||
|
||||
void QNumberCtrl::EnableUndo(const QString& undoText)
|
||||
{
|
||||
m_undoText = undoText;
|
||||
m_bUndoEnabled = true;
|
||||
}
|
||||
|
||||
void QNumberCtrl::focusInEvent(QFocusEvent* event)
|
||||
{
|
||||
m_prevValue = value();
|
||||
QDoubleSpinBox::focusInEvent(event);
|
||||
}
|
||||
|
||||
void QNumberCtrl::onEditingFinished()
|
||||
{
|
||||
bool undo = m_bUndoEnabled && !CUndo::IsRecording() && m_prevValue != value();
|
||||
if (undo)
|
||||
{
|
||||
GetIEditor()->BeginUndo();
|
||||
}
|
||||
|
||||
emit valueUpdated();
|
||||
emit valueChanged();
|
||||
|
||||
if (undo)
|
||||
{
|
||||
GetIEditor()->AcceptUndo(m_undoText);
|
||||
}
|
||||
|
||||
m_prevValue = value();
|
||||
}
|
||||
|
||||
#include <Controls/moc_NumberCtrl.cpp>
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_CONTROLS_NUMBERCTRL_H
|
||||
#define CRYINCLUDE_EDITOR_CONTROLS_NUMBERCTRL_H
|
||||
#pragma once
|
||||
|
||||
// NumberCtrl.h : header file
|
||||
//
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QDoubleSpinBox>
|
||||
#endif
|
||||
|
||||
class QNumberCtrl
|
||||
: public QDoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QNumberCtrl(QWidget* parent = nullptr);
|
||||
|
||||
bool IsDragging() const { return m_bDragged; }
|
||||
|
||||
//! If called will enable undo with given text when control is modified.
|
||||
void EnableUndo(const QString& undoText);
|
||||
void SetRange(double newMin, double maxRange);
|
||||
|
||||
Q_SIGNALS:
|
||||
void dragStarted();
|
||||
void dragFinished();
|
||||
|
||||
void valueUpdated();
|
||||
void valueChanged();
|
||||
|
||||
void mouseReleased();
|
||||
void mousePressed();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent* event) override;
|
||||
void focusInEvent(QFocusEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
void mouseMoveEvent(QMouseEvent* event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||
|
||||
private:
|
||||
void onEditingFinished();
|
||||
void onValueChanged(double d);
|
||||
|
||||
bool m_bMouseDown;
|
||||
bool m_bDragged;
|
||||
QPoint m_mousePos;
|
||||
bool m_bUndoEnabled;
|
||||
double m_prevValue;
|
||||
QString m_undoText;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_CONTROLS_NUMBERCTRL_H
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "TextEditorCtrl.h"
|
||||
|
||||
|
||||
// CTextEditorCtrl
|
||||
CTextEditorCtrl::CTextEditorCtrl(QWidget* pParent)
|
||||
: QTextEdit(pParent)
|
||||
{
|
||||
m_bModified = true;
|
||||
|
||||
QFont font;
|
||||
font.setFamily("Courier New");
|
||||
font.setFixedPitch(true);
|
||||
font.setPointSize(10);
|
||||
setFont(font);
|
||||
|
||||
setLineWrapMode(NoWrap);
|
||||
|
||||
connect(this, &QTextEdit::textChanged, this, &CTextEditorCtrl::OnChange);
|
||||
}
|
||||
|
||||
CTextEditorCtrl::~CTextEditorCtrl()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// CTextEditorCtrl message handlers
|
||||
|
||||
void CTextEditorCtrl::LoadFile(const QString& sFileName)
|
||||
{
|
||||
if (m_filename == sFileName)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_filename = sFileName;
|
||||
|
||||
clear();
|
||||
|
||||
CCryFile file(sFileName.toUtf8().data(), "rb");
|
||||
if (file.Open(sFileName.toUtf8().data(), "rb"))
|
||||
{
|
||||
size_t length = file.GetLength();
|
||||
|
||||
QByteArray text;
|
||||
text.resize(static_cast<int>(length));
|
||||
file.ReadRaw(text.data(), length);
|
||||
|
||||
setPlainText(text);
|
||||
}
|
||||
|
||||
m_bModified = false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CTextEditorCtrl::SaveFile(const QString& sFileName)
|
||||
{
|
||||
if (sFileName.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CFileUtil::OverwriteFile(sFileName.toUtf8().data()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(sFileName);
|
||||
file.open(QFile::WriteOnly);
|
||||
|
||||
file.write(toPlainText().toUtf8());
|
||||
|
||||
m_bModified = false;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void CTextEditorCtrl::OnChange()
|
||||
{
|
||||
|
||||
m_bModified = true;
|
||||
}
|
||||
|
||||
#include <Controls/moc_TextEditorCtrl.cpp>
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_CONTROLS_TEXTEDITORCTRL_H
|
||||
#define CRYINCLUDE_EDITOR_CONTROLS_TEXTEDITORCTRL_H
|
||||
#pragma once
|
||||
|
||||
// CTextEditorCtrl
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QTextEdit>
|
||||
#endif
|
||||
|
||||
class CTextEditorCtrl
|
||||
: public QTextEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CTextEditorCtrl(QWidget* pParent = nullptr);
|
||||
virtual ~CTextEditorCtrl();
|
||||
|
||||
void LoadFile(const QString& sFileName);
|
||||
void SaveFile(const QString& sFileName);
|
||||
QString GetFilename() const { return m_filename; }
|
||||
|
||||
bool IsModified() const { return m_bModified; }
|
||||
|
||||
//! Must be called after OnChange message.
|
||||
void OnChange();
|
||||
|
||||
protected:
|
||||
QString m_filename;
|
||||
bool m_bModified;
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_CONTROLS_TEXTEDITORCTRL_H
|
||||
@@ -1,322 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project.
|
||||
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_EDITOR_CONTROLS_TREECTRLUTILS_H
|
||||
#define CRYINCLUDE_EDITOR_CONTROLS_TREECTRLUTILS_H
|
||||
#pragma once
|
||||
|
||||
#include <iterator>
|
||||
|
||||
namespace TreeCtrlUtils
|
||||
{
|
||||
template <typename P>
|
||||
class TreeItemIterator
|
||||
: public P
|
||||
{
|
||||
public:
|
||||
typedef P Traits;
|
||||
|
||||
//iterator traits, required by STL
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef HTREEITEM value_type;
|
||||
typedef HTREEITEM* pointer;
|
||||
typedef HTREEITEM& reference;
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
|
||||
TreeItemIterator()
|
||||
: pCtrl(0)
|
||||
, hItem(0) {}
|
||||
explicit TreeItemIterator(const P& traits)
|
||||
: P(traits)
|
||||
, pCtrl(0)
|
||||
, hItem(0) {}
|
||||
TreeItemIterator(const TreeItemIterator& other)
|
||||
: P(other)
|
||||
, pCtrl(other.pCtrl)
|
||||
, hItem(other.hItem) {}
|
||||
TreeItemIterator(CTreeCtrl* pCtrl, HTREEITEM hItem)
|
||||
: pCtrl(pCtrl)
|
||||
, hItem(hItem) {}
|
||||
TreeItemIterator(CTreeCtrl* pCtrl, HTREEITEM hItem, const P& traits)
|
||||
: P(traits)
|
||||
, pCtrl(pCtrl)
|
||||
, hItem(hItem) {}
|
||||
|
||||
HTREEITEM operator*() {return hItem; }
|
||||
bool operator==(const TreeItemIterator& other) const {return pCtrl == other.pCtrl && hItem == other.hItem; }
|
||||
bool operator!=(const TreeItemIterator& other) const {return pCtrl != other.pCtrl || hItem != other.hItem; }
|
||||
|
||||
TreeItemIterator& operator++()
|
||||
{
|
||||
HTREEITEM hNextItem = 0;
|
||||
if (RecurseToChildren(hItem))
|
||||
{
|
||||
hNextItem = (pCtrl ? pCtrl->GetChildItem(hItem) : 0);
|
||||
}
|
||||
while (pCtrl && hItem && !hNextItem)
|
||||
{
|
||||
hNextItem = pCtrl->GetNextSiblingItem(hItem);
|
||||
if (!hNextItem)
|
||||
{
|
||||
hItem = pCtrl->GetParentItem(hItem);
|
||||
}
|
||||
}
|
||||
hItem = hNextItem;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
TreeItemIterator operator++(int) {TreeItemIterator old = *this; ++(*this); return old; }
|
||||
|
||||
CTreeCtrl* pCtrl;
|
||||
HTREEITEM hItem;
|
||||
};
|
||||
|
||||
class NonRecursiveTreeItemIteratorTraits
|
||||
{
|
||||
public:
|
||||
bool RecurseToChildren(HTREEITEM hItem) {return false; }
|
||||
};
|
||||
typedef TreeItemIterator<NonRecursiveTreeItemIteratorTraits> NonRecursiveTreeItemIterator;
|
||||
|
||||
class RecursiveTreeItemIteratorTraits
|
||||
{
|
||||
public:
|
||||
bool RecurseToChildren(HTREEITEM hItem) {return true; }
|
||||
};
|
||||
typedef TreeItemIterator<RecursiveTreeItemIteratorTraits> RecursiveTreeItemIterator;
|
||||
|
||||
inline RecursiveTreeItemIterator BeginTreeItemsRecursive(CTreeCtrl* pCtrl, HTREEITEM hItem = 0)
|
||||
{
|
||||
if (hItem == 0)
|
||||
{
|
||||
hItem = (pCtrl ? pCtrl->GetRootItem() : 0);
|
||||
}
|
||||
return RecursiveTreeItemIterator(pCtrl, hItem);
|
||||
}
|
||||
|
||||
inline RecursiveTreeItemIterator EndTreeItemsRecursive(CTreeCtrl* pCtrl, HTREEITEM hItem = 0)
|
||||
{
|
||||
HTREEITEM hEndItem = 0;
|
||||
HTREEITEM hParent = hItem;
|
||||
do
|
||||
{
|
||||
if (hParent)
|
||||
{
|
||||
hEndItem = pCtrl->GetNextSiblingItem(hParent);
|
||||
}
|
||||
hParent = (pCtrl && hParent ? pCtrl->GetParentItem(hParent) : 0);
|
||||
}
|
||||
while (hParent && !hEndItem);
|
||||
return RecursiveTreeItemIterator(pCtrl, hEndItem);
|
||||
}
|
||||
|
||||
inline NonRecursiveTreeItemIterator BeginTreeItemsNonRecursive(CTreeCtrl* pCtrl, HTREEITEM hItem = 0)
|
||||
{
|
||||
if (hItem == 0)
|
||||
{
|
||||
hItem = (pCtrl ? pCtrl->GetRootItem() : 0);
|
||||
}
|
||||
if (hItem)
|
||||
{
|
||||
hItem = pCtrl->GetChildItem(hItem);
|
||||
}
|
||||
return NonRecursiveTreeItemIterator(pCtrl, hItem);
|
||||
}
|
||||
|
||||
inline NonRecursiveTreeItemIterator EndTreeItemsNonRecursive(CTreeCtrl* pCtrl, HTREEITEM hItem = 0)
|
||||
{
|
||||
HTREEITEM hEndItem = 0;
|
||||
HTREEITEM hParent = 0;
|
||||
while (hParent && !hEndItem)
|
||||
{
|
||||
hParent = (pCtrl && hItem ? pCtrl->GetParentItem(hItem) : 0);
|
||||
if (hParent)
|
||||
{
|
||||
hEndItem = pCtrl->GetNextSiblingItem(hParent);
|
||||
}
|
||||
}
|
||||
return NonRecursiveTreeItemIterator(pCtrl, hEndItem);
|
||||
}
|
||||
|
||||
template <typename T, typename P>
|
||||
class TreeItemDataIterator
|
||||
{
|
||||
public:
|
||||
typedef T Type;
|
||||
typedef TreeItemIterator<P> InternalIterator;
|
||||
|
||||
//iterator traits, required by STL
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef Type* value_type;
|
||||
typedef Type** pointer;
|
||||
typedef Type*& reference;
|
||||
typedef std::forward_iterator_tag iterator_category;
|
||||
|
||||
TreeItemDataIterator() {}
|
||||
TreeItemDataIterator(const TreeItemDataIterator& other)
|
||||
: iterator(other.iterator) {AdvanceToValidIterator(); }
|
||||
explicit TreeItemDataIterator(const InternalIterator& iterator)
|
||||
: iterator(iterator) {AdvanceToValidIterator(); }
|
||||
|
||||
Type* operator*() {return reinterpret_cast<Type*>(iterator.pCtrl->GetItemData(iterator.hItem)); }
|
||||
bool operator==(const TreeItemDataIterator& other) const {return iterator == other.iterator; }
|
||||
bool operator!=(const TreeItemDataIterator& other) const {return iterator != other.iterator; }
|
||||
|
||||
HTREEITEM GetTreeItem() {return iterator.hItem; }
|
||||
|
||||
TreeItemDataIterator& operator++()
|
||||
{
|
||||
++iterator;
|
||||
AdvanceToValidIterator();
|
||||
return *this;
|
||||
}
|
||||
|
||||
TreeItemDataIterator operator++(int) {TreeItemDataIterator old = *this; ++(*this); return old; }
|
||||
|
||||
private:
|
||||
void AdvanceToValidIterator()
|
||||
{
|
||||
while (iterator.pCtrl && iterator.hItem && !iterator.pCtrl->GetItemData(iterator.hItem))
|
||||
{
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
|
||||
InternalIterator iterator;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class RecursiveItemDataIteratorType
|
||||
{
|
||||
public: typedef TreeItemDataIterator<T, RecursiveTreeItemIteratorTraits> type;
|
||||
};
|
||||
template <typename T>
|
||||
inline TreeItemDataIterator<T, RecursiveTreeItemIteratorTraits> BeginTreeItemDataRecursive(CTreeCtrl* pCtrl, HTREEITEM hItem = 0)
|
||||
{
|
||||
return TreeItemDataIterator<T, RecursiveTreeItemIteratorTraits>(BeginTreeItemsRecursive(pCtrl, hItem));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline TreeItemDataIterator<T, RecursiveTreeItemIteratorTraits> EndTreeItemDataRecursive(CTreeCtrl* pCtrl, HTREEITEM hItem = 0)
|
||||
{
|
||||
return TreeItemDataIterator<T, RecursiveTreeItemIteratorTraits>(EndTreeItemsRecursive(pCtrl, hItem));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class NonRecursiveItemDataIteratorType
|
||||
{
|
||||
typedef TreeItemDataIterator<T, NonRecursiveTreeItemIteratorTraits> type;
|
||||
};
|
||||
template <typename T>
|
||||
inline TreeItemDataIterator<T, NonRecursiveTreeItemIteratorTraits> BeginTreeItemDataNonRecursive(CTreeCtrl* pCtrl, HTREEITEM hItem = 0)
|
||||
{
|
||||
return TreeItemDataIterator<T, NonRecursiveTreeItemIteratorTraits>(BeginTreeItemsNonRecursive(pCtrl, hItem));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline TreeItemDataIterator<T, NonRecursiveTreeItemIteratorTraits> EndTreeItemDataNonRecursive(CTreeCtrl* pCtrl, HTREEITEM hItem = 0)
|
||||
{
|
||||
return TreeItemDataIterator<T, NonRecursiveTreeItemIteratorTraits>(EndTreeItemsNonRecursive(pCtrl, hItem));
|
||||
}
|
||||
|
||||
class SelectedTreeItemIterator
|
||||
{
|
||||
public:
|
||||
SelectedTreeItemIterator()
|
||||
: pCtrl(0)
|
||||
, hItem(0) {}
|
||||
SelectedTreeItemIterator(const SelectedTreeItemIterator& other)
|
||||
: pCtrl(other.pCtrl)
|
||||
, hItem(other.hItem) {}
|
||||
SelectedTreeItemIterator(CXTTreeCtrl* pCtrl, HTREEITEM hItem)
|
||||
: pCtrl(pCtrl)
|
||||
, hItem(hItem) {}
|
||||
|
||||
HTREEITEM operator*() {return hItem; }
|
||||
bool operator==(const SelectedTreeItemIterator& other) const {return pCtrl == other.pCtrl && hItem == other.hItem; }
|
||||
bool operator!=(const SelectedTreeItemIterator& other) const {return pCtrl != other.pCtrl || hItem != other.hItem; }
|
||||
|
||||
SelectedTreeItemIterator& operator++()
|
||||
{
|
||||
hItem = (pCtrl ? pCtrl->GetNextSelectedItem(hItem) : 0);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
SelectedTreeItemIterator operator++(int) {SelectedTreeItemIterator old = *this; ++(*this); return old; }
|
||||
|
||||
CXTTreeCtrl* pCtrl;
|
||||
HTREEITEM hItem;
|
||||
};
|
||||
|
||||
SelectedTreeItemIterator BeginSelectedTreeItems(CXTTreeCtrl* pCtrl)
|
||||
{
|
||||
return SelectedTreeItemIterator(pCtrl, (pCtrl ? pCtrl->GetFirstSelectedItem() : 0));
|
||||
}
|
||||
|
||||
SelectedTreeItemIterator EndSelectedTreeItems(CXTTreeCtrl* pCtrl)
|
||||
{
|
||||
return SelectedTreeItemIterator(pCtrl, 0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class SelectedTreeItemDataIterator
|
||||
{
|
||||
public:
|
||||
typedef T Type;
|
||||
typedef SelectedTreeItemIterator InternalIterator;
|
||||
|
||||
SelectedTreeItemDataIterator() {}
|
||||
SelectedTreeItemDataIterator(const SelectedTreeItemDataIterator& other)
|
||||
: iterator(other.iterator) {AdvanceToValidIterator(); }
|
||||
explicit SelectedTreeItemDataIterator(const InternalIterator& iterator)
|
||||
: iterator(iterator) {AdvanceToValidIterator(); }
|
||||
|
||||
Type* operator*() {return reinterpret_cast<Type*>(iterator.pCtrl->GetItemData(iterator.hItem)); }
|
||||
bool operator==(const SelectedTreeItemDataIterator& other) const {return iterator == other.iterator; }
|
||||
bool operator!=(const SelectedTreeItemDataIterator& other) const {return iterator != other.iterator; }
|
||||
|
||||
HTREEITEM GetTreeItem() {return iterator.hItem; }
|
||||
|
||||
SelectedTreeItemDataIterator& operator++()
|
||||
{
|
||||
++iterator;
|
||||
AdvanceToValidIterator();
|
||||
return *this;
|
||||
}
|
||||
|
||||
SelectedTreeItemDataIterator operator++(int) {SelectedTreeItemDataIterator old = *this; ++(*this); return old; }
|
||||
|
||||
private:
|
||||
void AdvanceToValidIterator()
|
||||
{
|
||||
while (iterator.pCtrl && iterator.hItem && !iterator.pCtrl->GetItemData(iterator.hItem))
|
||||
{
|
||||
++iterator;
|
||||
}
|
||||
}
|
||||
|
||||
InternalIterator iterator;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
SelectedTreeItemDataIterator<T> BeginSelectedTreeItemData(CXTTreeCtrl* pCtrl)
|
||||
{
|
||||
return SelectedTreeItemDataIterator<T>(BeginSelectedTreeItems(pCtrl));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
SelectedTreeItemDataIterator<T> EndSelectedTreeItemData(CXTTreeCtrl* pCtrl)
|
||||
{
|
||||
return SelectedTreeItemDataIterator<T>(EndSelectedTreeItems(pCtrl));
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_EDITOR_CONTROLS_TREECTRLUTILS_H
|
||||
Reference in New Issue
Block a user