initial port for Cevo game in C++ (libs)

This commit is contained in:
Geoffray Levasseur committed 2026-10-22 17:20:45 +02:00
commit 8436242032
375 files changed
+46282

No files matched your search

+114
View File
@@ -0,0 +1,114 @@
# DpiWidgets: Qt Widgets equivalent of the Lazarus/Delphi "DpiControls"
# package found at ../../cevo/Packages/DpiControls. It provides a Dpi::
# namespace of thin wrappers around Qt widgets, following the same unit
# breakdown (Common, Graphics, PixelPointer, Controls, Forms, StdCtrls,
# ExtCtrls, ComCtrls, Grids, Menus, Spin), to ease porting the C-evo UI code.
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
set(DPI_WIDGETS_HEADERS
include/Dpi/DpiCommon.h
include/Dpi/DpiPixelPointer.h
include/Dpi/DpiGraphics.h
include/Dpi/DpiControls.h
include/Dpi/DpiForms.h
include/Dpi/DpiStdCtrls.h
include/Dpi/DpiExtCtrls.h
include/Dpi/DpiComCtrls.h
include/Dpi/DpiGrids.h
include/Dpi/DpiMenus.h
include/Dpi/DpiSpin.h
include/Dpi/DpiWidgets.h
)
set(DPI_WIDGETS_SOURCES
src/DpiCommon.cpp
src/DpiPixelPointer.cpp
src/DpiGraphics.cpp
src/DpiControls.cpp
src/DpiForms.cpp
src/DpiStdCtrls.cpp
src/DpiExtCtrls.cpp
src/DpiComCtrls.cpp
src/DpiGrids.cpp
src/DpiMenus.cpp
src/DpiSpin.cpp
)
add_library(dpiwidgets SHARED ${DPI_WIDGETS_SOURCES} ${DPI_WIDGETS_HEADERS})
target_include_directories(dpiwidgets PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(dpiwidgets PUBLIC Qt${QT_VERSION_MAJOR}::Widgets)
set_target_properties(dpiwidgets PROPERTIES
AUTOMOC ON
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
# CevoWidgets: Qt equivalent of the C-evo-specific "CevoComponents" package
# (../../cevo/Packages/CevoComponents), built on top of Dpi:: above. Provides
# a Cevo:: namespace (Area, ButtonBase/A/B/C/G/N, EOTButton, ListBoxEx,
# DrawDlg/BaseMessgDlg, BufferedDrawDlg/FramedDlg, GraphicSet, Texture,
# ScreenTools' drawing helpers). Directories, StringTables, AsyncProcess2 and
# Sound are not ported: they are plain platform/data utilities (QProcess
# already covers AsyncProcess2's job; Sound is superseded by ../media).
set(CEVO_WIDGETS_HEADERS
include/Cevo/CevoArea.h
include/Cevo/CevoBaseWin.h
include/Cevo/CevoButtonA.h
include/Cevo/CevoButtonB.h
include/Cevo/CevoButtonBase.h
include/Cevo/CevoButtonC.h
include/Cevo/CevoButtonG.h
include/Cevo/CevoButtonN.h
include/Cevo/CevoDrawDlg.h
include/Cevo/CevoEOTButton.h
include/Cevo/CevoGraphicSet.h
include/Cevo/CevoListBoxEx.h
include/Cevo/CevoScreenTools.h
include/Cevo/CevoTexture.h
include/Cevo/CevoWidgets.h
)
set(CEVO_WIDGETS_SOURCES
src/CevoArea.cpp
src/CevoBaseWin.cpp
src/CevoButtonA.cpp
src/CevoButtonB.cpp
src/CevoButtonBase.cpp
src/CevoButtonC.cpp
src/CevoButtonG.cpp
src/CevoButtonN.cpp
src/CevoDrawDlg.cpp
src/CevoEOTButton.cpp
src/CevoGraphicSet.cpp
src/CevoListBoxEx.cpp
src/CevoScreenTools.cpp
src/CevoTexture.cpp
)
add_library(cevowidgets SHARED ${CEVO_WIDGETS_SOURCES} ${CEVO_WIDGETS_HEADERS})
target_include_directories(cevowidgets PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(cevowidgets PUBLIC dpiwidgets Qt${QT_VERSION_MAJOR}::Widgets)
set_target_properties(cevowidgets PROPERTIES
AUTOMOC ON
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
include(GNUInstallDirs)
install(TARGETS dpiwidgets cevowidgets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/cevo-evo
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/cevo-evo
)
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <QWidget>
namespace Cevo {
// TArea equivalent: a disabled placeholder widget marking a region (e.g. the
// map view) that a parent dialog's smart-invalidate logic should not paint
// chrome over. The original also drew a red design-time-only frame in the
// Lazarus form designer; that has no equivalent at runtime in a hand-written
// Qt app, so it is omitted here.
class Area : public QWidget {
Q_OBJECT
public:
explicit Area(QWidget *parent = nullptr);
};
} // namespace Cevo
+84
View File
@@ -0,0 +1,84 @@
#pragma once
#include "Cevo/CevoDrawDlg.h"
#include "Dpi/DpiGraphics.h"
#include <functional>
namespace Cevo {
enum class WindowMode { None, Modal, Persistent, Submodal };
WindowMode windowModeMakePersistent(WindowMode mode);
constexpr int NarrowFrame = 11;
constexpr int WideFrame = 36;
constexpr int SideFrame = 9;
void createOffscreen(Dpi::Bitmap &offscreen, int width, int height);
void clearOffscreen(Dpi::Bitmap &offscreen);
// TBufferedDrawDlg equivalent: double-buffers dialog content into an
// offscreen bitmap composited in paintEvent (VPaint), separating "content"
// repaints (OffscreenPaint, done by subclasses) from the chrome drawn by
// FramedDlg around it.
class BufferedDrawDlg : public DrawDlg {
Q_OBJECT
public:
explicit BufferedDrawDlg(QWidget *parent = nullptr);
WindowMode windowMode() const { return m_windowMode; }
void showNewContent(WindowMode newMode, bool forceClose = false);
void smartUpdateContent(bool immediateUpdate = false);
int userLeft = 0;
int userTop = 0;
int usedOffscreenWidth = 0;
int usedOffscreenHeight = 0;
Dpi::Bitmap offscreen;
// Hook for the F1/help key, mirrors the global ShowNewContentProc in
// BaseWin.pas.
static std::function<void(WindowMode, const QString &)> showNewContentHook;
protected:
WindowMode m_windowMode = WindowMode::None;
int modalFrameIndent = 45;
QString helpContext = QStringLiteral("CONCEPTS");
void markUsedOffscreen(int xMax, int yMax);
virtual void offscreenPaint();
virtual void vpaint(Dpi::Canvas &canvas);
void resizeEvent(QResizeEvent *event) override;
void paintEvent(QPaintEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
};
// TFramedDlg equivalent: the ornate beveled window chrome (title bar,
// corners, button frames) drawn around a BufferedDrawDlg's content.
class FramedDlg : public BufferedDrawDlg {
Q_OBJECT
public:
explicit FramedDlg(QWidget *parent = nullptr);
void smartInvalidate() override;
protected:
int captionLeft = 0;
int captionRight = 0xFFFF;
bool wideBottom = false;
bool fullCaption = true;
bool texOverride = false;
bool modalIndication = true;
int innerWidth = 0;
int innerHeight = 0;
void vpaint(Dpi::Canvas &canvas) override;
void fillOffscreen(int left, int top, int w, int h);
void resizeEvent(QResizeEvent *event) override;
// Clips the widget to a non-rectangular region when fullCaption is
// false (narrow title bar with visible corners of the content below).
void initWindowRegion();
};
} // namespace Cevo
+26
View File
@@ -0,0 +1,26 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
namespace Cevo {
// TButtonA equivalent: a 100x25 captioned button painted from the system
// sprite sheet.
class ButtonA : public ButtonBase {
Q_OBJECT
public:
explicit ButtonA(QWidget *parent = nullptr);
QString caption() const { return m_caption; }
void setCaption(const QString &text);
void setFont(const Dpi::Font &font);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
QString m_caption;
Dpi::Font m_font;
};
} // namespace Cevo
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
namespace Cevo {
// TButtonB equivalent: a 25x25 button whose sprite is cut out with a mask
// (SRCAND) and painted in (SRCPAINT) over the background, selected by
// ButtonIndex from a 12-columns-wide grid.
class ButtonB : public ButtonBase {
Q_OBJECT
public:
explicit ButtonB(QWidget *parent = nullptr);
Dpi::Bitmap *mask() const { return m_mask; }
void setMask(Dpi::Bitmap *value) { m_mask = value; }
int buttonIndex() const { return m_index; }
void setButtonIndex(int value);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
Dpi::Bitmap *m_mask = nullptr;
int m_index = -1;
Dpi::Bitmap m_buffer;
};
} // namespace Cevo
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QWidget>
#include <functional>
namespace Cevo {
// TButtonBase equivalent: a lightweight, sprite-painted push button with
// manual mouse tracking (no native QAbstractButton state machine), matching
// the original TGraphicControl-based design and its Down/Permanent model.
class ButtonBase : public QWidget {
Q_OBJECT
public:
explicit ButtonBase(QWidget *parent = nullptr);
bool down() const { return m_down; }
void setDown(bool value);
bool permanent() const { return m_permanent; }
void setPermanent(bool value) { m_permanent = value; }
Dpi::Bitmap *graphic() const { return m_graphic; }
void setGraphic(Dpi::Bitmap *value) { m_graphic = value; }
std::function<void()> onClick;
std::function<void()> onDownChanged;
protected:
virtual void paint(Dpi::Canvas &canvas) { Q_UNUSED(canvas); }
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
Dpi::Bitmap *m_graphic = nullptr;
bool m_down = false;
private:
void paintEvent(QPaintEvent *event) override final;
void trackMouse(const QPoint &pos, bool leftPressed);
void setDownState(bool value);
bool m_permanent = false;
bool m_active = false;
};
} // namespace Cevo
+24
View File
@@ -0,0 +1,24 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
namespace Cevo {
// TButtonC equivalent: a 12x12 icon button, selected by ButtonIndex from a
// single-column grid.
class ButtonC : public ButtonBase {
Q_OBJECT
public:
explicit ButtonC(QWidget *parent = nullptr);
int buttonIndex() const { return m_index; }
void setButtonIndex(int value);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
int m_index = 0;
};
} // namespace Cevo
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
#include "Cevo/CevoGraphicSet.h"
namespace Cevo {
// TButtonG equivalent: a button whose background and glyph are looked up by
// index or name in a GraphicSet (used for the city/government icon
// buttons), instead of fixed sprite-sheet coordinates.
class ButtonG : public ButtonBase {
Q_OBJECT
public:
explicit ButtonG(QWidget *parent = nullptr);
GraphicSet *graphicSet() const { return m_graphicSet; }
void setGraphicSet(GraphicSet *value) { m_graphicSet = value; }
int backgroundUpIndex() const { return m_backgroundUpIndex; }
void setBackgroundUpIndex(int value);
QString backgroundUpName() const { return m_backgroundUpName; }
void setBackgroundUpName(const QString &value);
int backgroundDownIndex() const { return m_backgroundDownIndex; }
void setBackgroundDownIndex(int value);
QString backgroundDownName() const { return m_backgroundDownName; }
void setBackgroundDownName(const QString &value);
int glyphIndex() const { return m_glyphIndex; }
void setGlyphIndex(int value);
QString glyphName() const { return m_glyphName; }
void setGlyphName(const QString &value);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
GraphicSetItem *resolveItem(int index, const QString &name) const;
GraphicSet *m_graphicSet = nullptr;
int m_backgroundUpIndex = -1;
QString m_backgroundUpName;
int m_backgroundDownIndex = -1;
QString m_backgroundDownName;
int m_glyphIndex = -1;
QString m_glyphName;
};
} // namespace Cevo
+52
View File
@@ -0,0 +1,52 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QWidget>
#include <functional>
namespace Cevo {
// TButtonN equivalent: a 42x42 unit-selection button with its own
// Possible/Lit toggle model (distinct from ButtonBase's Down/Permanent),
// so it is a standalone widget rather than a ButtonBase subclass.
class ButtonN : public QWidget {
Q_OBJECT
public:
explicit ButtonN(QWidget *parent = nullptr);
bool possible() const { return m_possible; }
void setPossible(bool value);
bool lit() const { return m_lit; }
void setLit(bool value);
int buttonIndex() const { return m_index; }
void setButtonIndex(int value);
QString smartHint() const { return m_smartHint; }
void setSmartHint(const QString &value);
Dpi::Bitmap *graphic() const { return m_graphic; }
void setGraphic(Dpi::Bitmap *value) { m_graphic = value; }
Dpi::Bitmap *mask() const { return m_mask; }
void setMask(Dpi::Bitmap *value) { m_mask = value; }
Dpi::Bitmap *backGraphic() const { return m_backGraphic; }
void setBackGraphic(Dpi::Bitmap *value) { m_backGraphic = value; }
std::function<void()> onClick;
protected:
void paintEvent(QPaintEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
private:
Dpi::Bitmap *m_graphic = nullptr;
Dpi::Bitmap *m_mask = nullptr;
Dpi::Bitmap *m_backGraphic = nullptr;
bool m_possible = true;
bool m_lit = false;
int m_index = -1;
int m_backIndex = 1;
QString m_smartHint;
Dpi::Bitmap m_buffer;
};
} // namespace Cevo
+59
View File
@@ -0,0 +1,59 @@
#pragma once
#include "Dpi/DpiForms.h"
#include <QPoint>
#include <QString>
namespace Cevo {
// TDrawDlg equivalent: a borderless, custom-painted dialog that can be
// dragged by its title area and closed with Escape.
class DrawDlg : public Dpi::Form {
Q_OBJECT
public:
explicit DrawDlg(QWidget *parent = nullptr);
virtual void smartInvalidate();
void centerToScreen();
void centerToScreen(int w, int h);
protected:
int titleHeight = 0; // area (from the top) that can be used to drag the window
void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void leaveEvent(QEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
private:
QPoint m_moveFormPos;
QPoint m_moveMousePos;
bool m_moveActive = false;
};
// TBaseMessgDlg equivalent: a simple word-wrapped message box drawn with the
// game's own frame/background style.
class BaseMessgDlg : public DrawDlg {
Q_OBJECT
public:
explicit BaseMessgDlg(QWidget *parent = nullptr);
QString messageText;
protected:
static constexpr int Border = 3;
static constexpr int MessageLineSpacing = 20;
int lines = 0;
int topSpace = 0;
void paintEvent(QPaintEvent *event) override;
// Pass preview=true to just measure how many lines the text needs
// (fills `lines`) without drawing anything.
void splitText(bool preview);
void correctHeight();
};
} // namespace Cevo
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include "Cevo/CevoButtonBase.h"
namespace Cevo {
enum {
eotBlinkOff = -1,
eotCancel = 0,
eotGray = 1,
eotBlinkOn = 2,
eotBackToNego = 3,
};
// TEOTButton equivalent: the End-Of-Turn button, animated by swapping
// ButtonIndex between the eot* states above.
class EOTButton : public ButtonBase {
Q_OBJECT
public:
explicit EOTButton(QWidget *parent = nullptr);
Dpi::Bitmap *tmpl() const { return m_template; }
void setTemplate(Dpi::Bitmap *value) { m_template = value; }
int buttonIndex() const { return m_index; }
void setButtonIndex(int value);
// Immediately repaints (bypassing the event queue) if the index changed,
// mirroring SetButtonIndexFast's use during time-critical animation.
void setButtonIndexFast(int value);
void setBack(Dpi::Canvas &canvas, int x, int y);
protected:
void paint(Dpi::Canvas &canvas) override;
private:
Dpi::Bitmap *m_template = nullptr;
int m_index = -1;
Dpi::Bitmap m_buffer;
Dpi::Bitmap m_back;
};
} // namespace Cevo
+60
View File
@@ -0,0 +1,60 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QList>
#include <QRect>
#include <QString>
namespace Cevo {
class GraphicSet;
// TGraphicSetItem equivalent: one named sub-rectangle of a GraphicSet's
// sprite sheet.
class GraphicSetItem {
public:
QString name;
int left = 0;
int top = 0;
int width = 0;
int height = 0;
GraphicSet *graphicSet = nullptr;
QRect boundsRect() const { return QRect(left, top, width, height); }
void setBoundsRect(const QRect &rect);
};
// TGraphicSet equivalent: a sprite sheet (data) with its transparency mask
// (mask), plus a set of named item rectangles. Persisted as XML, though not
// in the same node layout as the original (custom WriteString/WriteInteger
// helper), so files are not binary-compatible with the original .grs format.
class GraphicSet {
public:
GraphicSet() = default;
~GraphicSet();
GraphicSet(const GraphicSet &) = delete;
GraphicSet &operator=(const GraphicSet &) = delete;
QString name;
Dpi::Bitmap data;
Dpi::Bitmap mask;
// Looks up by index first, falling back to name; nullptr (with a
// warning) if neither resolves to an item.
GraphicSetItem *item(const QString &itemName) const;
GraphicSetItem *searchByName(const QString &itemName) const;
GraphicSetItem *addNew(const QString &itemName);
const QList<GraphicSetItem *> &items() const { return m_items; }
void loadFromFile(const QString &fileName);
void saveToFile(const QString &fileName) const;
private:
QList<GraphicSetItem *> m_items;
};
constexpr const char *GraphicSetFileRootNode = "GraphicSet";
constexpr const char *GraphicSetFileExt = ".grs";
} // namespace Cevo
+25
View File
@@ -0,0 +1,25 @@
#pragma once
#include "Dpi/DpiStdCtrls.h"
#include <QStyledItemDelegate>
namespace Cevo {
// Paints the C-evo orange-on-black / blue-selection list style, since Qt's
// QListWidget has no OnDrawItem-style callback like TCustomListBox.
class ListBoxExDelegate : public QStyledItemDelegate {
Q_OBJECT
public:
using QStyledItemDelegate::QStyledItemDelegate;
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
};
// TListBoxEx equivalent.
class ListBoxEx : public Dpi::ListBox {
Q_OBJECT
public:
explicit ListBoxEx(QWidget *parent = nullptr);
};
} // namespace Cevo
+95
View File
@@ -0,0 +1,95 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QColor>
#include <QPoint>
#include <QRect>
#include <QString>
#include <array>
namespace Cevo {
class Texture;
class GraphicSet;
class GraphicSetItem;
// Delphi/VCL TColor ints are packed as $00BBGGRR (red in the low byte, the
// reverse of Qt's QRgb/QColor byte order). Convert ported color literals
// (e.g. ButtonA's $0000FF placeholder color) with this helper rather than
// constructing QColor from the raw hex value directly.
QColor colorFromDelphi(int value);
enum class FontType { Normal, Small, Tiny, Caption, Button, Count };
// Fonts, the main background texture and the system sprite sheets are
// populated by the application's asset-loading step (ScreenTools.pas's
// UnitInit/LoadAssets in the original, not ported here); null/default until
// the application assigns them.
extern std::array<Dpi::Font, static_cast<size_t>(FontType::Count)> UniFont;
extern Texture *MainTexture;
extern GraphicSet *HGrSystem;
extern GraphicSet *HGrSystem2;
extern GraphicSet *Templates;
extern Dpi::Bitmap *Colors; // palette lookup bitmap, indexed by clkAge0/cli* below
// Colors palette row/column indices (Colors->image().pixelColor(col, row)).
constexpr int clkAge0 = 1;
constexpr int cliTexture = 0;
constexpr int cliBevelLight = 1;
constexpr int cliBevelShade = 2;
constexpr int cliTextLight = 3;
constexpr int cliTextShade = 4;
constexpr int cliLitText = 5;
constexpr int cliMark = 6;
constexpr int cliDimmedText = 7;
constexpr int cliRoad = 8;
constexpr int cliHouse = 9;
constexpr int cliImp = 10;
constexpr int cliImpProject = 11;
constexpr int cliPage = 13;
constexpr int cliCover = 14;
enum class RasterOp { Copy, And, Paint, Invert };
// Mirrors ScreenTools.pas's BitBltBitmap raster-op blit (classic AND-mask +
// OR-data sprite compositing) and UnshareBitmap (a no-op here: QImage is
// already copy-on-write safe, so there is no shared-handle cache to break).
void bitBltBitmap(Dpi::Bitmap &dest, int x, int y, int width, int height,
Dpi::Bitmap &src, int xSrc, int ySrc, RasterOp rop = RasterOp::Copy);
void unshareBitmap(Dpi::Bitmap &bitmap);
// Draws a masked sprite (AND then OR, via an internal scratch buffer since
// Qt's QPainter has no raster-op compositing against the live canvas).
void sprite(Dpi::Canvas &canvas, GraphicSet &graphicSet, int xDst, int yDst,
int width, int height, int xGr, int yGr);
void sprite(Dpi::Canvas &canvas, int xDst, int yDst, const GraphicSetItem &item);
void frame(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, QColor cl0, QColor cl1);
void rframe(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, QColor cl0, QColor cl1);
void btnFrame(Dpi::Canvas &canvas, const QRect &rect, const Texture &texture);
// Unimplemented in the original ScreenTools.pas too (body is commented out there).
void corner(Dpi::Canvas &canvas, int x, int y, int kind, const Texture &texture);
void fill(Dpi::Canvas &canvas, int left, int top, int width, int height, int xOffset = 0, int yOffset = 0);
void fill(Dpi::Canvas &canvas, const QRect &rect, const QPoint &offset = QPoint());
void paintBackground(Dpi::Canvas &canvas, int left, int top, int width, int height,
int formWidth = 0, int formHeight = 0);
void biColorTextOut(Dpi::Canvas &canvas, QColor mainColor, QColor backColor, int x, int y, const QString &text);
int biColorTextWidth(Dpi::Canvas &canvas, const QString &text);
void risedTextOut(Dpi::Canvas &canvas, int x, int y, const QString &text);
// cl == -2: mixed bevel colors; cl < 0: texture's text shade/light pair; cl >= 0: explicit color.
void loweredTextOut(Dpi::Canvas &canvas, int cl, const Texture &texture, int x, int y, const QString &text);
// Template-based color blending (Src is a greyscale "template" bitmap whose
// channels encode per-pixel blend amplitudes). color0/color1/color2 use the
// Delphi $BBGGRR byte order, like colorFromDelphi's input.
void imageOpB(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc, int width, int height);
void imageOpBCC(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
int width, int height, int color1, int color2);
void imageOpCBC(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
int width, int height, int color0, int color2);
void imageOpCCC(Dpi::Bitmap &bmp, int x, int y, int width, int height, int color0, int color1, int color2);
} // namespace Cevo
+44
View File
@@ -0,0 +1,44 @@
#pragma once
#include "Dpi/DpiGraphics.h"
#include <QColor>
namespace Cevo {
// TTexture equivalent: a tiled background bitmap plus the UI palette colors
// associated with a given "age" (the game's tech-era visual theme), looked
// up from the Colors palette bitmap.
class Texture {
public:
Texture();
int age() const { return m_age; }
// Updates the palette colors from Cevo::Colors; does not (re)load the
// per-age background image, that stays an application-level concern
// (Directories::getGraphicsDir() + image()->loadFromFile() is not
// ported here). Call image().loadFromFile() explicitly afterwards.
void setAge(int value);
int width() const { return m_image.width(); }
int height() const { return m_image.height(); }
Dpi::Bitmap &image() { return m_image; }
Dpi::Canvas &canvas() { return m_image.canvas(); }
void assign(const Texture &source);
QColor colorBevelLight = Qt::black;
QColor colorBevelShade = Qt::black;
QColor colorTextLight = Qt::black;
QColor colorTextShade = Qt::black;
QColor colorLitText = Qt::black;
QColor colorMark = Qt::black;
QColor colorPage = Qt::black;
QColor colorCover = Qt::black;
private:
int m_age = -2;
Dpi::Bitmap m_image;
};
} // namespace Cevo
+19
View File
@@ -0,0 +1,19 @@
#pragma once
// Convenience umbrella header mirroring CevoComponents.pas: pulls in every
// Cevo:: widget so application code can simply `#include <Cevo/CevoWidgets.h>`.
#include "Cevo/CevoArea.h"
#include "Cevo/CevoBaseWin.h"
#include "Cevo/CevoButtonA.h"
#include "Cevo/CevoButtonB.h"
#include "Cevo/CevoButtonBase.h"
#include "Cevo/CevoButtonC.h"
#include "Cevo/CevoButtonG.h"
#include "Cevo/CevoButtonN.h"
#include "Cevo/CevoDrawDlg.h"
#include "Cevo/CevoEOTButton.h"
#include "Cevo/CevoGraphicSet.h"
#include "Cevo/CevoListBoxEx.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"
+90
View File
@@ -0,0 +1,90 @@
#pragma once
#include <QSplitter>
#include <QTabWidget>
#include <QToolBar>
#include <QTreeWidget>
#include <functional>
namespace Dpi {
enum class ViewStyle { Icon, List, Report, SmallIcon };
// TListView equivalent, backed by QTreeWidget: root-level items act as rows
// and the header provides Columns; OnColumnClick maps to the header's
// sectionClicked signal.
class ListView : public QTreeWidget {
Q_OBJECT
public:
explicit ListView(QWidget *parent = nullptr);
ViewStyle viewStyle() const { return m_viewStyle; }
void setViewStyle(ViewStyle value);
bool checkboxes() const { return m_checkboxes; }
void setCheckboxes(bool value);
// Mirrors Dpi.ComCtrls.TDpiLVCustomDrawItemEvent.
std::function<void(QTreeWidgetItem *, bool &defaultDraw)> onCustomDrawItem;
signals:
void columnClicked(int column);
void selectionChanged();
private:
ViewStyle m_viewStyle = ViewStyle::Report;
bool m_checkboxes = false;
};
// TToolBar equivalent.
class ToolBar : public QToolBar {
Q_OBJECT
public:
explicit ToolBar(QWidget *parent = nullptr);
int buttonHeight() const;
void setButtonHeight(int value);
int buttonWidth() const;
void setButtonWidth(int value);
};
// TCoolBand equivalent: per-band size constraints applied to a child widget
// hosted in a CoolBar.
struct CoolBand {
QWidget *widget = nullptr;
int minWidth = 100;
int minHeight = 25;
};
// TCoolBar equivalent. Qt has no direct "rebar" control; a horizontal
// QSplitter with one segment per band gives the closest user-draggable,
// resizable band behavior.
class CoolBar : public QSplitter {
Q_OBJECT
public:
explicit CoolBar(QWidget *parent = nullptr);
void addBand(const CoolBand &band);
int bandCount() const { return count(); }
bool themed() const { return m_themed; }
void setThemed(bool value) { m_themed = value; }
void beginUpdate();
void endUpdate();
private:
bool m_themed = true;
};
// TPageControl equivalent.
class PageControl : public QTabWidget {
Q_OBJECT
public:
explicit PageControl(QWidget *parent = nullptr);
int pageCount() const { return count(); }
QWidget *page(int index) const { return widget(index); }
};
} // namespace Dpi
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include <QPoint>
#include <QRect>
#include <QSize>
#include <QString>
namespace Dpi {
// Mirrors the role of Dpi.Common.pas / its ScreenInfo record: conversion
// between the DPI-independent coordinate space used for widget geometry
// (Qt's logical / device-independent pixels) and the native physical pixel
// space used by raw pixel buffers (QImage scanlines, screen grabs, etc.).
// Qt widgets already scale logical pixels to the physical display
// automatically, so these helpers are only needed where code must address
// physical pixels directly (e.g. custom raster rendering).
class ScreenInfo {
public:
// Effective DPI of the primary screen (96 == 100% scaling), kept for API
// parity with the Pascal ScreenInfo.Dpi property.
static int dpi();
// Multiplier from DPI-independent to native/physical pixels.
static double toNative();
// Multiplier from native/physical to DPI-independent pixels.
static double fromNative();
};
int scaleToNative(int value);
int scaleFromNative(int value);
int scaleToNativeDist(int base, int value);
QPoint scalePointToNative(const QPoint &value);
QPoint scalePointFromNative(const QPoint &value);
QSize scaleSizeToNative(const QSize &value);
QSize scaleSizeFromNative(const QSize &value);
QRect scaleRectToNative(const QRect &value);
QRect scaleRectFromNative(const QRect &value);
double scaleFloatToNative(double value);
double scaleFloatFromNative(double value);
void writeLog(const QString &text);
} // namespace Dpi
+47
View File
@@ -0,0 +1,47 @@
#pragma once
#include <QIcon>
#include <QList>
#include <QPoint>
#include <Qt>
namespace Dpi {
// Type aliases kept for parity with Dpi.Controls.pas; Qt's own enums already
// cover these concepts so no custom type is introduced for them.
using Align = Qt::Alignment;
enum class BorderStyle {
None,
Single,
};
// TImageList equivalent: a simple named collection of icons at a given size.
class ImageList {
public:
explicit ImageList(int width = 16, int height = 16) : m_width(width), m_height(height) {}
int width() const { return m_width; }
void setWidth(int value) { m_width = value; }
int height() const { return m_height; }
void setHeight(int value) { m_height = value; }
int count() const { return m_icons.count(); }
int add(const QIcon &icon);
QIcon icon(int index) const;
void clear() { m_icons.clear(); }
private:
int m_width;
int m_height;
QList<QIcon> m_icons;
};
// TMouse equivalent.
class Mouse {
public:
static QPoint cursorPos();
static void setCursorPos(const QPoint &value);
};
} // namespace Dpi
+56
View File
@@ -0,0 +1,56 @@
#pragma once
#include <QFrame>
#include <QLabel>
#include <QPixmap>
#include <QTimer>
#include <QWidget>
#include <functional>
namespace Dpi {
class Canvas;
// TTimer equivalent: QTimer already matches the VCL API closely.
using Timer = QTimer;
// TPanel equivalent.
class Panel : public QFrame {
Q_OBJECT
public:
explicit Panel(QWidget *parent = nullptr);
};
// TPaintBox equivalent: a plain widget exposing an OnPaint callback bound to
// a Dpi::Canvas, since custom drawing in Qt happens through QPainter in
// paintEvent rather than through a persistent handle-based canvas.
class PaintBox : public QWidget {
Q_OBJECT
public:
explicit PaintBox(QWidget *parent = nullptr);
std::function<void(Canvas &)> onPaint;
protected:
void paintEvent(QPaintEvent *event) override;
};
// TImage equivalent.
class Image : public QLabel {
Q_OBJECT
public:
explicit Image(QWidget *parent = nullptr);
bool stretch() const { return m_stretch; }
void setStretch(bool value);
void setPicture(const QPixmap &pixmap);
private:
void updatePixmap();
bool m_stretch = false;
QPixmap m_source;
};
} // namespace Dpi
+106
View File
@@ -0,0 +1,106 @@
#pragma once
#include <QRect>
#include <QString>
#include <QWidget>
#include <functional>
class QCloseEvent;
class QShowEvent;
class QHideEvent;
class QEventLoop;
class QScreen;
namespace Dpi {
// Modal result constants equivalent (mrNone, mrOk, mrCancel, ...).
enum class ModalResult {
None,
Ok,
Cancel,
Abort,
Retry,
Ignore,
Yes,
No,
All,
NoToAll,
YesToAll,
Close,
};
// TForm equivalent. Subclass this the same way game windows subclassed
// Dpi.Forms.TForm; ShowModal()/close handling mirror the VCL/LCL semantics.
class Form : public QWidget {
Q_OBJECT
public:
explicit Form(QWidget *parent = nullptr);
~Form() override;
ModalResult showModal();
ModalResult modalResult() const { return m_modalResult; }
void setModalResult(ModalResult value) { m_modalResult = value; }
// TNotifyEvent / TCloseEvent equivalents.
std::function<void()> onShow;
std::function<void()> onHide;
std::function<void()> onActivate;
std::function<void()> onDeactivate;
std::function<bool()> onCloseQuery; // return false to veto the close
std::function<void()> onClose;
protected:
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
void closeEvent(QCloseEvent *event) override;
bool event(QEvent *event) override;
private:
ModalResult m_modalResult = ModalResult::None;
QEventLoop *m_modalLoop = nullptr;
};
// TApplication equivalent: thin facade over QApplication.
class Application {
public:
static void run();
static void processMessages();
static void terminate();
static Form *mainForm() { return s_mainForm; }
static void setMainForm(Form *form) { s_mainForm = form; }
static QString title();
static void setTitle(const QString &value);
static QString exeName();
private:
static Form *s_mainForm;
};
// TMonitor equivalent.
class Monitor {
public:
explicit Monitor(QScreen *screen) : m_screen(screen) {}
int left() const;
int top() const;
int width() const;
int height() const;
QRect boundsRect() const;
private:
QScreen *m_screen;
};
// TScreen equivalent: thin facade over QGuiApplication screen state.
class Screen {
public:
static int formCount();
static Form *activeForm();
static int dpi();
static int pixelsPerInch();
static int width();
static int height();
static QRect desktopRect();
static Monitor primaryMonitor();
};
} // namespace Dpi
+204
View File
@@ -0,0 +1,204 @@
#pragma once
#include <QBrush>
#include <QColor>
#include <QFont>
#include <QImage>
#include <QPaintDevice>
#include <QPainter>
#include <QPen>
#include <QPolygon>
#include <QSize>
#include <QString>
#include <functional>
namespace Dpi {
// TFont equivalent. Qt already renders fonts DPI-correctly, so sizes here are
// plain point sizes with no extra scaling applied.
class Font {
public:
Font();
QString name() const;
void setName(const QString &value);
bool bold() const;
void setBold(bool value);
bool italic() const;
void setItalic(bool value);
bool underline() const;
void setUnderline(bool value);
int size() const;
void setSize(int value);
int height() const;
void setHeight(int value);
QColor color() const;
void setColor(const QColor &value);
QSize getTextSize(const QString &text) const;
int getTextWidth(const QString &text) const;
int getTextHeight(const QString &text) const;
void assign(const Font &source);
QFont toQFont() const { return m_font; }
// TNotifyEvent equivalent.
std::function<void()> onChange;
private:
void changed();
QFont m_font;
QColor m_color;
};
// TPen equivalent.
class Pen {
public:
Pen();
QColor color() const { return m_color; }
void setColor(const QColor &value) { m_color = value; }
Qt::PenStyle style() const { return m_style; }
void setStyle(Qt::PenStyle value) { m_style = value; }
int width() const { return m_width; }
void setWidth(int value) { m_width = value; }
void assign(const Pen &source);
QPen toQPen() const;
private:
QColor m_color;
Qt::PenStyle m_style;
int m_width;
};
// TBrush equivalent.
class Brush {
public:
Brush();
QColor color() const { return m_color; }
void setColor(const QColor &value) { m_color = value; }
Qt::BrushStyle style() const { return m_style; }
void setStyle(Qt::BrushStyle value) { m_style = value; }
void assign(const Brush &source);
QBrush toQBrush() const;
private:
QColor m_color;
Qt::BrushStyle m_style;
};
// TCanvas equivalent, bound to a QPaintDevice (widget, pixmap or image).
// Unlike VCL/LCL, Qt only allows painting through a QPainter that is either
// explicitly begin()/end()-ed (for off-screen devices such as QImage) or
// handed to us already active from within a paintEvent (see bind()).
class Canvas {
public:
Canvas();
explicit Canvas(QPaintDevice *device);
~Canvas();
void setDevice(QPaintDevice *device);
QPaintDevice *device() const { return m_device; }
void begin();
void end();
bool active() const { return m_painter != nullptr; }
// Use an already-active, externally owned painter (typically supplied by
// QWidget::paintEvent). The canvas does not take ownership of it.
void bind(QPainter *painter);
void unbind();
Pen &pen() { return m_pen; }
Brush &brush() { return m_brush; }
Font &font() { return m_font; }
int width() const;
int height() const;
QColor pixel(int x, int y) const;
void setPixel(int x, int y, const QColor &color);
void moveTo(int x, int y);
void lineTo(int x, int y);
void line(int x1, int y1, int x2, int y2);
void rectangle(int x1, int y1, int x2, int y2);
void ellipse(int x1, int y1, int x2, int y2);
void roundRect(int x1, int y1, int x2, int y2, int rx, int ry);
void polygon(const QPolygon &points);
void polyline(const QPolygon &points);
void textOut(int x, int y, const QString &text);
int textWidth(const QString &text) const;
int textHeight(const QString &text) const;
QSize textExtent(const QString &text) const;
void fillRect(const QRect &rect);
void frameRect(const QRect &rect);
void draw(int x, int y, const QImage &image);
void stretchDraw(const QRect &rect, const QImage &image);
void copyRect(const QRect &dest, Canvas &source, const QRect &sourceRect);
private:
QPainter *painter();
void applyPenBrush();
QPaintDevice *m_device = nullptr;
QPainter *m_painter = nullptr;
bool m_ownsPainter = false;
QPoint m_penPos;
Pen m_pen;
Brush m_brush;
Font m_font;
};
// TBitmap equivalent, backed by a QImage in ARGB32 format for transparency
// support.
class Bitmap {
public:
Bitmap();
Bitmap(int width, int height);
void setSize(int width, int height);
int width() const { return m_image.width(); }
int height() const { return m_image.height(); }
QImage &image() { return m_image; }
const QImage &image() const { return m_image; }
Canvas &canvas() { return m_canvas; }
bool transparent() const { return m_transparent; }
void setTransparent(bool value) { m_transparent = value; }
QColor transparentColor() const { return m_transparentColor; }
void setTransparentColor(const QColor &value);
void loadFromFile(const QString &fileName);
void saveToFile(const QString &fileName) const;
void assign(const Bitmap &source);
private:
QImage m_image;
Canvas m_canvas;
bool m_transparent = false;
QColor m_transparentColor;
};
// TPicture equivalent: a simple container that owns a Bitmap.
class Picture {
public:
Bitmap &bitmap() { return m_bitmap; }
const Bitmap &bitmap() const { return m_bitmap; }
void loadFromFile(const QString &fileName);
private:
Bitmap m_bitmap;
};
} // namespace Dpi
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <QTableWidget>
namespace Dpi {
// TStringGrid equivalent.
class StringGrid : public QTableWidget {
Q_OBJECT
public:
explicit StringGrid(QWidget *parent = nullptr);
QString cell(int col, int row) const;
void setCell(int col, int row, const QString &value);
int fixedRows() const { return m_fixedRows; }
void setFixedRows(int value);
int fixedCols() const { return m_fixedCols; }
void setFixedCols(int value) { m_fixedCols = value; }
QRect cellRect(int col, int row) const;
private:
int m_fixedRows = 0;
int m_fixedCols = 0;
};
} // namespace Dpi
+96
View File
@@ -0,0 +1,96 @@
#pragma once
#include <QAction>
#include <QKeySequence>
#include <QList>
#include <QMenu>
#include <QMenuBar>
#include <QObject>
#include <QPoint>
#include <functional>
namespace Dpi {
// TMenuItem equivalent: wraps a QAction and, lazily, a QMenu used to host
// child items when the item acts as a submenu.
class MenuItem : public QObject {
Q_OBJECT
public:
explicit MenuItem(const QString &caption = QString(), QObject *parent = nullptr);
// Wraps an existing QMenu (e.g. one returned by QMenuBar::addMenu). When
// ownsMenu is true, this item deletes the menu on destruction.
explicit MenuItem(QMenu *existingMenu, bool ownsMenu = false, QObject *parent = nullptr);
// Root item for a QMenuBar: add() creates top-level bar menus.
explicit MenuItem(QMenuBar *bar, QObject *parent = nullptr);
~MenuItem() override;
QAction *action() const { return m_action; }
QMenu *submenu();
QString caption() const { return m_action ? m_action->text() : QString(); }
void setCaption(const QString &value) { if (m_action) m_action->setText(value); }
bool enabled() const { return m_action ? m_action->isEnabled() : true; }
void setEnabled(bool value) { if (m_action) m_action->setEnabled(value); }
bool visible() const { return m_action ? m_action->isVisible() : true; }
void setVisible(bool value) { if (m_action) m_action->setVisible(value); }
bool checked() const { return m_action && m_action->isChecked(); }
void setChecked(bool value) { if (m_action) m_action->setChecked(value); }
bool radioItem() const { return m_radioItem; }
void setRadioItem(bool value);
int groupIndex() const { return m_groupIndex; }
void setGroupIndex(int value) { m_groupIndex = value; }
QKeySequence shortCut() const { return m_action ? m_action->shortcut() : QKeySequence(); }
void setShortCut(const QKeySequence &value) { if (m_action) m_action->setShortcut(value); }
MenuItem *add(const QString &caption);
void insert(int index, MenuItem *item);
void remove(MenuItem *item);
void deleteItem(int index);
void clear();
int indexOf(MenuItem *item) const { return m_items.indexOf(item); }
int count() const { return m_items.count(); }
MenuItem *items(int index) const { return m_items.value(index); }
void click();
// TNotifyEvent equivalent.
std::function<void()> onClick;
private:
QAction *m_action = nullptr;
QMenu *m_submenu = nullptr;
QMenuBar *m_bar = nullptr;
bool m_ownsSubmenu = false;
QList<MenuItem *> m_items;
bool m_radioItem = false;
int m_groupIndex = 0;
};
// TMenu equivalent (a window's main menu bar).
class Menu {
public:
explicit Menu(QMenuBar *bar) : m_root(new MenuItem(bar)) {}
~Menu() { delete m_root; }
MenuItem &items() { return *m_root; }
private:
MenuItem *m_root;
};
// TPopupMenu equivalent.
class PopupMenu : public MenuItem {
Q_OBJECT
public:
explicit PopupMenu(QObject *parent = nullptr);
bool autoPopup() const { return m_autoPopup; }
void setAutoPopup(bool value) { m_autoPopup = value; }
void popup(const QPoint &pos);
private:
bool m_autoPopup = true;
};
QKeySequence shortCut(int key, Qt::KeyboardModifiers modifiers);
} // namespace Dpi
+40
View File
@@ -0,0 +1,40 @@
#pragma once
#include <QImage>
namespace Dpi {
// Mirrors Dpi.PixelPointer.pas / NativePixelPointer.pas: a cursor for fast
// pixel-by-pixel iteration over a 32-bit ARGB QImage, addressing native
// (physical) pixels directly. The image must use QImage::Format_ARGB32 (or
// Format_ARGB32_Premultiplied) for the scanline arithmetic below to be valid.
class PixelPointer {
public:
PixelPointer() = default;
PixelPointer(QImage *image, int baseX, int baseY);
void setXY(int x, int y);
void setX(int x);
void nextPixel();
void previousPixel();
void nextLine();
void previousLine();
bool posValid() const;
QRgb pixelARGB() const;
void setPixelARGB(QRgb value);
QRgb pixelRGB() const; // alpha forced to 0xFF
void setPixelRGB(QRgb value);
int x() const { return m_x; }
int y() const { return m_y; }
private:
QImage *m_image = nullptr;
int m_x = 0;
int m_y = 0;
int m_width = 0;
int m_height = 0;
};
} // namespace Dpi
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <QSpinBox>
namespace Dpi {
// TDpiSpinEdit equivalent.
class SpinEdit : public QSpinBox {
Q_OBJECT
public:
using QSpinBox::QSpinBox;
};
} // namespace Dpi
+77
View File
@@ -0,0 +1,77 @@
#pragma once
#include <QCheckBox>
#include <QComboBox>
#include <QLineEdit>
#include <QListWidget>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QRadioButton>
#include <QScrollBar>
#include <QStringList>
namespace Dpi {
// TEdit equivalent.
class Edit : public QLineEdit {
Q_OBJECT
public:
using QLineEdit::QLineEdit;
};
// TMemo equivalent; adds a TStrings-like Lines accessor over QPlainTextEdit.
class Memo : public QPlainTextEdit {
Q_OBJECT
public:
using QPlainTextEdit::QPlainTextEdit;
QStringList lines() const;
void setLines(const QStringList &value);
};
// TComboBox equivalent.
class ComboBox : public QComboBox {
Q_OBJECT
public:
using QComboBox::QComboBox;
};
// TCheckBox equivalent.
class CheckBox : public QCheckBox {
Q_OBJECT
public:
using QCheckBox::QCheckBox;
};
// TRadioButton equivalent.
class RadioButton : public QRadioButton {
Q_OBJECT
public:
using QRadioButton::QRadioButton;
};
// TButton equivalent.
class Button : public QPushButton {
Q_OBJECT
public:
using QPushButton::QPushButton;
};
// TListBox equivalent.
class ListBox : public QListWidget {
Q_OBJECT
public:
using QListWidget::QListWidget;
QStringList items() const;
void setItems(const QStringList &value);
};
// TScrollBar equivalent.
class ScrollBar : public QScrollBar {
Q_OBJECT
public:
using QScrollBar::QScrollBar;
};
} // namespace Dpi
+18
View File
@@ -0,0 +1,18 @@
#pragma once
// Convenience umbrella header mirroring the DpiControls.lpk package: pulls in
// every Dpi:: widget/graphics wrapper so application code can simply
// `#include <Dpi/DpiWidgets.h>`, the same way Pascal units did `uses
// DpiControls, Dpi.StdCtrls, ...`.
#include "Dpi/DpiCommon.h"
#include "Dpi/DpiComCtrls.h"
#include "Dpi/DpiControls.h"
#include "Dpi/DpiExtCtrls.h"
#include "Dpi/DpiForms.h"
#include "Dpi/DpiGraphics.h"
#include "Dpi/DpiGrids.h"
#include "Dpi/DpiMenus.h"
#include "Dpi/DpiPixelPointer.h"
#include "Dpi/DpiSpin.h"
#include "Dpi/DpiStdCtrls.h"
+10
View File
@@ -0,0 +1,10 @@
#include "Cevo/CevoArea.h"
namespace Cevo {
Area::Area(QWidget *parent) : QWidget(parent)
{
setEnabled(false);
}
} // namespace Cevo
+258
View File
@@ -0,0 +1,258 @@
#include "Cevo/CevoBaseWin.h"
#include "Cevo/CevoArea.h"
#include "Cevo/CevoButtonBase.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"
#include <QKeyEvent>
#include <QPainter>
#include <QRegion>
#include <algorithm>
namespace Cevo {
std::function<void(WindowMode, const QString &)> BufferedDrawDlg::showNewContentHook;
WindowMode windowModeMakePersistent(WindowMode mode)
{
return mode == WindowMode::Modal ? WindowMode::Submodal : WindowMode::Persistent;
}
void createOffscreen(Dpi::Bitmap &offscreen, int width, int height)
{
if (offscreen.width() != width || offscreen.height() != height) {
offscreen.setSize(width, height);
clearOffscreen(offscreen);
}
}
void clearOffscreen(Dpi::Bitmap &offscreen)
{
Dpi::Canvas &canvas = offscreen.canvas();
canvas.begin();
canvas.brush().setColor(Qt::black);
canvas.fillRect(QRect(0, 0, offscreen.width(), offscreen.height()));
canvas.end();
}
BufferedDrawDlg::BufferedDrawDlg(QWidget *parent) : DrawDlg(parent)
{
createOffscreen(offscreen, width(), height());
const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor();
userLeft = monitor.left() + (monitor.width() - width()) / 2;
userTop = monitor.top() + (monitor.height() - height()) / 2;
titleHeight = WideFrame;
}
void BufferedDrawDlg::markUsedOffscreen(int xMax, int yMax)
{
usedOffscreenWidth = std::max(usedOffscreenWidth, xMax);
usedOffscreenHeight = std::max(usedOffscreenHeight, yMax);
}
void BufferedDrawDlg::offscreenPaint()
{
createOffscreen(offscreen, width(), height());
}
void BufferedDrawDlg::vpaint(Dpi::Canvas &canvas)
{
canvas.draw(0, 0, offscreen.image());
}
void BufferedDrawDlg::paintEvent(QPaintEvent *)
{
offscreenPaint();
QPainter painter(this);
Dpi::Canvas canvas;
canvas.bind(&painter);
vpaint(canvas);
canvas.unbind();
}
void BufferedDrawDlg::resizeEvent(QResizeEvent *event)
{
DrawDlg::resizeEvent(event);
smartUpdateContent();
}
void BufferedDrawDlg::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_F1) {
if (showNewContentHook)
showNewContentHook(windowModeMakePersistent(m_windowMode), helpContext);
} else {
DrawDlg::keyPressEvent(event);
}
}
void BufferedDrawDlg::showNewContent(WindowMode newMode, bool forceClose)
{
if (isVisible()) {
if (newMode == WindowMode::Modal && (forceClose || m_windowMode != WindowMode::Modal)) {
userLeft = x();
userTop = y();
setVisible(false);
m_windowMode = newMode;
showModal();
} else if (forceClose) {
setVisible(false);
m_windowMode = newMode;
move(userLeft, userTop);
show();
} else {
m_windowMode = newMode;
if (onShow)
onShow();
update();
raise();
}
} else {
m_windowMode = newMode;
move(userLeft, userTop);
if (m_windowMode == WindowMode::Modal)
showModal();
else
show();
}
}
void BufferedDrawDlg::smartUpdateContent(bool immediateUpdate)
{
if (isVisible()) {
offscreenPaint();
smartInvalidate();
if (immediateUpdate)
repaint();
}
}
// ---- FramedDlg ----
FramedDlg::FramedDlg(QWidget *parent) : BufferedDrawDlg(parent)
{
innerWidth = width() - 2 * SideFrame;
innerHeight = height() - titleHeight - NarrowFrame;
}
void FramedDlg::smartInvalidate()
{
const int bottomFrame = wideBottom ? WideFrame : NarrowFrame;
QRegion region(QRect(SideFrame, titleHeight, width() - 2 * SideFrame, height() - titleHeight - bottomFrame));
const auto children = findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly);
for (QWidget *child : children) {
if (!qobject_cast<Area *>(child) && child->isVisible())
region -= QRegion(child->geometry());
}
update(region);
}
void FramedDlg::resizeEvent(QResizeEvent *event)
{
BufferedDrawDlg::resizeEvent(event);
innerWidth = width() - 2 * SideFrame;
innerHeight = height() - titleHeight - NarrowFrame;
}
void FramedDlg::fillOffscreen(int left, int top, int w, int h)
{
fill(offscreen.canvas(), left, top, w, h, SideFrame, titleHeight);
}
void FramedDlg::initWindowRegion()
{
if (fullCaption)
return;
QRegion region(rect());
region -= QRegion(QRect(0, 0, captionLeft, titleHeight - NarrowFrame));
region -= QRegion(QRect(width() - captionLeft, 0, captionLeft, titleHeight - NarrowFrame));
if (wideBottom) {
region -= QRegion(QRect(0, height() - (WideFrame - NarrowFrame), captionLeft, WideFrame - NarrowFrame));
region -= QRegion(QRect(width() - captionLeft, height() - (WideFrame - NarrowFrame), captionLeft,
WideFrame - NarrowFrame));
}
setMask(region);
}
void FramedDlg::vpaint(Dpi::Canvas &canvas)
{
if (!MainTexture)
return;
auto cornerFrame = [&](int x0, int y0, int x1, int y1) {
frame(canvas, x0 + 1, y0 + 1, x1 - 2, y1 - 2, MainTexture->colorBevelLight, MainTexture->colorBevelShade);
frame(canvas, x0 + 2, y0 + 2, x1 - 3, y1 - 3, MainTexture->colorBevelLight, MainTexture->colorBevelShade);
corner(canvas, x0 + 1, y0 + 1, 0, *MainTexture);
corner(canvas, x1 - 9, y0 + 1, 1, *MainTexture);
corner(canvas, x0 + 1, y1 - 9, 2, *MainTexture);
corner(canvas, x1 - 9, y1 - 9, 3, *MainTexture);
};
canvas.font().assign(UniFont[static_cast<size_t>(FontType::Caption)]);
const int l = biColorTextWidth(canvas, windowTitle());
const int cut = (width() - l) / 2;
const int innerBottom = wideBottom ? height() - WideFrame : height() - NarrowFrame;
int frameTop, frameBottom;
if (fullCaption) {
frameTop = 0;
frameBottom = height();
} else {
frameTop = titleHeight - NarrowFrame;
frameBottom = wideBottom ? height() - (WideFrame - NarrowFrame) : height();
}
fill(canvas, 3, innerBottom + 1, width() - 6, height() - innerBottom - 4, 0, 0);
fill(canvas, 3, titleHeight - 2, SideFrame - 3, innerBottom - titleHeight + 4, 0, 0);
fill(canvas, width() - SideFrame, titleHeight - 2, SideFrame - 3, innerBottom - titleHeight + 4, 0, 0);
frame(canvas, 0, frameTop, width() - 1, frameBottom - 1, Qt::black, Qt::black);
frame(canvas, SideFrame - 1, titleHeight - 1, width() - SideFrame, innerBottom,
MainTexture->colorBevelShade, MainTexture->colorBevelLight);
// The original also draws an inset divider around the centered caption
// text when FWindowMode = wmModal and ModalIndication is set; omitted
// here as a purely cosmetic simplification (same Frame()/moveTo/lineTo
// pattern used elsewhere in this function could reproduce it).
if (fullCaption) {
fill(canvas, 3, 3 + frameTop, width() - 6, titleHeight - frameTop - 4, 0, 0);
cornerFrame(0, frameTop, width(), frameBottom);
} else {
fill(canvas, 3, 3 + frameTop, width() - 6, titleHeight - frameTop - 4, 0, 0);
cornerFrame(0, frameTop, width(), frameBottom);
frame(canvas, captionLeft, 0, width() - captionLeft - 1, frameTop, Qt::black, Qt::black);
fill(canvas, captionLeft + 3, 3, width() - 2 * captionLeft - 6, titleHeight - 4, 0, 0);
frame(canvas, captionLeft + 1, 1, width() - captionLeft - 2, titleHeight - 1,
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
frame(canvas, captionLeft + 2, 2, width() - captionLeft - 3, titleHeight - 1,
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
corner(canvas, captionLeft + 1, 1, 0, *MainTexture);
corner(canvas, width() - captionLeft - 9, 1, 1, *MainTexture);
if (wideBottom) {
frame(canvas, captionLeft, frameBottom, width() - captionLeft - 1, height() - 1, Qt::black, Qt::black);
fill(canvas, captionLeft + 3, height() - 3 - (WideFrame - 5), width() - 2 * captionLeft - 6,
WideFrame - 5, 0, 0);
frame(canvas, captionLeft + 1, height() - WideFrame, width() - captionLeft - 2, height() - 2,
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
corner(canvas, captionLeft + 1, height() - 9, 2, *MainTexture);
corner(canvas, width() - captionLeft - 9, height() - 9, 3, *MainTexture);
}
}
risedTextOut(canvas, cut - 1, 7, windowTitle());
const auto children = findChildren<ButtonBase *>(QString(), Qt::FindDirectChildrenOnly);
for (ButtonBase *button : children) {
if (button->isVisible()) {
const QRect r = button->geometry();
if (r.bottom() <= titleHeight || r.top() >= innerBottom)
btnFrame(canvas, r, *MainTexture);
}
}
canvas.copyRect(QRect(SideFrame, titleHeight, width() - 2 * SideFrame, innerBottom - titleHeight),
offscreen.canvas(), QRect(0, 0, width() - 2 * SideFrame, innerBottom - titleHeight));
}
} // namespace Cevo
+40
View File
@@ -0,0 +1,40 @@
#include "Cevo/CevoButtonA.h"
#include "Cevo/CevoScreenTools.h"
namespace Cevo {
ButtonA::ButtonA(QWidget *parent) : ButtonBase(parent)
{
resize(100, 25);
}
void ButtonA::paint(Dpi::Canvas &canvas)
{
if (m_graphic) {
canvas.copyRect(QRect(0, 0, 100, 25), m_graphic->canvas(),
QRect(195, 243 + 26 * (down() ? 1 : 0), 100, 25));
canvas.font().assign(m_font);
canvas.font().setColor(Qt::black);
const QSize textSize = canvas.textExtent(m_caption);
canvas.textOut(50 - (textSize.width() + 1) / 2, 12 - textSize.height() / 2, m_caption);
} else {
canvas.brush().setColor(colorFromDelphi(0x0000FF));
canvas.frameRect(QRect(0, 0, 100, 25));
}
}
void ButtonA::setCaption(const QString &text)
{
if (text != m_caption) {
m_caption = text;
update();
}
}
void ButtonA::setFont(const Dpi::Font &font)
{
m_font.assign(font);
m_font.setColor(Qt::black);
}
} // namespace Cevo
+37
View File
@@ -0,0 +1,37 @@
#include "Cevo/CevoButtonB.h"
#include "Cevo/CevoScreenTools.h"
namespace Cevo {
ButtonB::ButtonB(QWidget *parent) : ButtonBase(parent), m_buffer(25, 25)
{
resize(25, 25);
}
void ButtonB::paint(Dpi::Canvas &canvas)
{
if (m_graphic) {
unshareBitmap(m_buffer);
bitBltBitmap(m_buffer, 0, 0, width(), height(), *m_graphic, 169, 243 + 26 * (down() ? 1 : 0));
if (m_index >= 0 && m_mask) {
bitBltBitmap(m_buffer, 0, 0, width(), height(), *m_mask,
1 + m_index % 12 * 26, 337 + m_index / 12 * 26, RasterOp::And);
bitBltBitmap(m_buffer, 0, 0, width(), height(), *m_graphic,
1 + m_index % 12 * 26, 337 + m_index / 12 * 26, RasterOp::Paint);
}
canvas.draw(0, 0, m_buffer.image());
} else {
canvas.brush().setColor(colorFromDelphi(0x0000FF));
canvas.frameRect(QRect(0, 0, width(), height()));
}
}
void ButtonB::setButtonIndex(int value)
{
if (value != m_index) {
m_index = value;
update();
}
}
} // namespace Cevo
+76
View File
@@ -0,0 +1,76 @@
#include "Cevo/CevoButtonBase.h"
#include <QMouseEvent>
#include <QPainter>
namespace Cevo {
ButtonBase::ButtonBase(QWidget *parent) : QWidget(parent) {}
void ButtonBase::setDown(bool value)
{
m_down = value;
update();
}
void ButtonBase::setDownState(bool value)
{
if (m_down == value)
return;
m_down = value;
update();
if (onDownChanged)
onDownChanged();
}
void ButtonBase::trackMouse(const QPoint &pos, bool leftPressed)
{
if (!m_active)
return;
if (rect().contains(pos)) {
if (leftPressed && !m_down)
setDownState(true);
} else if (m_down && !m_permanent) {
setDownState(false);
}
}
void ButtonBase::mousePressEvent(QMouseEvent *event)
{
m_active = true;
trackMouse(event->pos(), event->buttons() & Qt::LeftButton);
}
void ButtonBase::mouseMoveEvent(QMouseEvent *event)
{
trackMouse(event->pos(), event->buttons() & Qt::LeftButton);
}
void ButtonBase::mouseReleaseEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton)
return; // another button was released while left is still held
trackMouse(event->pos(), false);
if (m_active && m_down) {
m_active = false;
if (m_down != m_permanent)
setDownState(m_permanent);
if (event->button() == Qt::LeftButton && onClick)
onClick();
} else {
m_active = false;
if (m_down)
setDownState(false);
}
}
void ButtonBase::paintEvent(QPaintEvent *)
{
QPainter painter(this);
Dpi::Canvas canvas;
canvas.bind(&painter);
paint(canvas);
canvas.unbind();
}
} // namespace Cevo
+30
View File
@@ -0,0 +1,30 @@
#include "Cevo/CevoButtonC.h"
#include "Cevo/CevoScreenTools.h"
namespace Cevo {
ButtonC::ButtonC(QWidget *parent) : ButtonBase(parent)
{
resize(12, 12);
}
void ButtonC::paint(Dpi::Canvas &canvas)
{
if (m_graphic) {
canvas.copyRect(QRect(0, 0, 12, 12), m_graphic->canvas(),
QRect(169 + 13 * (down() ? 1 : 0), 159 + 13 * m_index, 12, 12));
} else {
canvas.brush().setColor(colorFromDelphi(0x0000FF));
canvas.frameRect(QRect(0, 0, 12, 12));
}
}
void ButtonC::setButtonIndex(int value)
{
if (value != m_index) {
m_index = value;
update();
}
}
} // namespace Cevo
+101
View File
@@ -0,0 +1,101 @@
#include "Cevo/CevoButtonG.h"
#include "Cevo/CevoScreenTools.h"
namespace Cevo {
ButtonG::ButtonG(QWidget *parent) : ButtonBase(parent) {}
GraphicSetItem *ButtonG::resolveItem(int index, const QString &name) const
{
if (!m_graphicSet)
return nullptr;
if (index != -1 && index < m_graphicSet->items().count())
return m_graphicSet->items().at(index);
if (!name.isEmpty())
return m_graphicSet->searchByName(name);
return nullptr;
}
void ButtonG::paint(Dpi::Canvas &canvas)
{
bool drawn = false;
Dpi::Bitmap buffer(width(), height());
if (m_graphicSet) {
GraphicSetItem *back = down() ? resolveItem(m_backgroundDownIndex, m_backgroundDownName)
: resolveItem(m_backgroundUpIndex, m_backgroundUpName);
if (back) {
bitBltBitmap(buffer, 0, 0, back->width, back->height, m_graphicSet->data, back->left, back->top);
drawn = true;
}
GraphicSetItem *glyph = resolveItem(m_glyphIndex, m_glyphName);
if (glyph) {
bitBltBitmap(buffer, 0, 0, glyph->width, glyph->height, m_graphicSet->mask,
glyph->left, glyph->top, RasterOp::And);
bitBltBitmap(buffer, 0, 0, glyph->width, glyph->height, m_graphicSet->data,
glyph->left, glyph->top, RasterOp::Paint);
drawn = true;
}
}
if (drawn) {
canvas.draw(0, 0, buffer.image());
} else {
canvas.brush().setColor(colorFromDelphi(0x0000FF));
canvas.frameRect(QRect(0, 0, width() - 1, height() - 1));
}
}
void ButtonG::setBackgroundUpIndex(int value)
{
if (m_backgroundUpIndex == value)
return;
m_backgroundUpIndex = value;
m_backgroundUpName.clear();
update();
}
void ButtonG::setBackgroundUpName(const QString &value)
{
if (m_backgroundUpName == value)
return;
m_backgroundUpName = value;
m_backgroundUpIndex = -1;
update();
}
void ButtonG::setBackgroundDownIndex(int value)
{
if (m_backgroundDownIndex == value)
return;
m_backgroundDownIndex = value;
m_backgroundDownName.clear();
update();
}
void ButtonG::setBackgroundDownName(const QString &value)
{
if (m_backgroundDownName == value)
return;
m_backgroundDownName = value;
m_backgroundDownIndex = -1;
update();
}
void ButtonG::setGlyphIndex(int value)
{
if (m_glyphIndex == value)
return;
m_glyphIndex = value;
m_glyphName.clear();
update();
}
void ButtonG::setGlyphName(const QString &value)
{
if (m_glyphName == value)
return;
m_glyphName = value;
m_glyphIndex = -1;
update();
}
} // namespace Cevo
+78
View File
@@ -0,0 +1,78 @@
#include "Cevo/CevoButtonN.h"
#include "Cevo/CevoScreenTools.h"
#include <QMouseEvent>
#include <QPainter>
namespace Cevo {
ButtonN::ButtonN(QWidget *parent) : QWidget(parent), m_buffer(42, 42)
{
setToolTip(QString());
resize(42, 42);
}
void ButtonN::paintEvent(QPaintEvent *)
{
QPainter painter(this);
Dpi::Canvas canvas;
canvas.bind(&painter);
if (m_graphic && m_backGraphic) {
bitBltBitmap(m_buffer, 1, 1, 40, 40, *m_backGraphic,
1 + 80 * m_backIndex + 40 * (m_possible && m_lit ? 1 : 0), 176);
if (m_possible && m_mask) {
bitBltBitmap(m_buffer, 3, 3, 36, 36, *m_mask,
195 + 37 * (m_index % 3), 21 + 37 * (m_index / 3), RasterOp::And);
bitBltBitmap(m_buffer, 3, 3, 36, 36, *m_graphic,
195 + 37 * (m_index % 3), 21 + 37 * (m_index / 3), RasterOp::Paint);
}
canvas.draw(0, 0, m_buffer.image());
}
frame(canvas, 0, 0, 41, 41, colorFromDelphi(0xB0B0B0), colorFromDelphi(0xFFFFFF));
canvas.unbind();
}
void ButtonN::mousePressEvent(QMouseEvent *event)
{
if (m_possible && event->button() == Qt::LeftButton && onClick)
onClick();
}
void ButtonN::setPossible(bool value)
{
if (value == m_possible)
return;
m_possible = value;
setToolTip(value ? m_smartHint : QString());
update();
}
void ButtonN::setLit(bool value)
{
if (value == m_lit)
return;
m_lit = value;
update();
}
void ButtonN::setButtonIndex(int value)
{
if (value == m_index)
return;
m_index = value;
m_backIndex = value < 6 ? 1 : 0;
update();
}
void ButtonN::setSmartHint(const QString &value)
{
if (value == m_smartHint)
return;
m_smartHint = value;
if (m_possible)
setToolTip(value);
}
} // namespace Cevo
+168
View File
@@ -0,0 +1,168 @@
#include "Cevo/CevoDrawDlg.h"
#include "Cevo/CevoArea.h"
#include "Cevo/CevoButtonBase.h"
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoTexture.h"
#include <QKeyEvent>
#include <QMouseEvent>
#include <QPainter>
#include <QRegion>
namespace Cevo {
DrawDlg::DrawDlg(QWidget *parent) : Dpi::Form(parent)
{
QPalette pal = palette();
pal.setColor(QPalette::Window, Qt::black);
setPalette(pal);
setAutoFillBackground(true);
}
void DrawDlg::mousePressEvent(QMouseEvent *event)
{
const QPoint pos = event->pos();
if (rect().contains(pos) && pos.y() < titleHeight) {
m_moveMousePos = mapToGlobal(event->pos());
m_moveFormPos = QPoint(x(), y());
m_moveActive = true;
} else {
m_moveActive = false;
}
}
void DrawDlg::mouseMoveEvent(QMouseEvent *event)
{
if (m_moveActive) {
const QPoint delta = mapToGlobal(event->pos()) - m_moveMousePos;
move(m_moveFormPos + delta);
}
}
void DrawDlg::mouseReleaseEvent(QMouseEvent *)
{
m_moveActive = false;
}
void DrawDlg::leaveEvent(QEvent *)
{
m_moveActive = false;
}
void DrawDlg::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Escape)
close();
else
QWidget::keyPressEvent(event);
}
void DrawDlg::smartInvalidate()
{
QRegion region(rect());
const auto children = findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly);
for (QWidget *child : children) {
if (!qobject_cast<Area *>(child) && child->isVisible())
region -= QRegion(child->geometry());
}
update(region);
}
void DrawDlg::centerToScreen()
{
centerToScreen(width(), height());
}
void DrawDlg::centerToScreen(int w, int h)
{
const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor();
setGeometry(monitor.left() + (monitor.width() - w) / 2,
monitor.top() + (monitor.height() - h) / 2, w, h);
}
// ---- BaseMessgDlg ----
BaseMessgDlg::BaseMessgDlg(QWidget *parent) : DrawDlg(parent)
{
titleHeight = Dpi::Screen::height();
}
void BaseMessgDlg::paintEvent(QPaintEvent *)
{
QPainter painter(this);
Dpi::Canvas canvas;
canvas.bind(&painter);
paintBackground(canvas, 3 + Border, 3 + Border, width() - (6 + 2 * Border), height() - (6 + 2 * Border),
width(), height());
for (int i = 0; i <= Border; ++i)
frame(canvas, i, i, width() - 1 - i, height() - 1 - i, Qt::black, Qt::black);
if (MainTexture) {
frame(canvas, Border + 1, Border + 1, width() - (2 + Border), height() - (2 + Border),
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
frame(canvas, 2 + Border, 2 + Border, width() - (3 + Border), height() - (3 + Border),
MainTexture->colorBevelLight, MainTexture->colorBevelShade);
}
splitText(false);
if (MainTexture) {
const auto children = findChildren<ButtonBase *>(QString(), Qt::FindDirectChildrenOnly);
for (ButtonBase *button : children) {
if (button->isVisible())
btnFrame(canvas, button->geometry(), *MainTexture);
}
}
canvas.unbind();
}
void BaseMessgDlg::splitText(bool preview)
{
// Best-effort port of the 1-indexed Pascal word-wrap logic below; wraps
// messageText at word boundaries (or '\' line breaks) to fit within
// (width() - 56) px per line.
if (!MainTexture)
return;
int start = 0;
int linesCount = 0;
QPixmap dummy(1, 1);
QPainter painter(&dummy);
Dpi::Canvas canvas;
canvas.bind(&painter);
while (start < messageText.length()) {
int stop = start;
while (stop < messageText.length() - 1 && messageText.at(stop) != QLatin1Char('\\') &&
biColorTextWidth(canvas, messageText.mid(start, stop - start + 1)) < width() - 56)
++stop;
if (stop != messageText.length() - 1) {
int ordinaryStop = stop;
while (ordinaryStop > start && messageText.at(ordinaryStop) != QLatin1Char(' ') &&
messageText.at(ordinaryStop) != QLatin1Char('\\'))
--ordinaryStop;
if ((ordinaryStop - start) * 2 >= stop - start)
stop = ordinaryStop - 1;
}
if (!preview) {
const QString s = messageText.mid(start, stop - start + 1);
loweredTextOut(canvas, -1, *MainTexture, (width() - biColorTextWidth(canvas, s)) / 2,
19 + Border + topSpace + linesCount * MessageLineSpacing, s);
}
start = stop + 2;
++linesCount;
}
canvas.unbind();
if (preview)
lines = linesCount;
}
void BaseMessgDlg::correctHeight()
{
const int newHeight = 72 + Border + topSpace + lines * MessageLineSpacing;
const Dpi::Monitor monitor = Dpi::Screen::primaryMonitor();
const int newTop = monitor.top() + (monitor.height() - newHeight) / 2;
setGeometry(x(), newTop, width(), newHeight);
const auto children = findChildren<QWidget *>(QString(), Qt::FindDirectChildrenOnly);
for (QWidget *child : children)
child->move(child->x(), newHeight - (34 + Border));
}
} // namespace Cevo
+48
View File
@@ -0,0 +1,48 @@
#include "Cevo/CevoEOTButton.h"
#include "Cevo/CevoScreenTools.h"
namespace Cevo {
EOTButton::EOTButton(QWidget *parent) : ButtonBase(parent), m_buffer(48, 48), m_back(48, 48)
{
resize(48, 48);
}
void EOTButton::paint(Dpi::Canvas &canvas)
{
if (m_graphic && m_template) {
unshareBitmap(m_buffer);
bitBltBitmap(m_buffer, 0, 0, 48, 48, m_back, 0, 0);
imageOpCBC(m_buffer, *m_template, 0, 0, 133, 149 + 48 * (down() ? 1 : 0), 48, 48, 0x000000, 0xFFFFFF);
if (m_index >= 0) {
imageOpCBC(m_buffer, *m_template, 8, 8, 1 + 32 * m_index, 246, 32, 32, 0x000000, 0xFFFFFF);
}
canvas.draw(0, 0, m_buffer.image());
} else {
canvas.brush().setColor(colorFromDelphi(0x0000FF));
canvas.frameRect(QRect(0, 0, 48, 48));
}
}
void EOTButton::setButtonIndex(int value)
{
if (value != m_index) {
m_index = value;
update();
}
}
void EOTButton::setButtonIndexFast(int value)
{
if (isVisible() && value != m_index) {
m_index = value;
repaint();
}
}
void EOTButton::setBack(Dpi::Canvas &canvas, int x, int y)
{
m_back.canvas().copyRect(QRect(0, 0, 48, 48), canvas, QRect(x, y, 48, 48));
}
} // namespace Cevo
+97
View File
@@ -0,0 +1,97 @@
#include "Cevo/CevoGraphicSet.h"
#include <QFile>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QtDebug>
namespace Cevo {
void GraphicSetItem::setBoundsRect(const QRect &rect)
{
left = rect.left();
top = rect.top();
width = rect.width();
height = rect.height();
}
GraphicSet::~GraphicSet()
{
qDeleteAll(m_items);
}
GraphicSetItem *GraphicSet::searchByName(const QString &itemName) const
{
for (GraphicSetItem *item : m_items) {
if (item->name == itemName)
return item;
}
return nullptr;
}
GraphicSetItem *GraphicSet::item(const QString &itemName) const
{
GraphicSetItem *found = searchByName(itemName);
if (!found)
qWarning("Graphic item %s not found in graphic set %s.", qUtf8Printable(itemName), qUtf8Printable(name));
return found;
}
GraphicSetItem *GraphicSet::addNew(const QString &itemName)
{
auto *newItem = new GraphicSetItem();
newItem->name = itemName;
newItem->graphicSet = this;
m_items.append(newItem);
return newItem;
}
void GraphicSet::loadFromFile(const QString &fileName)
{
qDeleteAll(m_items);
m_items.clear();
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
return;
QXmlStreamReader xml(&file);
while (!xml.atEnd()) {
xml.readNext();
if (xml.isStartElement() && xml.name() == QLatin1String("Item")) {
const QXmlStreamAttributes attrs = xml.attributes();
GraphicSetItem *newItem = addNew(attrs.value("Name").toString());
newItem->left = attrs.value("Left").toInt();
newItem->top = attrs.value("Top").toInt();
newItem->width = attrs.value("Width").toInt();
newItem->height = attrs.value("Height").toInt();
}
}
}
void GraphicSet::saveToFile(const QString &fileName) const
{
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
return;
QXmlStreamWriter xml(&file);
xml.setAutoFormatting(true);
xml.writeStartDocument();
xml.writeStartElement(QLatin1String(GraphicSetFileRootNode));
xml.writeStartElement(QLatin1String("Items"));
for (GraphicSetItem *item : m_items) {
xml.writeStartElement(QLatin1String("Item"));
xml.writeAttribute(QLatin1String("Name"), item->name);
xml.writeAttribute(QLatin1String("Left"), QString::number(item->left));
xml.writeAttribute(QLatin1String("Top"), QString::number(item->top));
xml.writeAttribute(QLatin1String("Width"), QString::number(item->width));
xml.writeAttribute(QLatin1String("Height"), QString::number(item->height));
xml.writeEndElement();
}
xml.writeEndElement();
xml.writeEndElement();
xml.writeEndDocument();
}
} // namespace Cevo
+34
View File
@@ -0,0 +1,34 @@
#include "Cevo/CevoListBoxEx.h"
#include "Cevo/CevoScreenTools.h"
#include <QPainter>
namespace Cevo {
void ListBoxExDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
const QColor orange = colorFromDelphi(0x5F77CB);
const QColor blue = colorFromDelphi(0xd77800);
const bool selected = option.state & QStyle::State_Selected;
const QColor background = selected ? blue : Qt::black;
const QColor textColor = selected ? Qt::white : orange;
painter->fillRect(option.rect, Qt::black);
const QRect inner = option.rect.adjusted(2, 1, -2, -2);
painter->fillRect(inner, background);
painter->setPen(textColor);
painter->setFont(option.font);
painter->drawText(inner, Qt::AlignVCenter | Qt::AlignLeft, index.data(Qt::DisplayRole).toString());
if (selected) {
painter->setPen(QPen(orange, 1, Qt::DotLine));
painter->setBrush(Qt::NoBrush);
painter->drawRect(inner);
}
}
ListBoxEx::ListBoxEx(QWidget *parent) : Dpi::ListBox(parent)
{
setItemDelegate(new ListBoxExDelegate(this));
}
} // namespace Cevo
+330
View File
@@ -0,0 +1,330 @@
#include "Cevo/CevoScreenTools.h"
#include "Cevo/CevoGraphicSet.h"
#include "Cevo/CevoTexture.h"
#include "Dpi/DpiPixelPointer.h"
#include <algorithm>
namespace Cevo {
std::array<Dpi::Font, static_cast<size_t>(FontType::Count)> UniFont;
Texture *MainTexture = nullptr;
GraphicSet *HGrSystem = nullptr;
GraphicSet *HGrSystem2 = nullptr;
GraphicSet *Templates = nullptr;
Dpi::Bitmap *Colors = nullptr;
QColor colorFromDelphi(int value)
{
return QColor(value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF);
}
void bitBltBitmap(Dpi::Bitmap &dest, int x, int y, int width, int height,
Dpi::Bitmap &src, int xSrc, int ySrc, RasterOp rop)
{
if (xSrc < 0) { x -= xSrc; width -= xSrc; xSrc = 0; }
if (ySrc < 0) { y -= ySrc; height -= ySrc; ySrc = 0; }
if (x < 0) { width += x; xSrc -= x; x = 0; }
if (y < 0) { height += y; ySrc -= y; y = 0; }
if (x + width > dest.width()) width = dest.width() - x;
if (y + height > dest.height()) height = dest.height() - y;
if (width < 0 || height < 0)
return;
Dpi::PixelPointer srcPixel(&src.image(), xSrc, ySrc);
Dpi::PixelPointer dstPixel(&dest.image(), x, y);
for (int yy = 0; yy < height; ++yy) {
for (int xx = 0; xx < width; ++xx) {
switch (rop) {
case RasterOp::Copy:
dstPixel.setPixelRGB(srcPixel.pixelRGB());
break;
case RasterOp::And:
dstPixel.setPixelRGB(dstPixel.pixelRGB() & srcPixel.pixelRGB());
break;
case RasterOp::Paint:
dstPixel.setPixelRGB(dstPixel.pixelRGB() | srcPixel.pixelRGB());
break;
case RasterOp::Invert:
dstPixel.setPixelRGB(~dstPixel.pixelRGB());
break;
}
dstPixel.nextPixel();
srcPixel.nextPixel();
}
dstPixel.nextLine();
srcPixel.nextLine();
}
}
void unshareBitmap(Dpi::Bitmap &) {}
void sprite(Dpi::Canvas &canvas, GraphicSet &graphicSet, int xDst, int yDst,
int width, int height, int xGr, int yGr)
{
Dpi::Bitmap scratch(width, height);
bitBltBitmap(scratch, 0, 0, width, height, graphicSet.mask, xGr, yGr, RasterOp::And);
bitBltBitmap(scratch, 0, 0, width, height, graphicSet.data, xGr, yGr, RasterOp::Paint);
canvas.draw(xDst, yDst, scratch.image());
}
void sprite(Dpi::Canvas &canvas, int xDst, int yDst, const GraphicSetItem &item)
{
if (!item.graphicSet)
return;
sprite(canvas, *item.graphicSet, xDst, yDst, item.width, item.height, item.left, item.top);
}
void frame(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, QColor cl0, QColor cl1)
{
canvas.moveTo(x0, y1);
canvas.pen().setColor(cl0);
canvas.lineTo(x0, y0);
canvas.lineTo(x1, y0);
canvas.pen().setColor(cl1);
canvas.lineTo(x1, y1);
canvas.lineTo(x0, y1);
}
void rframe(Dpi::Canvas &canvas, int x0, int y0, int x1, int y1, QColor cl0, QColor cl1)
{
canvas.pen().setColor(cl0);
canvas.moveTo(x0, y0 + 1);
canvas.lineTo(x0, y1);
canvas.moveTo(x0 + 1, y0);
canvas.lineTo(x1, y0);
canvas.pen().setColor(cl1);
canvas.moveTo(x1, y0 + 1);
canvas.lineTo(x1, y1);
canvas.moveTo(x0 + 1, y1);
canvas.lineTo(x1, y1);
}
void btnFrame(Dpi::Canvas &canvas, const QRect &rect, const Texture &texture)
{
rframe(canvas, rect.left() - 1, rect.top() - 1, rect.right(), rect.bottom(),
texture.colorBevelShade, texture.colorBevelLight);
}
void corner(Dpi::Canvas &, int, int, int, const Texture &)
{
// Unimplemented in the original ScreenTools.pas too (body is commented out there).
}
void fill(Dpi::Canvas &canvas, int left, int top, int width, int height, int xOffset, int yOffset)
{
Q_UNUSED(xOffset);
Q_UNUSED(yOffset);
if (!MainTexture || MainTexture->width() <= 0 || MainTexture->height() <= 0)
return;
const int w = std::min(width, MainTexture->width());
const int h = std::min(height, MainTexture->height());
const int yy = height / MainTexture->height();
const int xx = width / MainTexture->width();
for (int y = 0; y <= yy; ++y) {
for (int x = 0; x <= xx; ++x) {
canvas.copyRect(QRect(left + x * MainTexture->width(), top + y * MainTexture->height(), w, h),
MainTexture->canvas(), QRect(0, 0, w, h));
}
}
}
void fill(Dpi::Canvas &canvas, const QRect &rect, const QPoint &offset)
{
fill(canvas, rect.left(), rect.top(), rect.width(), rect.height(), offset.x(), offset.y());
}
void paintBackground(Dpi::Canvas &canvas, int left, int top, int width, int height, int formWidth, int formHeight)
{
Q_UNUSED(formWidth);
Q_UNUSED(formHeight);
fill(canvas, left, top, width, height, 0, 0);
}
namespace {
// %c=combat %f=food %l=luxury %m=manufacture %n=nation %o=output
// %p=production %r=research %t=terrain %w=welfare, each a 10px-wide icon.
const QString kIconChars = QStringLiteral("cflmnoprtw");
const int kIconKinds[] = { 6, 0, 8, 17, 7, 16, 2, 12, 4, 13 };
void paintIcon(Dpi::Canvas &canvas, int x, int y, int kind)
{
if (!HGrSystem)
return;
sprite(canvas, *HGrSystem, x, y + 6, 10, 10, 66 + kind % 11 * 11, 115 + kind / 11 * 11);
}
} // namespace
void biColorTextOut(Dpi::Canvas &canvas, QColor mainColor, QColor backColor, int x, int y, const QString &text)
{
const bool skipShadow = backColor == QColor(0x7F, 0x00, 0x7F);
for (int pass = 0; pass < 2; ++pass) {
const bool shadow = pass == 0;
if (shadow && skipShadow)
continue;
const int drawX = shadow ? x + 1 : x;
const int drawY = shadow ? y + 1 : y;
canvas.font().setColor(shadow ? backColor : mainColor);
QString s = text;
int xp = drawX;
for (;;) {
const int p = s.indexOf(QLatin1Char('%'));
const bool hasIcon = p >= 0 && p + 1 < s.length() && kIconChars.contains(s.at(p + 1));
if (!hasIcon) {
canvas.textOut(xp, drawY, s);
break;
}
const QString head = s.left(p);
canvas.textOut(xp, drawY, head);
xp += canvas.textWidth(head);
if (!shadow)
paintIcon(canvas, xp + 1, drawY, kIconKinds[kIconChars.indexOf(s.at(p + 1))]);
xp += 10;
s.remove(0, p + 2);
}
}
}
int biColorTextWidth(Dpi::Canvas &canvas, const QString &text)
{
int result = 1;
QString s = text;
for (;;) {
const int p = s.indexOf(QLatin1Char('%'));
if (p < 0 || p == s.length() - 1) {
result += canvas.textWidth(s);
break;
}
if (!kIconChars.contains(s.at(p + 1)))
result += canvas.textWidth(s.left(p + 2));
else
result += canvas.textWidth(s.left(p)) + 10;
s.remove(0, p + 2);
}
return result;
}
void risedTextOut(Dpi::Canvas &canvas, int x, int y, const QString &text)
{
biColorTextOut(canvas, Qt::white, Qt::black, x, y, text);
}
void loweredTextOut(Dpi::Canvas &canvas, int cl, const Texture &texture, int x, int y, const QString &text)
{
if (cl == -2) {
const QColor shade = texture.colorBevelShade;
const QColor mixedShade(shade.red() / 2, shade.green() / 2, shade.blue() / 2);
biColorTextOut(canvas, mixedShade, texture.colorBevelLight, x, y, text);
} else if (cl < 0) {
biColorTextOut(canvas, texture.colorTextShade, texture.colorTextLight, x, y, text);
} else {
biColorTextOut(canvas, colorFromDelphi(cl), texture.colorTextLight, x, y, text);
}
}
void imageOpB(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc, int width, int height)
{
if (xDst < 0) { width += xDst; xSrc -= xDst; xDst = 0; }
if (yDst < 0) { height += yDst; ySrc -= yDst; yDst = 0; }
if (xDst + width > dst.width()) width = dst.width() - xDst;
if (yDst + height > dst.height()) height = dst.height() - yDst;
if (width < 0 || height < 0)
return;
Dpi::PixelPointer srcPixel(&src.image(), xSrc, ySrc);
Dpi::PixelPointer dstPixel(&dst.image(), xDst, yDst);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
const int brightness = qBlue(srcPixel.pixelARGB()); // greyscale template, one byte
const QRgb d = dstPixel.pixelARGB();
auto scale = [brightness](int c) { const int v = (c * brightness) >> 7; return v > 255 ? 255 : v; };
dstPixel.setPixelARGB(qRgb(scale(qRed(d)), scale(qGreen(d)), scale(qBlue(d))));
dstPixel.nextPixel();
srcPixel.nextPixel();
}
dstPixel.nextLine();
srcPixel.nextLine();
}
}
namespace {
// Shared by ImageOp_BCC/ImageOp_CBC: Src is a template whose B channel is
// the background blend amplitude and whose G/R channels are the amplitudes
// for colorA/colorB respectively. colorA/colorB use the Delphi $BBGGRR byte
// order (see colorFromDelphi).
void blendTemplate(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
int width, int height, int colorA, int colorB)
{
if (xDst < 0) { width += xDst; xSrc -= xDst; xDst = 0; }
if (yDst < 0) { height += yDst; ySrc -= yDst; yDst = 0; }
if (xDst + width > dst.width()) width = dst.width() - xDst;
if (yDst + height > dst.height()) height = dst.height() - yDst;
if (width < 0 || height < 0)
return;
Dpi::PixelPointer srcPixel(&src.image(), xSrc, ySrc);
Dpi::PixelPointer dstPixel(&dst.image(), xDst, yDst);
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
const QRgb s = srcPixel.pixelARGB();
const int trans = qBlue(s) * 2;
const int ampA = qGreen(s) * 2;
const int ampB = qRed(s) * 2;
if (trans != 0xFF) {
const QRgb d = dstPixel.pixelARGB();
auto mix = [&](int dstChannel, int shift) {
const int value = (dstChannel * trans + ((colorB >> shift) & 0xFF) * ampB +
((colorA >> shift) & 0xFF) * ampA) / 0xFF;
return value > 255 ? 255 : value;
};
dstPixel.setPixelARGB(qRgb(mix(qRed(d), 0), mix(qGreen(d), 8), mix(qBlue(d), 16)));
}
dstPixel.nextPixel();
srcPixel.nextPixel();
}
dstPixel.nextLine();
srcPixel.nextLine();
}
}
} // namespace
void imageOpBCC(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
int width, int height, int color1, int color2)
{
blendTemplate(dst, src, xDst, yDst, xSrc, ySrc, width, height, color1, color2);
}
void imageOpCBC(Dpi::Bitmap &dst, Dpi::Bitmap &src, int xDst, int yDst, int xSrc, int ySrc,
int width, int height, int color0, int color2)
{
blendTemplate(dst, src, xDst, yDst, xSrc, ySrc, width, height, color0, color2);
}
void imageOpCCC(Dpi::Bitmap &bmp, int x, int y, int width, int height, int color0, int color1, int color2)
{
if (x + width > bmp.width()) width = bmp.width() - x;
if (y + height > bmp.height()) height = bmp.height() - y;
if (width < 0 || height < 0)
return;
Dpi::PixelPointer pixel(&bmp.image(), x, y);
for (int yy = 0; yy < height; ++yy) {
for (int xx = 0; xx < width; ++xx) {
const QRgb p = pixel.pixelARGB();
const int b = qBlue(p), g = qGreen(p), r = qRed(p);
auto mix = [&](int shift) {
return ((b * ((color0 >> shift) & 0xFF) + g * ((color1 >> shift) & 0xFF) +
r * ((color2 >> shift) & 0xFF)) >> 8) & 0xFF;
};
pixel.setPixelARGB(qRgb(mix(0), mix(8), mix(16)));
pixel.nextPixel();
}
pixel.nextLine();
}
}
} // namespace Cevo
+40
View File
@@ -0,0 +1,40 @@
#include "Cevo/CevoTexture.h"
#include "Cevo/CevoScreenTools.h"
namespace Cevo {
Texture::Texture() : m_image(1, 1) {}
void Texture::setAge(int value)
{
if (m_age == value)
return;
m_age = value;
if (!Colors)
return;
QImage &palette = Colors->image();
colorBevelLight = palette.pixelColor(clkAge0 + m_age, cliBevelLight);
colorBevelShade = palette.pixelColor(clkAge0 + m_age, cliBevelShade);
colorTextLight = palette.pixelColor(clkAge0 + m_age, cliTextLight);
colorTextShade = palette.pixelColor(clkAge0 + m_age, cliTextShade);
colorLitText = palette.pixelColor(clkAge0 + m_age, cliLitText);
colorMark = palette.pixelColor(clkAge0 + m_age, cliMark);
colorPage = palette.pixelColor(clkAge0 + m_age, cliPage);
colorCover = palette.pixelColor(clkAge0 + m_age, cliCover);
}
void Texture::assign(const Texture &source)
{
m_age = source.m_age;
m_image.assign(source.m_image);
colorBevelLight = source.colorBevelLight;
colorBevelShade = source.colorBevelShade;
colorTextLight = source.colorTextLight;
colorTextShade = source.colorTextShade;
colorLitText = source.colorLitText;
colorMark = source.colorMark;
colorPage = source.colorPage;
colorCover = source.colorCover;
}
} // namespace Cevo
+65
View File
@@ -0,0 +1,65 @@
#include "Dpi/DpiComCtrls.h"
#include <QHeaderView>
namespace Dpi {
ListView::ListView(QWidget *parent) : QTreeWidget(parent)
{
setRootIsDecorated(false);
connect(header(), &QHeaderView::sectionClicked, this, &ListView::columnClicked);
connect(this, &QTreeWidget::itemSelectionChanged, this, &ListView::selectionChanged);
}
void ListView::setViewStyle(ViewStyle value)
{
m_viewStyle = value;
switch (value) {
case ViewStyle::Report:
setHeaderHidden(false);
setIndentation(0);
break;
case ViewStyle::List:
case ViewStyle::SmallIcon:
case ViewStyle::Icon:
setHeaderHidden(true);
break;
}
}
void ListView::setCheckboxes(bool value)
{
m_checkboxes = value;
for (int i = 0; i < topLevelItemCount(); ++i) {
QTreeWidgetItem *it = topLevelItem(i);
it->setFlags(value ? (it->flags() | Qt::ItemIsUserCheckable)
: (it->flags() & ~Qt::ItemIsUserCheckable));
}
}
ToolBar::ToolBar(QWidget *parent) : QToolBar(parent) {}
int ToolBar::buttonHeight() const { return iconSize().height(); }
void ToolBar::setButtonHeight(int value) { setIconSize(QSize(iconSize().width(), value)); }
int ToolBar::buttonWidth() const { return iconSize().width(); }
void ToolBar::setButtonWidth(int value) { setIconSize(QSize(value, iconSize().height())); }
CoolBar::CoolBar(QWidget *parent) : QSplitter(Qt::Horizontal, parent)
{
setChildrenCollapsible(false);
}
void CoolBar::addBand(const CoolBand &band)
{
if (!band.widget)
return;
band.widget->setMinimumSize(band.minWidth, band.minHeight);
addWidget(band.widget);
}
void CoolBar::beginUpdate() { setUpdatesEnabled(false); }
void CoolBar::endUpdate() { setUpdatesEnabled(true); }
PageControl::PageControl(QWidget *parent) : QTabWidget(parent) {}
} // namespace Dpi
+87
View File
@@ -0,0 +1,87 @@
#include "Dpi/DpiCommon.h"
#include <QDebug>
#include <QGuiApplication>
#include <QScreen>
#include <QtMath>
namespace Dpi {
int ScreenInfo::dpi()
{
return qRound(96.0 * toNative());
}
double ScreenInfo::toNative()
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen ? screen->devicePixelRatio() : 1.0;
}
double ScreenInfo::fromNative()
{
const double ratio = toNative();
return ratio != 0.0 ? 1.0 / ratio : 1.0;
}
int scaleToNative(int value)
{
return qRound(value * ScreenInfo::toNative());
}
int scaleFromNative(int value)
{
return qRound(value * ScreenInfo::fromNative());
}
int scaleToNativeDist(int base, int value)
{
return scaleToNative(base + value) - scaleToNative(base);
}
QPoint scalePointToNative(const QPoint &value)
{
return QPoint(scaleToNative(value.x()), scaleToNative(value.y()));
}
QPoint scalePointFromNative(const QPoint &value)
{
return QPoint(scaleFromNative(value.x()), scaleFromNative(value.y()));
}
QSize scaleSizeToNative(const QSize &value)
{
return QSize(scaleToNative(value.width()), scaleToNative(value.height()));
}
QSize scaleSizeFromNative(const QSize &value)
{
return QSize(scaleFromNative(value.width()), scaleFromNative(value.height()));
}
QRect scaleRectToNative(const QRect &value)
{
return QRect(scalePointToNative(value.topLeft()), scaleSizeToNative(value.size()));
}
QRect scaleRectFromNative(const QRect &value)
{
return QRect(scalePointFromNative(value.topLeft()), scaleSizeFromNative(value.size()));
}
double scaleFloatToNative(double value)
{
return value * ScreenInfo::toNative();
}
double scaleFloatFromNative(double value)
{
return value * ScreenInfo::fromNative();
}
void writeLog(const QString &text)
{
qDebug().noquote() << text;
}
} // namespace Dpi
+21
View File
@@ -0,0 +1,21 @@
#include "Dpi/DpiControls.h"
#include <QCursor>
namespace Dpi {
int ImageList::add(const QIcon &icon)
{
m_icons.append(icon);
return m_icons.count() - 1;
}
QIcon ImageList::icon(int index) const
{
return m_icons.value(index);
}
QPoint Mouse::cursorPos() { return QCursor::pos(); }
void Mouse::setCursorPos(const QPoint &value) { QCursor::setPos(value); }
} // namespace Dpi
+50
View File
@@ -0,0 +1,50 @@
#include "Dpi/DpiExtCtrls.h"
#include "Dpi/DpiGraphics.h"
#include <QPainter>
namespace Dpi {
Panel::Panel(QWidget *parent) : QFrame(parent)
{
setFrameShape(QFrame::StyledPanel);
}
PaintBox::PaintBox(QWidget *parent) : QWidget(parent) {}
void PaintBox::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
if (!onPaint)
return;
QPainter painter(this);
Canvas canvas;
canvas.bind(&painter);
onPaint(canvas);
canvas.unbind();
}
Image::Image(QWidget *parent) : QLabel(parent)
{
setScaledContents(false);
}
void Image::setStretch(bool value)
{
m_stretch = value;
updatePixmap();
}
void Image::setPicture(const QPixmap &pixmap)
{
m_source = pixmap;
updatePixmap();
}
void Image::updatePixmap()
{
setScaledContents(m_stretch);
setPixmap(m_source);
}
} // namespace Dpi
+146
View File
@@ -0,0 +1,146 @@
#include "Dpi/DpiForms.h"
#include <QApplication>
#include <QCloseEvent>
#include <QEventLoop>
#include <QGuiApplication>
#include <QScreen>
#include <QtMath>
namespace Dpi {
Form::Form(QWidget *parent) : QWidget(parent) {}
Form::~Form()
{
if (m_modalLoop)
m_modalLoop->quit();
}
ModalResult Form::showModal()
{
setWindowModality(Qt::ApplicationModal);
m_modalResult = ModalResult::None;
show();
QEventLoop loop;
m_modalLoop = &loop;
loop.exec();
m_modalLoop = nullptr;
return m_modalResult;
}
void Form::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
if (onShow)
onShow();
}
void Form::hideEvent(QHideEvent *event)
{
QWidget::hideEvent(event);
if (onHide)
onHide();
if (m_modalLoop)
m_modalLoop->quit();
}
void Form::closeEvent(QCloseEvent *event)
{
if (onCloseQuery && !onCloseQuery()) {
event->ignore();
return;
}
if (onClose)
onClose();
QWidget::closeEvent(event);
}
bool Form::event(QEvent *event)
{
if (event->type() == QEvent::WindowActivate && onActivate)
onActivate();
if (event->type() == QEvent::WindowDeactivate && onDeactivate)
onDeactivate();
return QWidget::event(event);
}
Form *Application::s_mainForm = nullptr;
void Application::run()
{
if (s_mainForm)
s_mainForm->show();
QApplication::exec();
}
void Application::processMessages()
{
QApplication::processEvents();
}
void Application::terminate()
{
QApplication::quit();
}
QString Application::title() { return QApplication::applicationDisplayName(); }
void Application::setTitle(const QString &value) { QApplication::setApplicationDisplayName(value); }
QString Application::exeName() { return QApplication::applicationFilePath(); }
int Monitor::left() const { return m_screen ? m_screen->geometry().left() : 0; }
int Monitor::top() const { return m_screen ? m_screen->geometry().top() : 0; }
int Monitor::width() const { return m_screen ? m_screen->geometry().width() : 0; }
int Monitor::height() const { return m_screen ? m_screen->geometry().height() : 0; }
QRect Monitor::boundsRect() const { return m_screen ? m_screen->geometry() : QRect(); }
int Screen::formCount()
{
int count = 0;
const auto widgets = QApplication::topLevelWidgets();
for (QWidget *widget : widgets) {
if (qobject_cast<Form *>(widget))
++count;
}
return count;
}
Form *Screen::activeForm()
{
return qobject_cast<Form *>(QApplication::activeWindow());
}
int Screen::dpi()
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen ? qRound(screen->logicalDotsPerInch()) : 96;
}
int Screen::pixelsPerInch() { return dpi(); }
int Screen::width()
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen ? screen->geometry().width() : 0;
}
int Screen::height()
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen ? screen->geometry().height() : 0;
}
QRect Screen::desktopRect()
{
QScreen *screen = QGuiApplication::primaryScreen();
return screen ? screen->availableGeometry() : QRect();
}
Monitor Screen::primaryMonitor()
{
return Monitor(QGuiApplication::primaryScreen());
}
} // namespace Dpi
+318
View File
@@ -0,0 +1,318 @@
#include "Dpi/DpiGraphics.h"
#include <QFontMetrics>
namespace Dpi {
// ---- Font ----
Font::Font() : m_color(Qt::black) {}
QString Font::name() const { return m_font.family(); }
void Font::setName(const QString &value) { m_font.setFamily(value); changed(); }
bool Font::bold() const { return m_font.bold(); }
void Font::setBold(bool value) { m_font.setBold(value); changed(); }
bool Font::italic() const { return m_font.italic(); }
void Font::setItalic(bool value) { m_font.setItalic(value); changed(); }
bool Font::underline() const { return m_font.underline(); }
void Font::setUnderline(bool value) { m_font.setUnderline(value); changed(); }
int Font::size() const { return m_font.pointSize(); }
void Font::setSize(int value) { m_font.setPointSize(value); changed(); }
int Font::height() const { return QFontMetrics(m_font).height(); }
void Font::setHeight(int value) { m_font.setPixelSize(value); changed(); }
QColor Font::color() const { return m_color; }
void Font::setColor(const QColor &value) { m_color = value; changed(); }
QSize Font::getTextSize(const QString &text) const
{
return QFontMetrics(m_font).size(Qt::TextSingleLine, text);
}
int Font::getTextWidth(const QString &text) const
{
return QFontMetrics(m_font).horizontalAdvance(text);
}
int Font::getTextHeight(const QString &text) const
{
Q_UNUSED(text);
return QFontMetrics(m_font).height();
}
void Font::assign(const Font &source)
{
m_font = source.m_font;
m_color = source.m_color;
changed();
}
void Font::changed()
{
if (onChange)
onChange();
}
// ---- Pen ----
Pen::Pen() : m_color(Qt::black), m_style(Qt::SolidLine), m_width(1) {}
void Pen::assign(const Pen &source)
{
m_color = source.m_color;
m_style = source.m_style;
m_width = source.m_width;
}
QPen Pen::toQPen() const
{
QPen pen(m_color);
pen.setStyle(m_style);
pen.setWidth(m_width);
return pen;
}
// ---- Brush ----
Brush::Brush() : m_color(Qt::white), m_style(Qt::SolidPattern) {}
void Brush::assign(const Brush &source)
{
m_color = source.m_color;
m_style = source.m_style;
}
QBrush Brush::toQBrush() const
{
return QBrush(m_color, m_style);
}
// ---- Canvas ----
Canvas::Canvas() = default;
Canvas::Canvas(QPaintDevice *device)
{
setDevice(device);
}
Canvas::~Canvas()
{
end();
}
void Canvas::setDevice(QPaintDevice *device)
{
end();
m_device = device;
}
void Canvas::begin()
{
if (m_painter || !m_device)
return;
m_painter = new QPainter(m_device);
m_ownsPainter = true;
applyPenBrush();
}
void Canvas::end()
{
if (m_painter && m_ownsPainter) {
m_painter->end();
delete m_painter;
}
m_painter = nullptr;
m_ownsPainter = false;
}
void Canvas::bind(QPainter *painter)
{
end();
m_painter = painter;
m_ownsPainter = false;
m_device = painter ? painter->device() : nullptr;
applyPenBrush();
}
void Canvas::unbind()
{
if (!m_ownsPainter) {
m_painter = nullptr;
}
}
QPainter *Canvas::painter()
{
if (!m_painter)
begin();
return m_painter;
}
void Canvas::applyPenBrush()
{
if (!m_painter)
return;
m_painter->setPen(m_pen.toQPen());
m_painter->setBrush(m_brush.toQBrush());
m_painter->setFont(m_font.toQFont());
}
int Canvas::width() const { return m_device ? m_device->width() : 0; }
int Canvas::height() const { return m_device ? m_device->height() : 0; }
QColor Canvas::pixel(int x, int y) const
{
auto *image = dynamic_cast<QImage *>(m_device);
return image ? image->pixelColor(x, y) : QColor();
}
void Canvas::setPixel(int x, int y, const QColor &color)
{
auto *image = dynamic_cast<QImage *>(m_device);
if (image)
image->setPixelColor(x, y, color);
}
void Canvas::moveTo(int x, int y)
{
m_penPos = QPoint(x, y);
}
void Canvas::lineTo(int x, int y)
{
painter()->setPen(m_pen.toQPen());
painter()->drawLine(m_penPos, QPoint(x, y));
m_penPos = QPoint(x, y);
}
void Canvas::line(int x1, int y1, int x2, int y2)
{
painter()->setPen(m_pen.toQPen());
painter()->drawLine(x1, y1, x2, y2);
}
void Canvas::rectangle(int x1, int y1, int x2, int y2)
{
applyPenBrush();
painter()->drawRect(QRect(QPoint(x1, y1), QPoint(x2 - 1, y2 - 1)));
}
void Canvas::ellipse(int x1, int y1, int x2, int y2)
{
applyPenBrush();
painter()->drawEllipse(QRect(QPoint(x1, y1), QPoint(x2 - 1, y2 - 1)));
}
void Canvas::roundRect(int x1, int y1, int x2, int y2, int rx, int ry)
{
applyPenBrush();
painter()->drawRoundedRect(QRect(QPoint(x1, y1), QPoint(x2 - 1, y2 - 1)), rx, ry);
}
void Canvas::polygon(const QPolygon &points)
{
applyPenBrush();
painter()->drawPolygon(points);
}
void Canvas::polyline(const QPolygon &points)
{
painter()->setPen(m_pen.toQPen());
painter()->drawPolyline(points);
}
void Canvas::textOut(int x, int y, const QString &text)
{
painter()->setFont(m_font.toQFont());
painter()->setPen(QPen(m_font.color()));
painter()->drawText(x, y + QFontMetrics(m_font.toQFont()).ascent(), text);
}
int Canvas::textWidth(const QString &text) const { return m_font.getTextWidth(text); }
int Canvas::textHeight(const QString &text) const { return m_font.getTextHeight(text); }
QSize Canvas::textExtent(const QString &text) const { return m_font.getTextSize(text); }
void Canvas::fillRect(const QRect &rect)
{
painter()->fillRect(rect, m_brush.toQBrush());
}
void Canvas::frameRect(const QRect &rect)
{
painter()->setPen(m_pen.toQPen());
painter()->setBrush(Qt::NoBrush);
painter()->drawRect(rect.adjusted(0, 0, -1, -1));
}
void Canvas::draw(int x, int y, const QImage &image)
{
painter()->drawImage(QPoint(x, y), image);
}
void Canvas::stretchDraw(const QRect &rect, const QImage &image)
{
painter()->drawImage(rect, image);
}
void Canvas::copyRect(const QRect &dest, Canvas &source, const QRect &sourceRect)
{
auto *image = dynamic_cast<QImage *>(source.device());
if (image)
painter()->drawImage(dest, *image, sourceRect);
}
// ---- Bitmap ----
Bitmap::Bitmap() : m_image(1, 1, QImage::Format_ARGB32), m_canvas(&m_image) {}
Bitmap::Bitmap(int width, int height)
: m_image(width, height, QImage::Format_ARGB32), m_canvas(&m_image)
{
m_image.fill(Qt::transparent);
}
void Bitmap::setSize(int width, int height)
{
QImage resized(width, height, QImage::Format_ARGB32);
resized.fill(Qt::transparent);
m_image = resized;
m_canvas.setDevice(&m_image);
}
void Bitmap::setTransparentColor(const QColor &value)
{
m_transparentColor = value;
m_transparent = true;
}
void Bitmap::loadFromFile(const QString &fileName)
{
m_image.load(fileName);
m_image = m_image.convertToFormat(QImage::Format_ARGB32);
m_canvas.setDevice(&m_image);
}
void Bitmap::saveToFile(const QString &fileName) const
{
m_image.save(fileName);
}
void Bitmap::assign(const Bitmap &source)
{
m_image = source.m_image;
m_transparent = source.m_transparent;
m_transparentColor = source.m_transparentColor;
m_canvas.setDevice(&m_image);
}
// ---- Picture ----
void Picture::loadFromFile(const QString &fileName)
{
m_bitmap.loadFromFile(fileName);
}
} // namespace Dpi
+37
View File
@@ -0,0 +1,37 @@
#include "Dpi/DpiGrids.h"
#include <QHeaderView>
namespace Dpi {
StringGrid::StringGrid(QWidget *parent) : QTableWidget(parent) {}
QString StringGrid::cell(int col, int row) const
{
QTableWidgetItem *it = item(row, col);
return it ? it->text() : QString();
}
void StringGrid::setCell(int col, int row, const QString &value)
{
QTableWidgetItem *it = item(row, col);
if (!it) {
it = new QTableWidgetItem();
setItem(row, col, it);
}
it->setText(value);
}
void StringGrid::setFixedRows(int value)
{
m_fixedRows = value;
for (int r = 0; r < value && r < rowCount(); ++r)
verticalHeader()->resizeSection(r, verticalHeader()->defaultSectionSize());
}
QRect StringGrid::cellRect(int col, int row) const
{
return visualItemRect(item(row, col));
}
} // namespace Dpi
+118
View File
@@ -0,0 +1,118 @@
#include "Dpi/DpiMenus.h"
namespace Dpi {
MenuItem::MenuItem(const QString &caption, QObject *parent) : QObject(parent)
{
m_action = new QAction(caption, this);
connect(m_action, &QAction::triggered, this, [this] {
if (onClick)
onClick();
});
}
MenuItem::MenuItem(QMenu *existingMenu, bool ownsMenu, QObject *parent)
: QObject(parent), m_submenu(existingMenu), m_ownsSubmenu(ownsMenu)
{
m_action = existingMenu->menuAction();
connect(m_action, &QAction::triggered, this, [this] {
if (onClick)
onClick();
});
}
MenuItem::MenuItem(QMenuBar *bar, QObject *parent) : QObject(parent), m_bar(bar) {}
MenuItem::~MenuItem()
{
qDeleteAll(m_items);
if (m_ownsSubmenu)
delete m_submenu;
}
QMenu *MenuItem::submenu()
{
if (!m_submenu) {
m_submenu = new QMenu();
m_ownsSubmenu = true;
if (m_action)
m_action->setMenu(m_submenu);
}
return m_submenu;
}
void MenuItem::setRadioItem(bool value)
{
m_radioItem = value;
if (m_action)
m_action->setCheckable(value);
}
MenuItem *MenuItem::add(const QString &caption)
{
MenuItem *item;
if (m_bar) {
QMenu *menu = m_bar->addMenu(caption);
item = new MenuItem(menu, false, this);
} else {
item = new MenuItem(caption, this);
submenu()->addAction(item->action());
}
m_items.append(item);
return item;
}
void MenuItem::insert(int index, MenuItem *item)
{
if (!m_bar) {
QAction *before = (index >= 0 && index < m_items.count()) ? m_items[index]->action() : nullptr;
submenu()->insertAction(before, item->action());
}
m_items.insert(index, item);
}
void MenuItem::remove(MenuItem *item)
{
if (m_submenu)
m_submenu->removeAction(item->action());
m_items.removeOne(item);
}
void MenuItem::deleteItem(int index)
{
MenuItem *item = m_items.value(index);
if (!item)
return;
remove(item);
delete item;
}
void MenuItem::clear()
{
for (MenuItem *item : std::as_const(m_items)) {
if (m_submenu)
m_submenu->removeAction(item->action());
delete item;
}
m_items.clear();
}
void MenuItem::click()
{
if (m_action)
m_action->trigger();
}
PopupMenu::PopupMenu(QObject *parent) : MenuItem(new QMenu(), true, parent) {}
void PopupMenu::popup(const QPoint &pos)
{
submenu()->popup(pos);
}
QKeySequence shortCut(int key, Qt::KeyboardModifiers modifiers)
{
return QKeySequence(static_cast<int>(modifiers) | key);
}
} // namespace Dpi
+75
View File
@@ -0,0 +1,75 @@
#include "Dpi/DpiPixelPointer.h"
namespace Dpi {
PixelPointer::PixelPointer(QImage *image, int baseX, int baseY)
: m_image(image)
{
if (m_image) {
m_width = m_image->width();
m_height = m_image->height();
}
setXY(baseX, baseY);
}
void PixelPointer::setXY(int x, int y)
{
m_x = x;
m_y = y;
}
void PixelPointer::setX(int x)
{
m_x = x;
}
void PixelPointer::nextPixel()
{
++m_x;
}
void PixelPointer::previousPixel()
{
--m_x;
}
void PixelPointer::nextLine()
{
++m_y;
}
void PixelPointer::previousLine()
{
--m_y;
}
bool PixelPointer::posValid() const
{
return m_image && m_x >= 0 && m_x < m_width && m_y >= 0 && m_y < m_height;
}
QRgb PixelPointer::pixelARGB() const
{
if (!posValid())
return 0;
return reinterpret_cast<const QRgb *>(m_image->constScanLine(m_y))[m_x];
}
void PixelPointer::setPixelARGB(QRgb value)
{
if (!posValid())
return;
reinterpret_cast<QRgb *>(m_image->scanLine(m_y))[m_x] = value;
}
QRgb PixelPointer::pixelRGB() const
{
return pixelARGB() | 0xFF000000;
}
void PixelPointer::setPixelRGB(QRgb value)
{
setPixelARGB(value | 0xFF000000);
}
} // namespace Dpi
+4
View File
@@ -0,0 +1,4 @@
#include "Dpi/DpiSpin.h"
// No out-of-line members yet; this translation unit exists so AUTOMOC picks
// up SpinEdit's Q_OBJECT macro consistently with the rest of the library.
+29
View File
@@ -0,0 +1,29 @@
#include "Dpi/DpiStdCtrls.h"
namespace Dpi {
QStringList Memo::lines() const
{
return toPlainText().split(QLatin1Char('\n'));
}
void Memo::setLines(const QStringList &value)
{
setPlainText(value.join(QLatin1Char('\n')));
}
QStringList ListBox::items() const
{
QStringList result;
for (int i = 0; i < count(); ++i)
result << item(i)->text();
return result;
}
void ListBox::setItems(const QStringList &value)
{
clear();
addItems(value);
}
} // namespace Dpi