Skip to content

Commit

Permalink
cosmetic, allow to remove comment blocks (fix #925)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Apr 7, 2019
1 parent cc8cb4d commit e7ee45b
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ int main(int argc, char** argv)

QPixmapCache::setCacheLimit(819200);
Application app(argc, argv);
;

app.init();
int res = app.exec();

Expand Down
18 changes: 9 additions & 9 deletions src/lib/resources/qsimpledarkstyle.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1010,32 +1010,32 @@ QCheckBox:focus {
border: none;
}

StyledButton {
score--StyledButton {
background-color: #252930;
border: 0px solid #aaa;
border: 1px solid #252930;
}
StyledButton:hover {
score--StyledButton:hover {
border: 1px solid #aaa;
}

StyledButton#SplitCondition {
score--StyledButton#SplitCondition {
image: url(:/icons/split_condition_off.png);
}

StyledButton#SplitCondition:hover {
score--StyledButton#SplitCondition:hover {
image: url(:/icons/split_condition_on.png);
}

StyledButton#Desynchronize {
score--StyledButton#Desynchronize {
image: url(:/icons/desynchronize_off.png);
}
StyledButton#Desynchronize:hover {
score--StyledButton#Desynchronize:hover {
image: url(:/icons/desynchronize_on.png);
}

