first re-commit.

This commit is contained in:
2025-08-05 22:39:41 +02:00
commit 87de9c1f33
73 changed files with 23249 additions and 0 deletions

68
widgets/xqcontextmenu.cpp Normal file
View File

@@ -0,0 +1,68 @@
/***************************************************************************
source::worx xtree
Copyright © 2024-2025 c.holzheuer
christoph.holzheuer@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#include <xqcontextmenu.h>
XQContextMenu::XQContextMenu(const QString& title, QWidget* parent )
: QMenu( title, parent )
{
/*
QAction* titleDummy = new QAction(title,this);
QWidget::addAction(titleDummy);
addSeparator();
titleDummy->setEnabled(false);
*/
}
XQContextMenu::XQContextMenu(QWidget* parent)
: QMenu( parent )
{
}
void XQContextMenu::addAction(const QString& text, XQCommand::CmdType commandType, bool enabled)
{
QAction* newAction = new QAction(text, this);
newAction->setData(commandType);
_actionMap[commandType] = newAction;
QWidget::addAction(newAction);
setActionEnabled( commandType, enabled );
}
void XQContextMenu::addAction(const QString& iconKey, const QString& name, XQCommand::CmdType commandType, bool enabled)
{
addAction(XQAppData::typeIcon( iconKey), name, commandType, enabled );
}
void XQContextMenu::addAction(const QIcon& icon, const QString& text, XQCommand::CmdType commandType, bool enabled)
{
QAction* newAction = new QAction(icon, text, this);
newAction->setData(commandType);
_actionMap[commandType] = newAction;
QWidget::addAction(newAction);
setActionEnabled( commandType, enabled );
}
void XQContextMenu::setActionEnabled(XQCommand::CmdType commandType, bool enabled)
{
if( _actionMap.contains(commandType) )
_actionMap[commandType]->setEnabled( enabled );
}

51
widgets/xqcontextmenu.h Normal file
View File

@@ -0,0 +1,51 @@
/***************************************************************************
source::worx xtree
Copyright © 2024-2025 c.holzheuer
christoph.holzheuer@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#ifndef XQCONTEXTMENU_H
#define XQCONTEXTMENU_H
#include <QMenu>
#include <QMap>
#include <xqcommand.h>
/**
* @brief A specialized QMenu for @see XQCommands
*/
class XQContextMenu : public QMenu
{
Q_OBJECT
public:
XQContextMenu(const QString& title, QWidget* parent = nullptr );
XQContextMenu(QWidget* parent = nullptr );
virtual ~XQContextMenu() = default;
void addAction(const QString& name, XQCommand::CmdType commandType, bool enabled );
void addAction(const QString& iconKey, const QString& name, XQCommand::CmdType commandType, bool enabled );
void addAction(const QIcon& icon, const QString& name, XQCommand::CmdType commandType, bool enabled );
void setActionEnabled(XQCommand::CmdType commandType, bool enabled);
protected:
QMap<int, QAction*> _actionMap;
};
#endif //; XQContextMenu_H

196
widgets/xqtreeview.cpp Normal file
View File

