diff --git a/qt/lc_qcolorlist.cpp b/common/lc_colorlist.cpp similarity index 91% rename from qt/lc_qcolorlist.cpp rename to common/lc_colorlist.cpp index 6f6f988c..3cad8055 100644 --- a/qt/lc_qcolorlist.cpp +++ b/common/lc_colorlist.cpp @@ -1,5 +1,5 @@ #include "lc_global.h" -#include "lc_qcolorlist.h" +#include "lc_colorlist.h" #include "lc_application.h" #include "lc_library.h" #include "lc_colors.h" @@ -45,17 +45,17 @@ void lcDrawNoColorRect(QPainter& Painter, const QRect& Rect) } } -lcQColorList::lcQColorList(QWidget* Parent, bool AllowNoColor) +lcColorList::lcColorList(QWidget* Parent, bool AllowNoColor) : QWidget(Parent), mAllowNoColor(AllowNoColor) { setFocusPolicy(Qt::StrongFocus); UpdateCells(); - connect(lcGetPiecesLibrary(), &lcPiecesLibrary::ColorsLoaded, this, &lcQColorList::ColorsLoaded); + connect(lcGetPiecesLibrary(), &lcPiecesLibrary::ColorsLoaded, this, &lcColorList::ColorsLoaded); } -void lcQColorList::UpdateCells() +void lcColorList::UpdateCells() { mCells.clear(); mGroups.clear(); @@ -102,7 +102,7 @@ void lcQColorList::UpdateCells() setMinimumHeight(TextHeight + 5 * mRows); } -void lcQColorList::UpdateRects() +void lcColorList::UpdateRects() { QFontMetrics Metrics(font()); int TextHeight = 0; @@ -191,22 +191,22 @@ void lcQColorList::UpdateRects() } } -void lcQColorList::ColorsLoaded() +void lcColorList::ColorsLoaded() { UpdateCells(); UpdateRects(); - setCurrentColor(lcGetColorIndex(mColorCode)); + SetCurrentColor(lcGetColorIndex(mColorCode)); update(); } -QSize lcQColorList::sizeHint() const +QSize lcColorList::sizeHint() const { return QSize(200, mPreferredHeight); } -void lcQColorList::setCurrentColor(int ColorIndex) +void lcColorList::SetCurrentColor(int ColorIndex) { for (size_t CellIndex = 0; CellIndex < mCells.size(); CellIndex++) { @@ -218,7 +218,7 @@ void lcQColorList::setCurrentColor(int ColorIndex) } } -bool lcQColorList::event(QEvent *event) +bool lcColorList::event(QEvent *event) { if (event->type() == QEvent::ToolTip) { @@ -292,7 +292,7 @@ bool lcQColorList::event(QEvent *event) return QWidget::event(event); } -void lcQColorList::mousePressEvent(QMouseEvent* MouseEvent) +void lcColorList::mousePressEvent(QMouseEvent* MouseEvent) { for (size_t CellIndex = 0; CellIndex < mCells.size(); CellIndex++) { @@ -300,7 +300,7 @@ void lcQColorList::mousePressEvent(QMouseEvent* MouseEvent) continue; SelectCell(CellIndex); - emit colorSelected(mCells[CellIndex].ColorIndex); + emit ColorSelected(mCells[CellIndex].ColorIndex); break; } @@ -308,7 +308,7 @@ void lcQColorList::mousePressEvent(QMouseEvent* MouseEvent) mDragStartPosition = MouseEvent->pos(); } -void lcQColorList::mouseMoveEvent(QMouseEvent* MouseEvent) +void lcColorList::mouseMoveEvent(QMouseEvent* MouseEvent) { if (!(MouseEvent->buttons() & Qt::LeftButton)) return; @@ -325,7 +325,7 @@ void lcQColorList::mouseMoveEvent(QMouseEvent* MouseEvent) Drag->exec(Qt::CopyAction); } -void lcQColorList::keyPressEvent(QKeyEvent *event) +void lcColorList::keyPressEvent(QKeyEvent *event) { size_t NewCell = mCurrentCell; @@ -397,7 +397,7 @@ void lcQColorList::keyPressEvent(QKeyEvent *event) } else if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { - emit colorSelected(mCells[mCurrentCell].ColorIndex); + emit ColorSelected(mCells[mCurrentCell].ColorIndex); } if (NewCell != mCurrentCell) @@ -406,7 +406,7 @@ void lcQColorList::keyPressEvent(QKeyEvent *event) QWidget::keyPressEvent(event); } -void lcQColorList::resizeEvent(QResizeEvent* Event) +void lcColorList::resizeEvent(QResizeEvent* Event) { if (mWidth == width() && mHeight == height()) return; @@ -419,7 +419,7 @@ void lcQColorList::resizeEvent(QResizeEvent* Event) QWidget::resizeEvent(Event); } -void lcQColorList::paintEvent(QPaintEvent* Event) +void lcColorList::paintEvent(QPaintEvent* Event) { Q_UNUSED(Event); @@ -463,18 +463,10 @@ void lcQColorList::paintEvent(QPaintEvent* Event) QRect CellRect = mCells[mCurrentCell].Rect; CellRect.adjust(1, 1, -1, -1); Painter.drawRect(CellRect); - - /* - if (GetFocus() == this) - { - rc.DeflateRect(2, 2); - dc.DrawFocusRect(rc); - } - */ } } -void lcQColorList::SelectCell(size_t CellIndex) +void lcColorList::SelectCell(size_t CellIndex) { if (CellIndex >= mCells.size()) return; @@ -485,6 +477,6 @@ void lcQColorList::SelectCell(size_t CellIndex) mCurrentCell = CellIndex; mColorCode = lcGetColorCode(mCells[CellIndex].ColorIndex); - emit colorChanged(mCells[mCurrentCell].ColorIndex); + emit ColorChanged(mCells[mCurrentCell].ColorIndex); update(); } diff --git a/qt/lc_qcolorlist.h b/common/lc_colorlist.h similarity index 80% rename from qt/lc_qcolorlist.h rename to common/lc_colorlist.h index 4b40a3c5..a06d64b3 100644 --- a/qt/lc_qcolorlist.h +++ b/common/lc_colorlist.h @@ -15,21 +15,21 @@ struct lcColorListGroup void lcDrawNoColorRect(QPainter& Painter, const QRect& Rect); -class lcQColorList : public QWidget +class lcColorList : public QWidget { Q_OBJECT public: - lcQColorList(QWidget* Parent = nullptr, bool AllowNoColor = false); - ~lcQColorList() = default; + lcColorList(QWidget* Parent = nullptr, bool AllowNoColor = false); + ~lcColorList() = default; QSize sizeHint() const override; - void setCurrentColor(int colorIndex); + void SetCurrentColor(int colorIndex); signals: - void colorChanged(int colorIndex); - void colorSelected(int colorIndex); + void ColorChanged(int colorIndex); + void ColorSelected(int colorIndex); protected slots: void ColorsLoaded(); diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index 429c1ff3..9b0bfe19 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -5,7 +5,7 @@ #include "lc_partselectionwidget.h" #include "lc_timelinewidget.h" #include "lc_viewwidget.h" -#include "lc_qcolorlist.h" +#include "lc_colorlist.h" #include "lc_qpropertiestree.h" #include "lc_qutils.h" #include "lc_qupdatedialog.h" @@ -674,7 +674,7 @@ void lcMainWindow::CreateToolBars() mColorsToolBar->setObjectName("ColorsToolbar"); mColorsToolBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); - mColorList = new lcQColorList(); + mColorList = new lcColorList(); connect(mColorList, SIGNAL(colorChanged(int)), this, SLOT(ColorChanged(int))); QWidget* ColorWidget = new QWidget(mColorsToolBar); @@ -2083,7 +2083,7 @@ void lcMainWindow::UpdateColor() mColorButton->setIcon(Pixmap); mColorButton->setText(QString(" ") + gColorList[mColorIndex].Name); - mColorList->setCurrentColor(mColorIndex); + mColorList->SetCurrentColor(mColorIndex); } void lcMainWindow::UpdateUndoRedo(const QString& UndoText, const QString& RedoText) diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 582681d9..4531a154 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -10,7 +10,7 @@ class lcPartSelectionWidget; class lcPreviewDockWidget; class PiecePreview; class lcQPartsTree; -class lcQColorList; +class lcColorList; class lcQPropertiesTree; class lcTimelineWidget; class lcElidedLabel; @@ -376,7 +376,7 @@ protected: QDockWidget* mTimelineToolBar; lcPartSelectionWidget* mPartSelectionWidget; - lcQColorList* mColorList; + lcColorList* mColorList; QToolButton* mColorButton; lcQPropertiesTree* mPropertiesWidget; lcTimelineWidget* mTimelineWidget; diff --git a/leocad.pro b/leocad.pro index a94e2ccf..393ac7b3 100644 --- a/leocad.pro +++ b/leocad.pro @@ -176,6 +176,7 @@ SOURCES += \ common/lc_bricklink.cpp \ common/lc_category.cpp \ common/lc_collapsiblewidget.cpp \ + common/lc_colorlist.cpp \ common/lc_colors.cpp \ common/lc_commands.cpp \ common/lc_context.cpp \ @@ -227,7 +228,6 @@ SOURCES += \ qt/lc_qutils.cpp \ qt/lc_qpropertiestree.cpp \ qt/lc_qcolorpicker.cpp \ - qt/lc_qcolorlist.cpp \ qt/lc_qmodellistdialog.cpp \ qt/lc_renderdialog.cpp \ qt/lc_setsdatabasedialog.cpp \ @@ -245,6 +245,7 @@ HEADERS += \ common/lc_bricklink.h \ common/lc_category.h \ common/lc_collapsiblewidget.h \ + common/lc_colorlist.h \ common/lc_colors.h \ common/lc_commands.h \ common/lc_context.h \ @@ -296,7 +297,6 @@ HEADERS += \ qt/lc_qutils.h \ qt/lc_qpropertiestree.h \ qt/lc_qcolorpicker.h \ - qt/lc_qcolorlist.h \ qt/lc_qmodellistdialog.h \ qt/lc_renderdialog.h \ qt/lc_setsdatabasedialog.h \ diff --git a/qt/lc_qcolorpicker.cpp b/qt/lc_qcolorpicker.cpp index 2d7e1020..8826ae89 100644 --- a/qt/lc_qcolorpicker.cpp +++ b/qt/lc_qcolorpicker.cpp @@ -1,6 +1,6 @@ #include "lc_global.h" #include "lc_qcolorpicker.h" -#include "lc_qcolorlist.h" +#include "lc_colorlist.h" #include "lc_colors.h" lcQColorPickerPopup::lcQColorPickerPopup(QWidget* Parent, int ColorIndex, bool AllowNoColor) @@ -16,13 +16,13 @@ lcQColorPickerPopup::lcQColorPickerPopup(QWidget* Parent, int ColorIndex, bool A layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); - colorList = new lcQColorList(this, AllowNoColor); - connect(colorList, SIGNAL(colorChanged(int)), this, SLOT(colorChanged(int))); - connect(colorList, SIGNAL(colorSelected(int)), this, SLOT(colorSelected(int))); + colorList = new lcColorList(this, AllowNoColor); + connect(colorList, &lcColorList::ColorChanged, this, &lcQColorPickerPopup::colorChanged); + connect(colorList, &lcColorList::ColorSelected, this, &lcQColorPickerPopup::colorSelected); layout->addWidget(colorList); colorList->blockSignals(true); - colorList->setCurrentColor(ColorIndex); + colorList->SetCurrentColor(ColorIndex); colorList->blockSignals(false); eventLoop = nullptr; diff --git a/qt/lc_qcolorpicker.h b/qt/lc_qcolorpicker.h index 3847fc4c..55fe4add 100644 --- a/qt/lc_qcolorpicker.h +++ b/qt/lc_qcolorpicker.h @@ -1,7 +1,7 @@ #pragma once #include -class lcQColorList; +class lcColorList; class lcQColorPickerPopup : public QFrame { @@ -29,7 +29,7 @@ protected: private: QEventLoop* eventLoop; - lcQColorList* colorList; + lcColorList* colorList; }; class lcQColorPicker : public QPushButton