Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #9

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,7 @@ gen
/lib/src/.DS_Store
.DS_Store
/.cache

build
install
.vs
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ if(NOT CMAKE_BUILD_TYPE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

# MSVC并行编译 cmake -j xxx 对于MSVC没有作用
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/Gm->) #高版本已被废弃,但是低版本的Gm会影响并行
cmake_host_system_information(RESULT CPU_NUMBER_OF_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
add_compile_options($<$<CXX_COMPILER_ID:MSVC>:/MP${CPU_NUMBER_OF_LOGICAL_CORES}>)

add_subdirectory(vanillastyle)

if (BUILD_EXAMPLES)
Expand Down
1 change: 1 addition & 0 deletions example/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ MainWindow::MainWindow(QWidget* parent)

ui->progressBar->setValue(0);
ui->toggleBtnfirst->setIconList(QStringList{":grid.svg", ":list.svg", ":download.svg"});
ui->toggleBtnfirst->setToolTips(QStringList{"Default", "Account", "Advance"});
ui->toggleBtnfirst->setColumnWidth(50);

// ui->toggleBtnSecond->setUseIcon(false);
Expand Down
2 changes: 1 addition & 1 deletion vanillastyle/include/VanillaStyle/Helper/ButtonStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class VANILLA_EXPORT ButtonStyle
bool drawPushButtonLabel(const QStyleOption* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget = nullptr) const;
};

}
} // namespace Vanilla
4 changes: 2 additions & 2 deletions vanillastyle/include/VanillaStyle/Helper/CheckBoxStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Theme;
class VANILLA_EXPORT CheckBoxStyle
{
public:
bool draw(const QStyleOption* option, QPainter* painter,const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
bool draw(const QStyleOption* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
};

} // namespace VanillaStyle
} // namespace Vanilla
2 changes: 1 addition & 1 deletion vanillastyle/include/VanillaStyle/Helper/ComboBoxStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class VANILLA_EXPORT ComboBoxStyle
bool draw(const QStyleOptionComplex* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
bool drawIndicator(const QStyleOptionComplex* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
QRect subControlRect(QStyle::ComplexControl control, const QStyleOptionComplex* option, QStyle::SubControl subControl, const std::shared_ptr<Theme>& theme,
const QWidget* widget) const;
const QWidget* widget) const;
void eventFilter(QComboBox* obj) const;
};

Expand Down
5 changes: 2 additions & 3 deletions vanillastyle/include/VanillaStyle/Helper/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ VANILLA_EXPORT QPixmap shadowPixmap(QSize const& size, double borderRadius, doub
VANILLA_EXPORT void drawUpArrow(const QString& iconPath, QPainter* painter, const QRect& rect);
VANILLA_EXPORT void drawDownArrow(const QString& iconPath, QPainter* painter, const QRect& rect);


VANILLA_EXPORT QRect insideMargin(const QRect& rect, int margin);
VANILLA_EXPORT QRectF insideMargin(const QRectF& rect, int margin);
VANILLA_EXPORT QRect insideMargin(const QRect& rect, int marginWidth, int marginHeight);
VANILLA_EXPORT QRectF insideMargin(const QRectF& rect, int marginWidth, int marginHeight);

VANILLA_EXPORT QRect centerRect(const QRect& rect, const QSize& size) ;
VANILLA_EXPORT QRect centerRect(const QRect& rect, const QSize& size);

VANILLA_EXPORT QRect centerRect(const QRect& rect, int width, int height);

VANILLA_EXPORT QRectF centerRectF(const QRectF& rect, double width, double height);

VANILLA_EXPORT bool checkBoolProperty(const QWidget* widget, const std::string& propertyName);
VANILLA_EXPORT QColor getQColorProperty(const QWidget* widget, const std::string& propertyName);
} // namespace VanillaStyle
} // namespace Vanilla
7 changes: 4 additions & 3 deletions vanillastyle/include/VanillaStyle/Helper/EventFilters.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
namespace Vanilla
{

class VANILLA_EXPORT MenuEventFilter : public QObject {
class VANILLA_EXPORT MenuEventFilter : public QObject
{
public:
explicit MenuEventFilter(QMenu* menu);

bool eventFilter(QObject* watchedObject, QEvent* evt) override;

private:
QMenu* _menu{ nullptr };
QMenu* _menu{nullptr};
};

} // namespace VanillaStyle
} // namespace Vanilla
2 changes: 1 addition & 1 deletion vanillastyle/include/VanillaStyle/Helper/MenuStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class VANILLA_EXPORT MenuStyle
void eventFilter(QMenu* obj) const;
};

} // namespace VanillaStyle
} // namespace Vanilla
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class VANILLA_EXPORT ProgressBarStyle
QRect subElementRect(QStyle::SubElement subElement, const QStyleOption* option, const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
};

} // namespace VanillaStyle
} // namespace Vanilla
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class VANILLA_EXPORT RadioButtonStyle
bool draw(const QStyleOption* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget = nullptr) const;
QRect subElementRect(QStyle::SubElement element, const QStyleOption* option, const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
};
} // namespace VanillaStyle
} // namespace Vanilla
8 changes: 5 additions & 3 deletions vanillastyle/include/VanillaStyle/Helper/ScrollBarStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ class QPainter;
class QStyleOption;
class QWidget;