@@ -0,0 +1,196 @@
/***************************************************************************
source::worx xtree
Copyright © 2024-2025 c.holzheuer
christoph.holzheuer@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#include <QPainter>
#include <QTime>
#include "qheaderview.h"
#include <xqtreeview.h>
#include <xqmodel.h>
#define DB_TIMESTAMP QTime::currentTime().toString(" -- HH:mm:ss.zzz")
XQTreeView::XQTreeView(QWidget* parent)
: QTreeView(parent)
{
/*
setDragEnabled(true);
setAcceptDrops(true);
setDragDropOverwriteMode(true);
setDropIndicatorShown(false);
*/
setHeaderHidden(true);
setMouseTracking(true);
}
XQTreeView::~XQTreeView()
{
}
XQModel* XQTreeView::modelView()
{
return static_cast<XQModel*>(model());
}
// __fixme: necessary?
XQItem& XQTreeView::xqItemFromIndex(const QModelIndex& index )
{
return modelView()->xqItemFromIndex( index );
}
void XQTreeView::currentChanged(const QModelIndex& current, const QModelIndex& previous)
{
QTreeView::currentChanged(current, previous);
// edit comboboxes directly
//XQItem& currentItem = xqItemFromIndex(current);
// xx_fix!
/*
if (curreXQItem && curreXQItem->renderStyle() == XQItem::ComboBoxStyle )
{
QTreeView::edit(current);
}
*/
}
void XQTreeView::mouseResizeHeaderEntry(int xpos)
{
// resize colummn: minimal vertical margin in pixels
static const int s_MinimalMargin = 50;
QRect itemRect = visualRect(_indexToResize);
// new position different to item rect outer right position
int newPos = xpos - itemRect.right();
// current section size from header
int column = _indexToResize.column();
int sectionSize = columnWidth( column );
int maxPos = s_MinimalMargin + xpos;
// resize header and update view
if (maxPos <= width())
{
header()->resizeSection(column, sectionSize + newPos);
}
}
void XQTreeView::mouseMoveEvent(QMouseEvent* event)
{
// pixel Grenzwert zur Anzeige des Splitcursors
static const int s_CatchOffset = 5;
bool leftBtn = (event->buttons() & Qt::LeftButton);
QPoint eventPos = event->pos();
// splitcursor ist active
bool splitCursor = (cursor().shape() == Qt::SplitHCursor);
// sind wir schon am 'draggen'?
if (_indexToResize.isValid() && splitCursor && leftBtn)
{
return mouseResizeHeaderEntry(eventPos.x());
}
// nein, nocht nicht
QModelIndex idxFromPos = indexAt(eventPos);
// mousepointer is inside a header section
if ( xqItemFromIndex(idxFromPos).isHeaderStyle() )
{
QRect itemRect = visualRect(idxFromPos);
int crX = itemRect.topRight().x() - s_CatchOffset;
QRect catchRect = QRect(crX, itemRect.y(), s_CatchOffset, itemRect.height());
if (catchRect.contains(eventPos))
{
return setCursor(QCursor(Qt::SplitHCursor));
}
}
setCursor(QCursor(Qt::ArrowCursor));
QTreeView::mouseMoveEvent(event);
}
void XQTreeView::mouseDoubleClickEvent(QMouseEvent* event)
{
/*
QModelIndex idxFromPos = indexAt(event->pos());
if (idxFromPos.isValid())
{
if ( NTItem::isHeaderType(idxFromPos) && cursor().shape() == Qt::SplitHCursor)
{
return resizeColumnToContents(idxFromPos.column());
}
}
*/
QTreeView::mouseDoubleClickEvent(event);
}
void XQTreeView::mousePressEvent(QMouseEvent* event)
{
// case #1:
// Handle header resiszing
QPoint pos = event->pos();
QModelIndex index = indexAt(pos);
// set index for resize column if cursor for split is active
if (cursor().shape() == Qt::SplitHCursor)
{
_indexToResize = index;
}
QTreeView::mousePressEvent(event);
}
void XQTreeView::mouseReleaseEvent(QMouseEvent* event)
{
// reset index for resize column
_indexToResize = QModelIndex();
setCursor(QCursor(Qt::ArrowCursor));
QTreeView::mouseReleaseEvent(event);
}
void XQTreeView::wheelEvent(QWheelEvent* event)
{
// Ctrl-key down?
if (!event->modifiers().testFlag(Qt::ControlModifier))
// default processing
return QTreeView::wheelEvent(event);
// current size
int curSize = fontInfo().pointSize();
// increase?
if (event->angleDelta().y() > 0)
{
// "zoom in"
curSize += (curSize < 40) ? (1) : (0);
}
else
{
// "zoom out"
curSize -= (curSize > 8) ? (1) : (0);
}
// adjust size via stylesheet
setStyleSheet(QString("font: %1pt;").arg(curSize));
}

62
widgets/xqtreeview.h Normal file
View File

@@ -0,0 +1,62 @@
/***************************************************************************
source::worx xtree
Copyright © 2024-2025 c.holzheuer
christoph.holzheuer@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
***************************************************************************/
#ifndef XQTREEVIEW_H
#define XQTREEVIEW_H
#include <QTreeView>
#include <QMouseEvent>
#include <QDebug>
class XQItem;
class XQModel;
/**
* @brief A specialized QTreeView that will handle the drawing of
* empty or non-existing items in the future.
*/
class XQTreeView : public QTreeView
{
Q_OBJECT
Q_DECLARE_PRIVATE(QTreeView)
public:
XQTreeView(QWidget* parent = nullptr );
virtual ~XQTreeView();
XQModel* modelView();
XQItem& xqItemFromIndex(const QModelIndex& index );
protected:
void currentChanged(const QModelIndex& current, const QModelIndex& previous) override;
void mouseMoveEvent(QMouseEvent* event) override;
//! Mouse press event.used to emulate the behavior of a QHeaderView in the first line of the view
void mouseDoubleClickEvent(QMouseEvent* event) override;
//! Mouse release event.used to emulate the behavior of a QHeaderView in the first line of the view
void mouseReleaseEvent(QMouseEvent* event) override;
//! Mouse press event.used to emulate the behavior of a QHeaderView in the first line of the view
void mousePressEvent(QMouseEvent* event) override;
void mouseResizeHeaderEntry(int xpos);
//! Mouse wheel event.
void wheelEvent(QWheelEvent* event) override;
//! used by the mouse events
QModelIndex _indexToResize;
};
#endif // XQTREEVIEW_H