git mv Code\Sandbox\Editor Code/Editor
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "ClickableLabel.h"
|
||||
|
||||
|
||||
ClickableLabel::ClickableLabel(const QString& text, QWidget* parent)
|
||||
: QLabel(parent)
|
||||
, m_text(text)
|
||||
, m_showDecoration(false)
|
||||
{
|
||||
setTextFormat(Qt::RichText);
|
||||
setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
}
|
||||
|
||||
ClickableLabel::ClickableLabel(QWidget* parent)
|
||||
: QLabel(parent)
|
||||
, m_showDecoration(false)
|
||||
{
|
||||
setTextFormat(Qt::RichText);
|
||||
setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
}
|
||||
|
||||
void ClickableLabel::showEvent([[maybe_unused]] QShowEvent* event)
|
||||
{
|
||||
updateFormatting(false);
|
||||
}
|
||||
|
||||
void ClickableLabel::enterEvent(QEvent* ev)
|
||||
{
|
||||
if (!isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
updateFormatting(true);
|
||||
QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
|
||||
QLabel::enterEvent(ev);
|
||||
}
|
||||
|
||||
void ClickableLabel::leaveEvent(QEvent* ev)
|
||||
{
|
||||
if (!isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
updateFormatting(false);
|
||||
QApplication::restoreOverrideCursor();
|
||||
QLabel::leaveEvent(ev);
|
||||
}
|
||||
|
||||
void ClickableLabel::setText(const QString& text)
|
||||
{
|
||||
m_text = text;
|
||||
QLabel::setText(text);
|
||||
updateFormatting(false);
|
||||
}
|
||||
|
||||
void ClickableLabel::setShowDecoration(bool b)
|
||||
{
|
||||
m_showDecoration = b;
|
||||
updateFormatting(false);
|
||||
}
|
||||
|
||||
void ClickableLabel::updateFormatting(bool mouseOver)
|
||||
{
|
||||
//FIXME: this should be done differently. Using a style sheet would be easiest.
|
||||
|
||||
QColor c = palette().color(QPalette::WindowText);
|
||||
if (mouseOver || m_showDecoration)
|
||||
{
|
||||
QLabel::setText(QString(R"(<a href="dummy" style="color: %1";>%2</a>)").arg(c.name(), m_text));
|
||||
}
|
||||
else
|
||||
{
|
||||
QLabel::setText(m_text);
|
||||
}
|
||||
}
|
||||
|
||||
bool ClickableLabel::event(QEvent* e)
|
||||
{
|
||||
if (isEnabled())
|
||||
{
|
||||
if (e->type() == QEvent::MouseButtonDblClick)
|
||||
{
|
||||
emit linkActivated(QString());
|
||||
return true; //ignore
|
||||
}
|
||||
}
|
||||
|
||||
return QLabel::event(e);
|
||||
}
|
||||
|
||||
#include <QtUI/moc_ClickableLabel.cpp>
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef CRYINCLUDE_EDITORCOMMON_CLICKABLELABEL_H
|
||||
#define CRYINCLUDE_EDITORCOMMON_CLICKABLELABEL_H
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QLabel>
|
||||
#endif
|
||||
|
||||
class SANDBOX_API ClickableLabel
|
||||
: public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ClickableLabel(const QString& text, QWidget* parent = nullptr);
|
||||
explicit ClickableLabel(QWidget* parent = nullptr);
|
||||
bool event(QEvent* e) override;
|
||||
|
||||
void setText(const QString& text);
|
||||
void setShowDecoration(bool b);
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
void enterEvent(QEvent* ev) override;
|
||||
void leaveEvent(QEvent* ev) override;
|
||||
|
||||
private:
|
||||
void updateFormatting(bool mouseOver);
|
||||
QString m_text;
|
||||
bool m_showDecoration;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#include <AzCore/PlatformDef.h>
|
||||
#include <platform.h>
|
||||
|
||||
#include "ColorButton.h"
|
||||
|
||||
// Qt
|
||||
#include <QPainter>
|
||||
|
||||
// AzQtComponents
|
||||
#include <AzQtComponents/Components/Widgets/ColorPicker.h> // for AzQtComponents::ColorPicker
|
||||
#include <AzQtComponents/Utilities/Conversions.h> // for AzQtComponents::toQColor
|
||||
|
||||
|
||||
ColorButton::ColorButton(QWidget* parent /* = nullptr */)
|
||||
: QToolButton(parent)
|
||||
{
|
||||
connect(this, &ColorButton::clicked, this, &ColorButton::OnClick);
|
||||
}
|
||||
|
||||
void ColorButton::paintEvent([[maybe_unused]] QPaintEvent* event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
painter.fillRect(rect(), m_color);
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawRect(rect().adjusted(0, 0, -1, -1));
|
||||
}
|
||||
|
||||
#if AZ_TRAIT_OS_PLATFORM_APPLE
|
||||
void macRaiseWindowDelayed(QWidget* window);
|
||||
#endif
|
||||
|
||||
void ColorButton::OnClick()
|
||||
{
|
||||
const QColor color = AzQtComponents::toQColor(
|
||||
AzQtComponents::ColorPicker::getColor(AzQtComponents::ColorPicker::Configuration::RGB,
|
||||
AzQtComponents::fromQColor(m_color),
|
||||
tr("Select Color")));
|
||||
|
||||
#if AZ_TRAIT_OS_PLATFORM_APPLE
|
||||
macRaiseWindowDelayed(window());
|
||||
#endif
|
||||
|
||||
if (color != m_color)
|
||||
|
||||
{
|
||||
m_color = color;
|
||||
update();
|
||||
emit ColorChanged(m_color);
|
||||
}
|
||||
}
|
||||
|
||||
#include <QtUI/moc_ColorButton.cpp>
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef CRYINCLUDE_EDITORCOMMON_COLORBUTTON_H
|
||||
#define CRYINCLUDE_EDITORCOMMON_COLORBUTTON_H
|
||||
|
||||
#include <Include/EditorCoreAPI.h>
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QToolButton>
|
||||
#endif
|
||||
|
||||
class QColor;
|
||||
class QPaintEvent;
|
||||
|
||||
class EDITOR_CORE_API ColorButton
|
||||
: public QToolButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QColor Color READ Color WRITE SetColor)
|
||||
|
||||
public:
|
||||
ColorButton(QWidget* parent = nullptr);
|
||||
virtual ~ColorButton() {};
|
||||
|
||||
QColor Color() const { return m_color; }
|
||||
void SetColor(const QColor& color)
|
||||
{
|
||||
m_color = color;
|
||||
update();
|
||||
}
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
QColor m_color;
|
||||
|
||||
signals:
|
||||
void ColorChanged(const QColor& color);
|
||||
|
||||
private slots:
|
||||
void OnClick();
|
||||
};
|
||||
|
||||
#endif // CRYINCLUDE_EDITORCOMMON_COLORBUTTON_H
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include <QTimer>
|
||||
#include <QVariant>
|
||||
#include <QWidget>
|
||||
|
||||
// this makes sure the native widget of the window
|
||||
// has the same window level as it should have
|
||||
// the problem is that for some reason the window level is changed to 0
|
||||
// unfortunately not directly so we have to check repeated times
|
||||
void macRaiseWindowDelayed(QWidget* window)
|
||||
{
|
||||
NSWindow* nativeWindow = [(NSView*)(window->winId()) window];
|
||||
CGWindowLevel level = nativeWindow.level;
|
||||
QTimer* t = new QTimer(window);
|
||||
QObject::connect(t, &QTimer::timeout, t, [t,nativeWindow,level] {
|
||||
if (nativeWindow.level != level)
|
||||
{
|
||||
// level was changed -> we can break as soon as we fixed it
|
||||
t->setProperty("raiseCounter", 99);
|
||||
}
|
||||
if (nativeWindow.level == level && t->property("raiseCounter").toInt() >= 99)
|
||||
{
|
||||
// break condition met and correct level -> end this
|
||||
t->deleteLater();
|
||||
}
|
||||
t->setProperty("raiseCounter", t->property("raiseCounter").toInt() + 1);
|
||||
// try to set the right level
|
||||
nativeWindow.level = level;
|
||||
});
|
||||
t->start(10);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "PixmapLabelPreview.h"
|
||||
|
||||
PixmapLabelPreview::PixmapLabelPreview(QWidget* parent)
|
||||
: QLabel(parent)
|
||||
, m_mode(Qt::IgnoreAspectRatio)
|
||||
{
|
||||
this->setMinimumSize(10, 10);
|
||||
}
|
||||
|
||||
void PixmapLabelPreview::setPixmap(const QPixmap& p)
|
||||
{
|
||||
m_pixmap = p;
|
||||
QLabel::setPixmap(transformPixmap(p));
|
||||
}
|
||||
|
||||
int PixmapLabelPreview::heightForWidth(int width) const
|
||||
{
|
||||
if (m_mode == Qt::KeepAspectRatio)
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
return ((qreal)m_pixmap.height() * width) / m_pixmap.width();
|
||||
}
|
||||
|
||||
|
||||
QSize PixmapLabelPreview::sizeHint() const
|
||||
{
|
||||
int w = this->width();
|
||||
return QSize(w, heightForWidth(w));
|
||||
}
|
||||
|
||||
void PixmapLabelPreview::setAspectRatioMode(Qt::AspectRatioMode mode)
|
||||
{
|
||||
m_mode = mode;
|
||||
}
|
||||
|
||||
void PixmapLabelPreview::resizeEvent([[maybe_unused]] QResizeEvent* e)
|
||||
{
|
||||
QLabel::setPixmap(transformPixmap(m_pixmap));
|
||||
}
|
||||
|
||||
QPixmap PixmapLabelPreview::transformPixmap(QPixmap pix)
|
||||
{
|
||||
return pix.scaled(this->size(), m_mode, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
#include <QtUI/moc_PixmapLabelPreview.cpp>
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PIXMAPLABELPREVIEW_H
|
||||
#define PIXMAPLABELPREVIEW_H
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QResizeEvent>
|
||||
#endif
|
||||
|
||||
class PixmapLabelPreview
|
||||
: public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PixmapLabelPreview(QWidget* parent = 0);
|
||||
virtual int heightForWidth(int width) const;
|
||||
virtual QSize sizeHint() const;
|
||||
|
||||
public slots:
|
||||
void setAspectRatioMode(Qt::AspectRatioMode);
|
||||
void setPixmap(const QPixmap&);
|
||||
void resizeEvent(QResizeEvent*);
|
||||
private:
|
||||
QPixmap transformPixmap(QPixmap);
|
||||
|
||||
QPixmap m_pixmap;
|
||||
Qt::AspectRatioMode m_mode;
|
||||
};
|
||||
|
||||
#endif // PIXMAPLABELPREVIEW_H
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "QtUI/QCollapsibleGroupBox.h"
|
||||
|
||||
|
||||
QCollapsibleGroupBox::QCollapsibleGroupBox(QWidget* parent)
|
||||
: QGroupBox(parent)
|
||||
, m_collapsed(false)
|
||||
, m_toggleButton(0)
|
||||
{
|
||||
m_toggleButton = new QToolButton(this);
|
||||
m_toggleButton->setFixedSize(16, 16);
|
||||
m_toggleButton->setArrowType(Qt::DownArrow);
|
||||
connect(m_toggleButton, &QToolButton::clicked, this, [&]()
|
||||
{
|
||||
setCollapsed(!m_collapsed);
|
||||
});
|
||||
}
|
||||
|
||||
QCollapsibleGroupBox::~QCollapsibleGroupBox()
|
||||
{
|
||||
}
|
||||
|
||||
void QCollapsibleGroupBox::setCollapsed(bool v)
|
||||
{
|
||||
if (v == m_collapsed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_collapsed = v;
|
||||
if (m_collapsed)
|
||||
{
|
||||
m_visibleState.clear();
|
||||
}
|
||||
Q_FOREACH(QObject * child, children())
|
||||
{
|
||||
QWidget* w = qobject_cast<QWidget*>(child);
|
||||
if (w && w != m_toggleButton)
|
||||
{
|
||||
if (m_collapsed)
|
||||
{
|
||||
m_visibleState[w] = w->isVisible();
|
||||
w->setHidden(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_visibleState.contains(w))
|
||||
{
|
||||
w->setVisible(m_visibleState[w]);
|
||||
}
|
||||
else
|
||||
{
|
||||
w->setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_toggleButton->setArrowType(v ? Qt::LeftArrow : Qt::DownArrow);
|
||||
adaptSize(v);
|
||||
Q_EMIT collapsed(v);
|
||||
}
|
||||
|
||||
void QCollapsibleGroupBox::resizeEvent(QResizeEvent* event)
|
||||
{
|
||||
if (m_toggleButton)
|
||||
{
|
||||
m_toggleButton->move(event->size().width() - m_toggleButton->width() - 1, 1);
|
||||
}
|
||||
QGroupBox::resizeEvent(event);
|
||||
}
|
||||
|
||||
void QCollapsibleGroupBox::adaptSize(bool v)
|
||||
{
|
||||
if (v)
|
||||
{
|
||||
m_expandedSize = maximumSize();
|
||||
setMaximumHeight(fontMetrics().height() + 5); // shrinking to just let the groupbox title
|
||||
}
|
||||
else
|
||||
{
|
||||
setMaximumHeight(m_expandedSize.height());
|
||||
}
|
||||
}
|
||||
|
||||
#include <QtUI/moc_QCollapsibleGroupBox.cpp>
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef CRYINCLUDE_EDITORCOMMON_QCOLLAPSIBLEGROUPBOX_H
|
||||
#define CRYINCLUDE_EDITORCOMMON_QCOLLAPSIBLEGROUPBOX_H
|
||||
|
||||
#if !defined(Q_MOC_RUN)
|
||||
#include <QGroupBox>
|
||||
#include <QToolButton>
|
||||
#include <QHash>
|
||||
#endif
|
||||
|
||||
|
||||
class QCollapsibleGroupBox
|
||||
: public QGroupBox
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed NOTIFY collapsed)
|
||||
public:
|
||||
QCollapsibleGroupBox(QWidget* parent);
|
||||
~QCollapsibleGroupBox();
|
||||
|
||||
bool collapsed() const { return m_collapsed; }
|
||||
|
||||
public slots:
|
||||
void setCollapsed(bool v);
|
||||
|
||||
signals:
|
||||
void collapsed(bool);
|
||||
|
||||
protected:
|
||||
void adaptSize(bool v);
|
||||
void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
|
||||
|
||||
QSize m_expandedSize;
|
||||
bool m_collapsed;
|
||||
QToolButton* m_toggleButton;
|
||||
QHash<QWidget*, bool> m_visibleState;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "EditorDefs.h"
|
||||
|
||||
#include "WaitCursor.h"
|
||||
|
||||
// Qt
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
WaitCursor::WaitCursor()
|
||||
{
|
||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||
}
|
||||
|
||||
WaitCursor::~WaitCursor()
|
||||
{
|
||||
QApplication::restoreOverrideCursor();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
#ifndef CRYINCLUDE_EDITORCOMMON_WAITCURSOR_H
|
||||
#define CRYINCLUDE_EDITORCOMMON_WAITCURSOR_H
|
||||
|
||||
class WaitCursor
|
||||
{
|
||||
public:
|
||||
WaitCursor();
|
||||
~WaitCursor();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user