namespace Vanilla {
namespace Vanilla
{

class Theme;

class VANILLA_EXPORT ScrollBarStyle {
class VANILLA_EXPORT ScrollBarStyle
{
public:
bool drawSlider(const QStyleOption* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
bool drawAddLine(const QStyleOption* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
bool drawSubLine(const QStyleOption* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget) const;
};

} // Vanilla
} // namespace Vanilla
2 changes: 1 addition & 1 deletion vanillastyle/include/VanillaStyle/Helper/SpinBoxStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class VANILLA_EXPORT SpinBoxStyle
int pixelMetric(QStyle::PixelMetric pm, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const;
};

} // namespace VanillaStyle
} // namespace Vanilla
2 changes: 0 additions & 2 deletions vanillastyle/include/VanillaStyle/Style/VanillaStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class VANILLA_EXPORT VanillaStyle : public QCommonStyle
explicit VanillaStyle(Mode mode);
~VanillaStyle();


void drawPrimitive(PrimitiveElement pe, const QStyleOption* option, QPainter* painter, const QWidget* widget = nullptr) const override;
int pixelMetric(PixelMetric pm, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const override;
void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget = nullptr) const override;
Expand Down Expand Up @@ -48,7 +47,6 @@ class VANILLA_EXPORT VanillaStyle : public QCommonStyle
template <typename T, typename F>
auto createHelper(const std::shared_ptr<T>& objectPtr, F fptr) const;


private:
Q_DECLARE_PRIVATE(VanillaStyle);
Q_DISABLE_COPY(VanillaStyle);
Expand Down
3 changes: 1 addition & 2 deletions vanillastyle/include/VanillaStyle/Theme/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "Theme.h"
#include "VanillaStyle/vglobal.h"


namespace Vanilla
{

Expand Down Expand Up @@ -41,7 +40,7 @@ class VANILLA_EXPORT ConfigErrorHanler
ErrorCallback errorCallback;
};

template<typename R, typename C>
template <typename R, typename C>
VANILLA_EXPORT R loadConfig(const QString& path, C callback, const ConfigErrorHanler& errorHandler, const Mode mode)
{
QFile file(path);
Expand Down
3 changes: 1 addition & 2 deletions vanillastyle/include/VanillaStyle/Theme/Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ enum Mode
Dark
};


enum class ColorRole
{
PrimaryText,
Expand Down Expand Up @@ -105,4 +104,4 @@ enum class ProgressMode
ModeTwo
};

}
} // namespace Vanilla
8 changes: 3 additions & 5 deletions vanillastyle/include/VanillaStyle/Theme/PatchHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class PatchConfig;
class VANILLA_EXPORT PatchHelper
{
public:
void init(const std::vector<PatchConfig> & patches);
void appendPatch(const std::vector<PatchConfig> & patches);
void init(const std::vector<PatchConfig>& patches);
void appendPatch(const std::vector<PatchConfig>& patches);
void appendPatch(const QString& patchPath);

void patchTheme(const QString& propertyValue, const std::shared_ptr<Theme>& theme);
Expand All @@ -31,7 +31,5 @@ class VANILLA_EXPORT PatchHelper
std::shared_ptr<Theme> defaultTheme = nullptr;

ConfigErrorHanler errorHandler;

};
}

} // namespace Vanilla
3 changes: 1 addition & 2 deletions vanillastyle/include/VanillaStyle/Theme/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace Vanilla
{
class ConfigManager;


class VANILLA_EXPORT Theme
{
public:
Expand Down Expand Up @@ -61,7 +60,7 @@ class VANILLA_EXPORT Theme
QColor createColor(StateFlags flags, const QStyleOption* option, ColorRole role) const;
[[nodiscard]] QColor customColor(ColorRole role) const;

[[nodiscard]] static QString checkIconFile(const std::string& path) ;
[[nodiscard]] static QString checkIconFile(const std::string& path);
[[nodiscard]] QString getIconPath(IconRole role) const;
QString getCachedIcon(const QString&, QColor color);

Expand Down
4 changes: 1 addition & 3 deletions vanillastyle/include/VanillaStyle/Theme/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "VanillaStyle/Helper/Common.h"


namespace Vanilla
{
class VanillaStyle;
Expand All @@ -19,5 +18,4 @@ struct VANILLA_EXPORT ConfigChangeNotifier

QString getPatchProperty(const QWidget* widget);

}

} // namespace Vanilla
4 changes: 2 additions & 2 deletions vanillastyle/include/VanillaStyle/Widgets/Spinner.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class VANILLA_EXPORT Spinner : public QWidget

void updataPosition();

signals:
void deltaChanged();
signals:
void deltaChanged();

protected:
void paintEvent(QPaintEvent* event) override;
Expand Down
1 change: 0 additions & 1 deletion vanillastyle/include/VanillaStyle/Widgets/SwitchButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class VANILLA_EXPORT SwitchButton : public QWidget
~SwitchButton();
[[nodiscard]] QSize sizeHint() const override;


Q_SIGNAL void toggled(bool checked);
Q_SIGNAL void checked(bool checked);

Expand Down
7 changes: 7 additions & 0 deletions vanillastyle/include/VanillaStyle/Widgets/ToggleButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class VANILLA_EXPORT ToggleButton : public QWidget
explicit ToggleButton(QWidget* parent = nullptr);
explicit ToggleButton(const QStringList& list, QWidget* parent = nullptr);
~ToggleButton();

[[nodiscard]] QSize sizeHint() const override;

void setItemList(const QStringList& list);
Expand All @@ -28,8 +29,13 @@ class VANILLA_EXPORT ToggleButton : public QWidget
void setIconList(const QStringList& list);
[[nodiscard]] const QStringList& iconList() const;

void setToolTips(const QStringList& list);
[[nodiscard]] const QStringList& toolTips() const;

void setIconColor(const QColor& color);

[[nodiscard]] int count() const;

void setEnableBackground(bool enable);
[[nodiscard]] bool enableBackground() const;

Expand All @@ -54,6 +60,7 @@ class VANILLA_EXPORT ToggleButton : public QWidget
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
bool event(QEvent* event) override;

ToggleButtonPrivate* d_ptr;

Expand Down
4 changes: 2 additions & 2 deletions vanillastyle/include/VanillaStyle/vglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <QtCore/QtGlobal>

#if defined(VANILLA_LIBRARY)
# define VANILLA_EXPORT Q_DECL_EXPORT
# define VANILLA_EXPORT Q_DECL_EXPORT
#else
# define VANILLA_EXPORT Q_DECL_IMPORT
# define VANILLA_EXPORT Q_DECL_IMPORT
#endif
2 changes: 1 addition & 1 deletion vanillastyle/src/Helper/CheckBoxStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Vanilla
{
bool CheckBoxStyle::draw(const QStyleOption* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget) const
{
return Helper::drawCheckBox(option,painter,theme,widget);
return Helper::drawCheckBox(option, painter, theme, widget);
}

} // namespace Vanilla
2 changes: 1 addition & 1 deletion vanillastyle/src/Helper/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ QColor getQColorProperty(const QWidget* widget, const std::string& propertyName)
{
if (const auto property = widget->property(propertyName.c_str()); property.isValid())
{
return property.value<QColor>();
return property.value<QColor>();
}
return {};
}
Expand Down
7 changes: 4 additions & 3 deletions vanillastyle/src/Helper/EventFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ bool MenuEventFilter::eventFilter(QObject* watchedObject, QEvent* evt)
// Menus have weird sizing bugs when moving them from this event.
// We have to wait for the event loop to be processed before setting the final position.
const auto menuSize = _menu->size();
if (menuSize != QSize(0, 0)) {
_menu->resize(0, 0); // Hide the menu for now until we can set the position.
if (menuSize != QSize(0, 0))
{
_menu->resize(0, 0); // Hide the menu for now until we can set the position.
QTimer::singleShot(0, _menu, [this, menuNewPos, menuSize]() {
_menu->move(menuNewPos);
_menu->resize(menuSize);
Expand All @@ -42,4 +43,4 @@ bool MenuEventFilter::eventFilter(QObject* watchedObject, QEvent* evt)
return QObject::eventFilter(watchedObject, evt);
}

} // namespace VanillaStyle
} // namespace Vanilla
2 changes: 1 addition & 1 deletion vanillastyle/src/Helper/ItemViewStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ void ItemViewStyle::drawPrimitive(const QStyleOption* option, QPainter* painter,
Helper::renderRoundRect(painter, rect.adjusted(1, 3, -1, -3), bgColor, radius);
}
}
} // namespace VanillaStyle
} // namespace Vanilla
1 change: 0 additions & 1 deletion vanillastyle/src/Helper/ScrollBarStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ bool ScrollBarStyle::drawSlider(const QStyleOption* option, QPainter* painter, c
Helper::renderRoundRect(painter, handleRect, color, radius);
return true;
}

}