StyledButton#FullView {
score--StyledButton#FullView {
image: url(:/icons/fullview_off.png);
}
StyledButton#FullView:hover {
score--StyledButton#FullView:hover {
image: url(:/icons/fullview_on.png);
}
2 changes: 1 addition & 1 deletion src/lib/score/widgets/StyledButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace score
StyledButton::StyledButton(QWidget* parent) : QPushButton{parent}
{
setMinimumSize(QSize(45, 45));
setIconSize(QSize(35, 35));
setIconSize(QSize(35, 33));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Style::Style(score::Skin& s) noexcept
, TimeRuler{&s.Base1}
, LocalTimeRuler{&s.Gray}
, CommentBlockPen{Qt::white, 1.}
, CommentBlockSelectedPen{Qt::white, 2.}
, SeparatorPen{Qt::white, 2.}
, SeparatorBrush{Qt::white}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ struct SCORE_LIB_PROCESS_EXPORT Style
QPen SlotHandlePen;

QPen CommentBlockPen;
QPen CommentBlockSelectedPen;
QPen MiniScenarioPen;
QPen SeparatorPen;
QBrush SeparatorBrush;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,36 @@ void CreateCommentBlock::deserializeImpl(DataStreamOutput& s)
{
s >> m_path >> m_date >> m_y >> m_id;
}

RemoveCommentBlock::RemoveCommentBlock(
const Scenario::ProcessModel& sc,
const Scenario::CommentBlockModel& cb)
: m_path{sc}, m_id{cb.id()}, m_block{score::marshall<DataStream>(cb)}
{
}

void RemoveCommentBlock::undo(const score::DocumentContext& ctx) const
{
auto& scenar = m_path.find(ctx);

auto comment = new CommentBlockModel{DataStreamWriter{m_block}, &scenar};
scenar.comments.add(comment);
}

void RemoveCommentBlock::redo(const score::DocumentContext& ctx) const
{
auto& scenar = m_path.find(ctx);
ScenarioCreate<CommentBlockModel>::undo(m_id, scenar);
}

void RemoveCommentBlock::serializeImpl(DataStreamInput& s) const
{
s << m_path << m_id << m_block;
}

void RemoveCommentBlock::deserializeImpl(DataStreamOutput& s)
{
s >> m_path >> m_id >> m_block;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,29 @@ class CreateCommentBlock final : public score::Command

Id<CommentBlockModel> m_id;
};
class RemoveCommentBlock final : public score::Command
{
SCORE_COMMAND_DECL(
ScenarioCommandFactoryName(),
RemoveCommentBlock,
"Remove a comment block")
public:
RemoveCommentBlock(
const Scenario::ProcessModel& sc,
const Scenario::CommentBlockModel& cb
);

void undo(const score::DocumentContext& ctx) const override;
void redo(const score::DocumentContext& ctx) const override;

protected:
void serializeImpl(DataStreamInput&) const override;
void deserializeImpl(DataStreamOutput&) override;

private:
Path<ProcessModel> m_path;
Id<CommentBlockModel> m_id;
QByteArray m_block;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <score/graphics/GraphicsItem.hpp>

#include <wobjectimpl.h>
#include <score/document/DocumentContext.hpp>
#include <score/selection/SelectionDispatcher.hpp>
W_OBJECT_IMPL(Scenario::CommentBlockPresenter)

namespace Scenario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ void CommentBlockView::paint(
{
auto& skin = Process::Style::instance();

painter->setPen(skin.CommentBlockPen);
if(!m_selected)
painter->setPen(skin.CommentBlockPen);
else
painter->setPen(skin.CommentBlockSelectedPen);
painter->setBrush(skin.TransparentBrush);
painter->drawRoundedRect(boundingRect(), 5., 5.);
}
Expand All @@ -66,17 +69,17 @@ QRectF CommentBlockView::boundingRect() const
return {-1., -1., 2., 2.};
}

void CommentBlockView::setSelected(bool b)
void CommentBlockView::setHtmlContent(QString htmlText)
{
if (m_selected == b)
return;

m_selected = b;
m_textItem->setHtml(htmlText);
}

void CommentBlockView::setHtmlContent(QString htmlText)
void CommentBlockView::setSelected(bool b)
{
m_textItem->setHtml(htmlText);
if (b != m_selected) {
m_selected = b;
update();
}
}

void CommentBlockView::mousePressEvent(QGraphicsSceneMouseEvent* event)
Expand Down Expand Up @@ -105,6 +108,8 @@ void CommentBlockView::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)

void CommentBlockView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* evt)
{
m_presenter.selected();

focusOnText();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <QGraphicsItem>
#include <QObject>
#include <QPointF>
#include <wobjectdefs.h>
namespace score
{
class TextItem;
Expand Down Expand Up @@ -34,9 +35,10 @@ class CommentBlockView final : public QObject, public QGraphicsItem

QRectF boundingRect() const override;

void setSelected(bool b);
void setHtmlContent(QString htmlText);

void setSelected(bool);

protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event) override;
void mouseMoveEvent(QGraphicsSceneMouseEvent* event) override;
Expand All @@ -50,9 +52,9 @@ class CommentBlockView final : public QObject, public QGraphicsItem
CommentBlockPresenter& m_presenter;

score::TextItem* m_textItem{};
bool m_selected{false};

QPointF m_clickedPoint{};
QPointF m_clickedScenePoint{};
bool m_selected{};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Scenario/Document/ScenarioDocument/ScenarioDocumentModel.hpp>
#include <Scenario/Process/ScenarioGlobalCommandManager.hpp>

#include <Scenario/Commands/Scenario/Creations/CreateCommentBlock.hpp>
#include <score/document/DocumentInterface.hpp>
#include <score/model/ObjectRemover.hpp>
namespace Scenario
Expand Down Expand Up @@ -44,6 +45,17 @@ class ScenarioRemover final : public score::ObjectRemover

if (auto sm = focusedScenarioModel(ctx))
{
if (s.size() == 1)
{
auto first = s.begin()->data();
if(auto cb = qobject_cast<const Scenario::CommentBlockModel*>(first))
{
CommandDispatcher<> d{ctx.commandStack};
d.submit<Command::RemoveCommentBlock>(*sm, *cb);
return true;
}
}

Scenario::removeSelection(*sm, ctx);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,9 @@ ObjectPanelDelegate::ObjectPanelDelegate(
{
m_widget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_widget->setMinimumHeight(100);
m_widget->setSizeHint({200, 100});
m_widget->setSizeHint({250, 100});
m_widget->setMinimumWidth(250);
m_widget->setMaximumWidth(250);
m_widget->setStatusTip(QObject::tr("Shows the currently selected items.\n"
"They can be renamed by double-clicking.\n"
"More options are available on the right-click menu."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ ScenarioPresenter::ScenarioPresenter(
m_view,
&ScenarioView::keyPressed,
this,
&ScenarioPresenter::on_keyPressed);
&ScenarioPresenter::keyPressed);
connect(
m_view,
&ScenarioView::keyReleased,
this,
&ScenarioPresenter::on_keyReleased);
&ScenarioPresenter::keyReleased);

connect(
m_view,
Expand Down Expand Up @@ -396,16 +396,6 @@ void ScenarioPresenter::on_askUpdate()
m_view->update();
}

void ScenarioPresenter::on_keyPressed(int k)
{
keyPressed(k);
}

void ScenarioPresenter::on_keyReleased(int k)
{
keyReleased(k);
}

void ScenarioPresenter::on_intervalExecutionTimer()
{
for (TemporalIntervalPresenter& cst : m_intervals)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,6 @@ class SCORE_PLUGIN_SCENARIO_EXPORT ScenarioPresenter final

void on_askUpdate();

void on_keyPressed(int);
void on_keyReleased(int);

void on_intervalExecutionTimer();

private:
Expand Down

0 comments on commit e7ee45b

Please sign in to comment.