mirror of
https://github.com/leozide/leocad.git
synced 2026-09-12 01:23:35 +00:00
Use QGraphicsScene::selectionChanged.
This commit is contained in:
@@ -6,52 +6,41 @@
|
||||
#include "lc_view.h"
|
||||
#include "lc_collapsiblewidget.h"
|
||||
|
||||
lcInstructionsStepImageItem::lcInstructionsStepImageItem(const QPixmap& Pixmap, QGraphicsItem* Parent, lcModel* Model, lcStep Step, lcInstructionsPropertiesWidget* PropertiesWidget)
|
||||
: QGraphicsPixmapItem(Pixmap, Parent), mModel(Model), mStep(Step), mPropertiesWidget(PropertiesWidget)
|
||||
lcInstructionsStepImageItem::lcInstructionsStepImageItem(const QPixmap& Pixmap, QGraphicsItem* Parent, lcModel* Model, lcStep Step)
|
||||
: QGraphicsPixmapItem(Pixmap, Parent), mModel(Model), mStep(Step)
|
||||
{
|
||||
}
|
||||
|
||||
void lcInstructionsStepImageItem::focusInEvent(QFocusEvent* FocusEvent)
|
||||
{
|
||||
mPropertiesWidget->StepImageItemFocusIn(this);
|
||||
|
||||
QGraphicsPixmapItem::focusInEvent(FocusEvent);
|
||||
}
|
||||
|
||||
void lcInstructionsStepImageItem::focusOutEvent(QFocusEvent* FocusEvent)
|
||||
{
|
||||
mPropertiesWidget->ItemFocusOut(this);
|
||||
|
||||
QGraphicsPixmapItem::focusOutEvent(FocusEvent);
|
||||
}
|
||||
|
||||
lcInstructionsStepNumberItem::lcInstructionsStepNumberItem(const QString& Text, QGraphicsItem* Parent, lcModel* Model, lcStep Step, lcInstructionsPropertiesWidget* PropertiesWidget)
|
||||
: QGraphicsSimpleTextItem(Text, Parent), mModel(Model), mStep(Step), mPropertiesWidget(PropertiesWidget)
|
||||
lcInstructionsStepNumberItem::lcInstructionsStepNumberItem(const QString& Text, QGraphicsItem* Parent, lcModel* Model, lcStep Step)
|
||||
: QGraphicsSimpleTextItem(Text, Parent), mModel(Model), mStep(Step)
|
||||
{
|
||||
}
|
||||
|
||||
void lcInstructionsStepNumberItem::focusInEvent(QFocusEvent* FocusEvent)
|
||||
{
|
||||
mPropertiesWidget->StepNumberItemFocusIn(this);
|
||||
|
||||
QGraphicsSimpleTextItem::focusInEvent(FocusEvent);
|
||||
}
|
||||
|
||||
void lcInstructionsStepNumberItem::focusOutEvent(QFocusEvent* FocusEvent)
|
||||
{
|
||||
mPropertiesWidget->ItemFocusOut(this);
|
||||
|
||||
QGraphicsSimpleTextItem::focusOutEvent(FocusEvent);
|
||||
}
|
||||
|
||||
lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions)
|
||||
: QGraphicsView(Parent), mInstructions(Instructions)
|
||||
lcInstructionsPageWidget::lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions, lcInstructionsPropertiesWidget* PropertiesWidget)
|
||||
: QGraphicsView(Parent), mInstructions(Instructions), mPropertiesWidget(PropertiesWidget)
|
||||
{
|
||||
}
|
||||
|
||||
void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page, lcInstructionsPropertiesWidget* PropertiesWidget)
|
||||
void lcInstructionsPageWidget::SelectionChanged()
|
||||
{
|
||||
QGraphicsScene* Scene = qobject_cast<QGraphicsScene*>(sender());
|
||||
QGraphicsItem* Focus = nullptr;
|
||||
|
||||
if (Scene)
|
||||
{
|
||||
QList<QGraphicsItem*> SelectedItems = Scene->selectedItems();
|
||||
|
||||
if (!SelectedItems.isEmpty())
|
||||
Focus = SelectedItems.first();
|
||||
}
|
||||
|
||||
mPropertiesWidget->FocusChanged(Focus);
|
||||
}
|
||||
|
||||
void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page)
|
||||
{
|
||||
QGraphicsScene* Scene = new QGraphicsScene();
|
||||
connect(Scene, &QGraphicsScene::selectionChanged, this, &lcInstructionsPageWidget::SelectionChanged);
|
||||
setScene(Scene);
|
||||
|
||||
if (!Page)
|
||||
@@ -85,11 +74,11 @@ void lcInstructionsPageWidget::SetCurrentPage(const lcInstructionsPage* Page, lc
|
||||
|
||||
QImage& StepImage = Images.front();
|
||||
|
||||
lcInstructionsStepImageItem* StepImageItem = new lcInstructionsStepImageItem(QPixmap::fromImage(StepImage), PageItem, Step.Model, Step.Step, PropertiesWidget);
|
||||
lcInstructionsStepImageItem* StepImageItem = new lcInstructionsStepImageItem(QPixmap::fromImage(StepImage), PageItem, Step.Model, Step.Step);
|
||||
StepImageItem->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
|
||||
StepImageItem->setPos(MarginsRect.left() + MarginsRect.width() * Step.Rect.x(), MarginsRect.top() + MarginsRect.height() * Step.Rect.y());
|
||||
|
||||
lcInstructionsStepNumberItem* StepNumberItem = new lcInstructionsStepNumberItem(QString::number(Step.Step), StepImageItem, Step.Model, Step.Step, PropertiesWidget);
|
||||
lcInstructionsStepNumberItem* StepNumberItem = new lcInstructionsStepNumberItem(QString::number(Step.Step), StepImageItem, Step.Model, Step.Step);
|
||||
QFont StepNumberFont;
|
||||
if (!StepNumberFont.fromString(StepProperties.StepNumberFont))
|
||||
StepNumberFont = QFont("Helvetica", 72);
|
||||
@@ -259,12 +248,6 @@ void lcInstructionsPropertiesWidget::ColorButtonClicked()
|
||||
|
||||
void lcInstructionsPropertiesWidget::StepImageItemFocusIn(lcInstructionsStepImageItem* ImageItem)
|
||||
{
|
||||
if (mFocusItem == ImageItem)
|
||||
return;
|
||||
|
||||
mFocusItem = ImageItem;
|
||||
|
||||
delete mWidget;
|
||||
mWidget = new lcCollapsibleWidget(tr("Step Properties")); // todo: disable collapse
|
||||
|
||||
QGridLayout* WidgetLayout = qobject_cast<QGridLayout*>(widget()->layout());
|
||||
@@ -283,12 +266,6 @@ void lcInstructionsPropertiesWidget::StepImageItemFocusIn(lcInstructionsStepImag
|
||||
|
||||
void lcInstructionsPropertiesWidget::StepNumberItemFocusIn(lcInstructionsStepNumberItem* NumberItem)
|
||||
{
|
||||
if (mFocusItem == NumberItem)
|
||||
return;
|
||||
|
||||
mFocusItem = NumberItem;
|
||||
|
||||
delete mWidget;
|
||||
mWidget = new lcCollapsibleWidget(tr("Step Number Properties")); // todo: disable collapse
|
||||
|
||||
QGridLayout* WidgetLayout = qobject_cast<QGridLayout*>(widget()->layout());
|
||||
@@ -326,15 +303,33 @@ void lcInstructionsPropertiesWidget::StepNumberItemFocusIn(lcInstructionsStepNum
|
||||
// connect(ColorButton, &QToolButton::clicked, this, &lcInstructionsPropertiesWidget::ColorButtonClicked);
|
||||
}
|
||||
|
||||
void lcInstructionsPropertiesWidget::ItemFocusOut(QGraphicsItem* Item)
|
||||
void lcInstructionsPropertiesWidget::FocusChanged(QGraphicsItem* FocusItem)
|
||||
{
|
||||
if (mFocusItem != Item)
|
||||
if (mFocusItem == FocusItem)
|
||||
return;
|
||||
|
||||
mFocusItem = nullptr;
|
||||
|
||||
delete mWidget;
|
||||
mWidget = nullptr;
|
||||
mFocusItem = FocusItem;
|
||||
|
||||
if (!FocusItem)
|
||||
return;
|
||||
|
||||
lcInstructionsStepImageItem* ImageItem = dynamic_cast<lcInstructionsStepImageItem*>(FocusItem);
|
||||
|
||||
if (ImageItem)
|
||||
{
|
||||
StepImageItemFocusIn(ImageItem);
|
||||
return;
|
||||
}
|
||||
|
||||
lcInstructionsStepNumberItem* NumberItem = dynamic_cast<lcInstructionsStepNumberItem*>(FocusItem);
|
||||
|
||||
if (NumberItem)
|
||||
{
|
||||
StepNumberItemFocusIn(NumberItem);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
lcInstructionsDialog::lcInstructionsDialog(QWidget* Parent, Project* Project)
|
||||
@@ -344,17 +339,17 @@ lcInstructionsDialog::lcInstructionsDialog(QWidget* Parent, Project* Project)
|
||||
|
||||
mInstructions = mProject->GetInstructions();
|
||||
|
||||
mPageWidget = new lcInstructionsPageWidget(this, mInstructions);
|
||||
mPropertiesWidget = new lcInstructionsPropertiesWidget(this, mInstructions);
|
||||
mPropertiesWidget->setObjectName("InstructionsProperties");
|
||||
addDockWidget(Qt::RightDockWidgetArea, mPropertiesWidget);
|
||||
|
||||
mPageWidget = new lcInstructionsPageWidget(this, mInstructions, mPropertiesWidget);
|
||||
setCentralWidget(mPageWidget);
|
||||
|
||||
mPageListWidget = new lcInstructionsPageListWidget(this, mInstructions);
|
||||
mPageListWidget->setObjectName("InstructionsPageList");
|
||||
addDockWidget(Qt::LeftDockWidgetArea, mPageListWidget);
|
||||
|
||||
mPropertiesWidget = new lcInstructionsPropertiesWidget(this, mInstructions);
|
||||
mPropertiesWidget->setObjectName("InstructionsProperties");
|
||||
addDockWidget(Qt::RightDockWidgetArea, mPropertiesWidget);
|
||||
|
||||
mPageSettingsToolBar = addToolBar(tr("Page Settings"));
|
||||
mPageSettingsToolBar->setObjectName("PageSettings");
|
||||
mPageSettingsToolBar->setFloatable(false);
|
||||
@@ -416,7 +411,7 @@ void lcInstructionsDialog::CurrentThumbnailChanged(int Index)
|
||||
{
|
||||
if (Index < 0 || Index >= static_cast<int>(mInstructions->mPages.size()))
|
||||
{
|
||||
mPageWidget->SetCurrentPage(nullptr, mPropertiesWidget);
|
||||
mPageWidget->SetCurrentPage(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -424,7 +419,7 @@ void lcInstructionsDialog::CurrentThumbnailChanged(int Index)
|
||||
// const lcInstructionsPageSettings& PageSettings = Page->Settings;
|
||||
const lcInstructionsPageSettings& PageSettings = mInstructions->mPageSettings;
|
||||
|
||||
mPageWidget->SetCurrentPage(Page, mPropertiesWidget);
|
||||
mPageWidget->SetCurrentPage(Page);
|
||||
|
||||
if (PageSettings.Direction == lcInstructionsDirection::Horizontal)
|
||||
{
|
||||
@@ -453,6 +448,6 @@ void lcInstructionsDialog::PageInvalid(int PageIndex)
|
||||
if (mPageListWidget->mThumbnailsWidget->currentRow() == PageIndex)
|
||||
{
|
||||
const lcInstructionsPage* Page = &mInstructions->mPages[PageIndex];
|
||||
mPageWidget->SetCurrentPage(Page, mPropertiesWidget);
|
||||
mPageWidget->SetCurrentPage(Page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ class lcInstructionsPropertiesWidget;
|
||||
class lcInstructionsStepImageItem : public QGraphicsPixmapItem
|
||||
{
|
||||
public:
|
||||
lcInstructionsStepImageItem(const QPixmap& Pixmap, QGraphicsItem* Parent, lcModel* Model, lcStep Step, lcInstructionsPropertiesWidget* PropertiesWidget);
|
||||
lcInstructionsStepImageItem(const QPixmap& Pixmap, QGraphicsItem* Parent, lcModel* Model, lcStep Step);
|
||||
|
||||
lcModel* GetModel() const
|
||||
{
|
||||
@@ -20,18 +20,14 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void focusInEvent(QFocusEvent* FocusEvent) override;
|
||||
void focusOutEvent(QFocusEvent* FocusEvent) override;
|
||||
|
||||
lcModel* mModel = nullptr;
|
||||
lcStep mStep = 1;
|
||||
lcInstructionsPropertiesWidget* mPropertiesWidget = nullptr;
|
||||
};
|
||||
|
||||
class lcInstructionsStepNumberItem : public QGraphicsSimpleTextItem
|
||||
{
|
||||
public:
|
||||
lcInstructionsStepNumberItem(const QString& Text, QGraphicsItem* Parent, lcModel* Model, lcStep Step, lcInstructionsPropertiesWidget* PropertiesWidget);
|
||||
lcInstructionsStepNumberItem(const QString& Text, QGraphicsItem* Parent, lcModel* Model, lcStep Step);
|
||||
|
||||
lcModel* GetModel() const
|
||||
{
|
||||
@@ -44,12 +40,8 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void focusInEvent(QFocusEvent* FocusEvent) override;
|
||||
void focusOutEvent(QFocusEvent* FocusEvent) override;
|
||||
|
||||
lcModel* mModel = nullptr;
|
||||
lcStep mStep = 1;
|
||||
lcInstructionsPropertiesWidget* mPropertiesWidget = nullptr;
|
||||
};
|
||||
|
||||
class lcInstructionsPageWidget : public QGraphicsView
|
||||
@@ -57,12 +49,16 @@ class lcInstructionsPageWidget : public QGraphicsView
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions);
|
||||
lcInstructionsPageWidget(QWidget* Parent, lcInstructions* Instructions, lcInstructionsPropertiesWidget* PropertiesWidget);
|
||||
|
||||
void SetCurrentPage(const lcInstructionsPage* Page, lcInstructionsPropertiesWidget* PropertiesWidget);
|
||||
void SetCurrentPage(const lcInstructionsPage* Page);
|
||||
|
||||
protected slots:
|
||||
void SelectionChanged();
|
||||
|
||||
protected:
|
||||
lcInstructions* mInstructions;
|
||||
lcInstructionsPropertiesWidget* mPropertiesWidget;
|
||||
};
|
||||
|
||||
class lcInstructionsPageListWidget : public QDockWidget
|
||||
@@ -104,14 +100,15 @@ class lcInstructionsPropertiesWidget : public QDockWidget
|
||||
public:
|
||||
lcInstructionsPropertiesWidget(QWidget* Parent, lcInstructions* Instructions);
|
||||
|
||||
void StepImageItemFocusIn(lcInstructionsStepImageItem* ImageItem);
|
||||
void StepNumberItemFocusIn(lcInstructionsStepNumberItem* NumberItem);
|
||||
void ItemFocusOut(QGraphicsItem* Item);
|
||||
void FocusChanged(QGraphicsItem* FocusItem);
|
||||
|
||||
protected slots:
|
||||
void ColorButtonClicked();
|
||||
|
||||
protected:
|
||||
void StepImageItemFocusIn(lcInstructionsStepImageItem* ImageItem);
|
||||
void StepNumberItemFocusIn(lcInstructionsStepNumberItem* NumberItem);
|
||||
|
||||
lcCollapsibleWidget* mWidget = nullptr;
|
||||
lcInstructions* mInstructions = nullptr;
|
||||
QGraphicsItem* mFocusItem = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user