bool ScrollBarStyle::drawAddLine(const QStyleOption* option, QPainter* painter, const std::shared_ptr<Theme>& theme, const QWidget* widget) const
Expand Down
1 change: 0 additions & 1 deletion vanillastyle/src/Helper/SpinBoxStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ bool SpinBoxStyle::draw(const QStyleOptionComplex* option, QPainter* painter, co
const auto fgColor = theme->getColor(opt, ColorRole::LineEditOutline);
Helper::renderRoundBorder(painter, rect, fgColor, 1.5, 5);


// 画箭头
if (opt->buttonSymbols != QAbstractSpinBox::NoButtons)
{
Expand Down
6 changes: 3 additions & 3 deletions vanillastyle/src/Style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

void Vanilla::Style::setDefaultTheme(const Mode mode)
{
auto *const style = getStyle();
auto* const style = getStyle();
style->setMode(mode);
qApp->setStyle(style);
}
Expand All @@ -22,7 +22,7 @@ void Vanilla::Style::setStyleFromPath(const QString& configPath)
{
if (QFile::exists(configPath))
{
auto *const style = getStyle();
auto* const style = getStyle();
style->setConfigPath(configPath);
qApp->setStyle(style);
}
Expand All @@ -35,7 +35,7 @@ void Vanilla::Style::setStyleFromPath(const QString& configPath)

void Vanilla::Style::appendPatch(const QString& patchConfigPath)
{
auto *const style = getStyle();
auto* const style = getStyle();
style->appendPatch(patchConfigPath);
}

Expand Down
2 changes: 1 addition & 1 deletion vanillastyle/src/Style/VanillaStyle_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class VanillaStylePrivate
{
public:
explicit VanillaStylePrivate(VanillaStyle* q);
explicit VanillaStylePrivate(VanillaStyle*q, Mode mode);
explicit VanillaStylePrivate(VanillaStyle* q, Mode mode);
void init() const;
void updatePalette() const;
void updateFont() const;
Expand Down
Loading
Loading