Modified Qt TAS branches view to compensate for different font sizes.

This commit is contained in:
mjbudd77 2021-12-08 21:43:39 -05:00
parent 77ced676f0
commit 5a34a78a24
2 changed files with 65 additions and 22 deletions

View File

@ -96,6 +96,7 @@ void BRANCHES::setFont( QFont &newFont )
void BRANCHES::calcFontData(void)
{
int w,h;
QWidget::setFont(font);
QFontMetrics metrics(font);
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
@ -110,6 +111,9 @@ void BRANCHES::calcFontData(void)
pxBoxHeight = pxLineSpacing;
pxSelWidth = (pxBoxWidth * 7) / 8;
pxSelHeight = (pxBoxHeight * 7) / 8;
pxMinGridWidth = pxBoxWidth * 1;
pxMaxGridWidth = pxBoxWidth * 2;
}
void BRANCHES::init()
@ -574,6 +578,16 @@ bool BRANCHES::event(QEvent *event)
return QWidget::event(event);
}
void BRANCHES::resizeEvent(QResizeEvent *event)
{
viewWidth = event->size().width();
viewHeight = event->size().height();
//printf("BranchView: %i x %i\n", viewWidth, viewHeight );
recalculateBranchesTree();
}
void BRANCHES::paintEvent(QPaintEvent *event)
{
int x,y;
@ -1351,14 +1365,33 @@ void BRANCHES::recalculateBranchesTree()
int grid_width, cloud_prefix = 0;
if (BranchesLevels.size()-1 > 0)
{
grid_width = BRANCHES_CANVAS_WIDTH / (BranchesLevels.size()-1);
if (grid_width < BRANCHES_GRID_MIN_WIDTH)
grid_width = BRANCHES_GRID_MIN_WIDTH;
else if (grid_width > BRANCHES_GRID_MAX_WIDTH)
grid_width = BRANCHES_GRID_MAX_WIDTH;
} else grid_width = BRANCHES_GRID_MAX_WIDTH;
//grid_width = BRANCHES_CANVAS_WIDTH / (BranchesLevels.size()-1);
grid_width = width() / (BranchesLevels.size()-1);
//if (grid_width < BRANCHES_GRID_MIN_WIDTH)
//{
// grid_width = BRANCHES_GRID_MIN_WIDTH;
//}
//else if (grid_width > BRANCHES_GRID_MAX_WIDTH)
//{
// grid_width = BRANCHES_GRID_MAX_WIDTH;
//}
if (grid_width < pxMinGridWidth)
{
grid_width = pxMinGridWidth;
}
else if (grid_width > pxMaxGridWidth)
{
grid_width = pxMaxGridWidth;
}
}
else
{
grid_width = pxMaxGridWidth;
}
if (grid_width < MIN_CLOUD_LINE_LENGTH)
{
cloud_prefix = MIN_CLOUD_LINE_LENGTH - grid_width;
}
// 2. Define GridY of branches
recursiveSetYPos(ITEM_UNDER_MOUSE_CLOUD, 0);
@ -1366,15 +1399,26 @@ void BRANCHES::recalculateBranchesTree()
int grid_halfheight;
int totalHeight = 0;
for (int i = children[0].size()-1; i >= 0; i--)
{
totalHeight += gridHeight[children[0][i]];
}
if (totalHeight)
{
grid_halfheight = BRANCHES_CANVAS_HEIGHT / (2 * totalHeight);
//grid_halfheight = BRANCHES_CANVAS_HEIGHT / (2 * totalHeight);
grid_halfheight = height() / (2 * totalHeight);
if (grid_halfheight < BRANCHES_GRID_MIN_HALFHEIGHT)
{
grid_halfheight = BRANCHES_GRID_MIN_HALFHEIGHT;
}
else if (grid_halfheight > BRANCHES_GRID_MAX_HALFHEIGHT)
{
grid_halfheight = BRANCHES_GRID_MAX_HALFHEIGHT;
} else grid_halfheight = BRANCHES_GRID_MAX_HALFHEIGHT;
}
}
else
{
grid_halfheight = BRANCHES_GRID_MAX_HALFHEIGHT;
}
// special case 2: if chain of branches is too long, the last item (fireball) goes up
if (changesSinceCurrentBranch)
{
@ -1488,9 +1532,13 @@ void BRANCHES::recalculateBranchesTree()
// align whole tree horizontally
cloudX = (BRANCHES_BITMAP_WIDTH + BASE_HORIZONTAL_SHIFT - max_x) / 2;
if (cloudX < MIN_CLOUD_X)
//if (cloudX < MIN_CLOUD_X)
//{
// cloudX = MIN_CLOUD_X;
//}
if (cloudX < pxBoxWidth)
{
cloudX = MIN_CLOUD_X;
cloudX = pxBoxWidth;
}
for (int i = TOTAL_BOOKMARKS-1; i >= 0; i--)
{

View File

@ -32,12 +32,14 @@
#define BRANCHES_CLOUD_X 14
#define BRANCHES_CLOUD_Y 72
#define BRANCHES_GRID_MIN_WIDTH 14
#define BRANCHES_GRID_MAX_WIDTH 30
//#define BRANCHES_GRID_MAX_WIDTH 30
#define BRANCHES_GRID_MAX_WIDTH 40
#define MIN_CLOUD_LINE_LENGTH 19
#define MIN_CLOUD_X 12
#define BASE_HORIZONTAL_SHIFT 10
#define BRANCHES_GRID_MIN_HALFHEIGHT 8
#define BRANCHES_GRID_MAX_HALFHEIGHT 12
#define BRANCHES_GRID_MAX_HALFHEIGHT 32
//#define BRANCHES_GRID_MAX_HALFHEIGHT 12
#define EMPTY_BRANCHES_X_BASE 4
#define EMPTY_BRANCHES_Y_BASE 9
#define EMPTY_BRANCHES_Y_FACTOR 14
@ -143,6 +145,7 @@ public:
protected:
void paintEvent(QPaintEvent *event);
void resizeEvent(QResizeEvent *event);
void mousePressEvent(QMouseEvent * event);
void mouseReleaseEvent(QMouseEvent * event);
void mouseMoveEvent(QMouseEvent * event);
@ -184,16 +187,6 @@ private:
int fireballSize;
int lastItemUnderMouse;
// GDI stuff
//HBRUSH normalBrush, borderBrush, selectedSlotBrush;
//RECT tempRect;
//HPEN normalPen, timelinePen, selectPen;
//HBITMAP hBranchesBitmap, hOldBitmap, hBufferBitmap, hOldBitmap1, hBranchesSpritesheet, hOldBitmap2;
//HDC hBitmapDC, hBufferDC, hSpritesheetDC;
//TRIVERTEX vertex[2];
//GRADIENT_RECT gRect;
//RECT branchesBitmapRect;
QFont font;
int viewWidth;
@ -205,6 +198,8 @@ private:
int pxBoxHeight;
int pxSelWidth;
int pxSelHeight;
int pxMinGridWidth;
int pxMaxGridWidth;
// temps
std::vector<int> gridX; // measured in grid units, not in pixels