-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
91 changed files
with
4,894 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "Clipboard.h" | ||
|
||
void Clipboard::init(const PatternScenePtr& a_scene) | ||
{ | ||
Q_ASSERT( m_scene.isNull() && !a_scene.isNull() ); | ||
m_scene = a_scene; | ||
} | ||
|
||
void Clipboard::copy() | ||
{ | ||
auto items = m_scene->selectedItems(); | ||
if (items.size() == 0) | ||
return; | ||
|
||
reset(); | ||
|
||
int smallest_frame = items[0]->frame(); | ||
for (auto item: items) | ||
{ | ||
if (smallest_frame > item->frame()) | ||
smallest_frame = item->frame(); | ||
} | ||
|
||
for (auto item: items) | ||
{ | ||
m_items << ClipboardItem{ | ||
item->key(), | ||
item->frame() - smallest_frame, | ||
item->size(), | ||
item->libraryItem().toWeakRef() | ||
}; | ||
|
||
} | ||
} | ||
|
||
void Clipboard::reset() | ||
{ | ||
m_items.clear(); | ||
} | ||
|
||
bool Clipboard::isValid() const | ||
{ | ||
for (auto& item: m_items) | ||
{ | ||
if (item.libraryItem().isNull()) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
int Clipboard::count() const | ||
{ | ||
return m_items.count(); | ||
} | ||
|
||
const ClipboardItem& Clipboard::item(int a_index) const | ||
{ | ||
Q_ASSERT(a_index >= 0 && a_index < m_items.count()); | ||
return m_items[a_index]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
#include <QObject> | ||
#include <QSharedPointer> | ||
#include "PatternScene.h" | ||
#include "ClipboardItem.h" | ||
|
||
class Clipboard: public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
void init(const PatternScenePtr& a_scene); | ||
|
||
void reset(); | ||
bool isValid() const; | ||
int count() const; | ||
const ClipboardItem& item(int a_index) const; | ||
|
||
public slots: | ||
void copy(); | ||
|
||
private: | ||
PatternScenePtr m_scene; | ||
QList<ClipboardItem> m_items; | ||
}; | ||
|
||
using ClipboardPtr = QSharedPointer<Clipboard>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "ClipboardItem.h" | ||
|
||
ClipboardItem::ClipboardItem(Key a_key, Frame a_frame, Frame a_size, LibraryItemWCPtr a_library_item) | ||
: m_key(a_key) | ||
, m_frame(a_frame) | ||
, m_size(a_size) | ||
, m_library_item(a_library_item) | ||
{ | ||
} | ||
|
||
Key ClipboardItem::key() const | ||
{ | ||
return m_key; | ||
} | ||
|
||
Frame ClipboardItem::frame() const | ||
{ | ||
return m_frame; | ||
} | ||
|
||
Frame ClipboardItem::size() const | ||
{ | ||
return m_size; | ||
} | ||
|
||
const LibraryItemWCPtr& ClipboardItem::libraryItem() const | ||
{ | ||
return m_library_item; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
#include "core_types.h" | ||
#include "LibraryItem.h" | ||
|
||
class ClipboardItem | ||
{ | ||
public: | ||
ClipboardItem() = delete; | ||
ClipboardItem(Key a_key, Frame a_frame, Frame a_size, LibraryItemWCPtr a_library_item); | ||
|
||
Key key() const; | ||
Frame frame() const; | ||
Frame size() const; | ||
const LibraryItemWCPtr& libraryItem() const; | ||
|
||
private: | ||
Key m_key; | ||
Frame m_frame; | ||
Frame m_size; | ||
LibraryItemWCPtr m_library_item; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include "core_types.h" | ||
|
||
namespace Properties::Core | ||
{ | ||
constexpr Pixel FrameWidth = 12_pix; | ||
constexpr Frame FramesPerSecond = 60_frm; | ||
constexpr Second SecondsInMinute = 60_sec; | ||
constexpr Pixel SecondWidth = FrameWidth*FramesPerSecond; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#include "LibraryDelegate.h" | ||
|
||
LibraryDelegate::LibraryDelegate(QObject* a_parent) | ||
: QStyledItemDelegate(a_parent) | ||
{ | ||
} | ||
|
||
QWidget* LibraryDelegate::createEditor(QWidget* a_parent, const QStyleOptionViewItem& a_option, const QModelIndex& a_index) const | ||
{ | ||
switch(a_index.column()) | ||
{ | ||
case LibraryModel::Column::Name: | ||
return QStyledItemDelegate::createEditor(a_parent, a_option, a_index); | ||
case LibraryModel::Column::Color: | ||
{ | ||
QColor color = a_index.data(Qt::BackgroundRole).value<QColor>(); | ||
QColorDialog* dialog = new QColorDialog(color, a_parent); | ||
dialog->setModal(true); | ||
QtTools::centerWidgetOnCursor(dialog); | ||
connect(dialog, &QColorDialog::accepted, this, &LibraryDelegate::onAccept); | ||
connect(dialog, &QColorDialog::rejected, this, &LibraryDelegate::onReject); | ||
return dialog; | ||
} | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
void LibraryDelegate::setModelData(QWidget* a_editor, QAbstractItemModel* a_model, const QModelIndex& a_index) const | ||
{ | ||
switch(a_index.column()) | ||
{ | ||
case LibraryModel::Column::Color: | ||
{ | ||
QColorDialog* dialog = qobject_cast<QColorDialog*>(a_editor); | ||
if (dialog->selectedColor().isValid()) | ||
a_model->setData(a_index, dialog->selectedColor(), Qt::BackgroundColorRole); | ||
return; | ||
} | ||
default: | ||
QStyledItemDelegate::setModelData(a_editor, a_model, a_index); | ||
} | ||
} | ||
|
||
void LibraryDelegate::paint(QPainter* a_painter, const QStyleOptionViewItem& a_option, const QModelIndex& a_index) const | ||
{ | ||
if (a_index.column() != LibraryModel::Column::Name) | ||
QStyledItemDelegate::paint(a_painter, a_option, a_index); | ||
else | ||
{ | ||
a_painter->save(); | ||
|
||
QStyleOptionViewItem option = a_option; | ||
initStyleOption(&option, a_index); | ||
option.backgroundBrush = Qt::NoBrush; | ||
|
||
// Draw as usual | ||
auto widget = a_option.widget; | ||
Q_ASSERT(widget != nullptr); | ||
widget->style()->drawControl(QStyle::CE_ItemViewItem, &option, a_painter, widget); | ||
|
||
// Draw item color icon on the right side | ||
const QModelIndex color_index = a_index.siblingAtColumn( LibraryModel::Column::Color ); | ||
QColor color = color_index.data(Qt::BackgroundRole).value<QColor>(); | ||
if (color.isValid()) | ||
{ | ||
a_painter->setPen(Qt::NoPen); | ||
a_painter->setBrush(color); | ||
int offset = static_cast<int>( a_option.rect.height() * 0.2f ); | ||
QRect position = a_option.rect.adjusted(offset,offset,-offset,-offset); | ||
position.setX( position.width() - position.height() ); | ||
a_painter->drawRect(position); | ||
} | ||
|
||
a_painter->restore(); | ||
} | ||
} | ||
|
||
void LibraryDelegate::onAccept() | ||
{ | ||
QColorDialog* dialog = qobject_cast<QColorDialog*>(sender()); | ||
emit closeEditor(dialog); | ||
emit commitData(dialog); | ||
dialog->deleteLater(); | ||
} | ||
|
||
void LibraryDelegate::onReject() | ||
{ | ||
QColorDialog* dialog = qobject_cast<QColorDialog*>(sender()); | ||
emit closeEditor(dialog); | ||
dialog->deleteLater(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
#include <QStyledItemDelegate> | ||
#include <QPainter> | ||
#include <QStyleOptionViewItem> | ||
#include <QColorDialog> | ||
#include "LibraryModel.h" | ||
#include "QtTools.h" | ||
|
||
class LibraryDelegate: public QStyledItemDelegate | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit LibraryDelegate(QObject* a_parent = nullptr); | ||
|
||
private slots: | ||
void onAccept(); | ||
void onReject(); | ||
|
||
protected: | ||
virtual QWidget* createEditor(QWidget* a_parent, const QStyleOptionViewItem& a_option, const QModelIndex& a_index) const override; | ||
virtual void setModelData(QWidget* a_editor, QAbstractItemModel* a_model, const QModelIndex& a_index) const override; | ||
virtual void paint(QPainter* a_painter, const QStyleOptionViewItem& a_option, const QModelIndex& a_index) const override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "LibraryItem.h" | ||
|
||
LibraryItem::LibraryItem( | ||
const QString& a_name, | ||
const QString& a_script, | ||
const QColor& a_color) | ||
: m_name (a_name) | ||
, m_script(a_script) | ||
, m_color (a_color) | ||
{ | ||
} | ||
|
||
const QString& LibraryItem::name() const { return m_name; } | ||
const QString& LibraryItem::script() const { return m_script; } | ||
const QColor& LibraryItem::color() const { return m_color; } | ||
|
||
void LibraryItem::setName(const QString& a_name) | ||
{ | ||
m_name = a_name; | ||
} | ||
|
||
void LibraryItem::setScript(const QString& a_script) | ||
{ | ||
m_script = a_script; | ||
} | ||
|
||
void LibraryItem::setColor(const QColor& a_color) | ||
{ | ||
m_color = a_color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
#include <QString> | ||
#include <QColor> | ||
#include <QSharedPointer> | ||
|
||
class LibraryItem | ||
{ | ||
public: | ||
LibraryItem( | ||
const QString& a_name, | ||
const QString& a_script = QString(), | ||
const QColor& a_color = Qt::white); | ||
|
||
const QString& name() const; | ||
const QString& script() const; | ||
const QColor& color() const; | ||
|
||
void setName (const QString& a_name); | ||
void setScript(const QString& a_script); | ||
void setColor (const QColor& a_color); | ||
|
||
private: | ||
QString m_name; | ||
QString m_script; | ||
QColor m_color{ Qt::white }; | ||
}; | ||
|
||
using LibraryItemPtr = QSharedPointer<LibraryItem>; | ||
using LibraryItemWCPtr = QWeakPointer<const LibraryItem>; | ||
using LibraryItemCPtr = QSharedPointer<const LibraryItem>; |
Oops, something went wrong.