tahoma2d/toonz/sources/toonzqt/treemodel.cpp

455 lines
15 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
UI update and Icons from Konero (#126) * add multi arc mockup * implement mutli arc * add join and smooth option * reset multiarc and arc when deactivated * create self loop if the last point is the same as the first * make join option in multiarc consistent with tape tool * fix a bug where thickness don't affect mutliarc in vector level * remove join option in geometric tool * stop mutliarc after closing shape * double click can also end multi arc * fix a bug where multiArc will produce buggy stroke * fix a bug where geometric tools is not deactivated * add multiArc shortcut * rewrite multiArc * revert changes to tvectorimage * add undo data for multiArc * Paste as Copy Command for XSheet * Remove unneeded code * Bug fix * prevent guide lines from jumping around in MultiArc * make stroke color consistent in MultiArc * remove color in MultiArc's undo data * make color consistent in MultiArc with previous version * Fix single image raster levels * fix compilation error * fix a bug where multiArc might generate bugged stroke * Remove ICONV dep (#3304) * fix crash on saving studio palette * Move to Paste Special Menu * Don't Set Fixed Width if Docking a Floating Panel * Update how_to_build_win.md New draft of pr for requested changes to windows build instructions. * fix geometric tool multiarc smooth option * fix level saving failure * fix wrong warning after saving palette * fix a bug where moving a control point while holding alt has unintended result * fix travis-install (#3389) * Fix assert debug crash in flipconsole.cpp Fix crash when using the viewer controls in the console (debug) * Redraw Audio Waveform Fills the waveform rather than outlines it. * Update .gitignore * fix undo data when drawing arc and mutliarc * fix overwriting raster drawing palette (#3387) * mode sensitive fx settings * Create New Style Command Button (#3394) * Create New Style Command Button This PR creates a new button in the pallette editor that creates a new style. Button is large and easy access for a faster and easier workflow. Original code developed by Turtletooth for Tahoma. Given permission to develop within Openoonz. Co-Authored-By: Jeremy Bullock <turtletooth@users.noreply.github.com> * Update paletteviewergui.cpp Made changes to the PR per request by Shun. * Fixed a space within the code that wasn't suppose to be there. Co-authored-by: Jeremy Bullock <turtletooth@users.noreply.github.com> * tahoma license (#3396) * new style button optional * fix loading pegbars (removing updateKeyframes) * periodic random expression * add fx in linear color space this commit is based on source for the ComposeAdd plugin fx by DWANGO Co., Ltd. in dwango_opentoonz_plugins and opentoonz_plugin_utility repositories. * fractal noise iwa fx * skip unnecessary icon invalidation * fix frame range fill with tablet * stop function editor to open by dbl clicking key * Expanding the radius of the rotation handle. This just changes when the cursor transforms into the rotation tool. (cherry picked from commit 7722ae989bbdc6aa5cb48df7a4c08bae1fe6ea39) * fix vector img patern stroke style * Update Stylesheets - Support the new icon sizes - XSheet and Timeline significantly redesigned - Lots of margin fixes and refactoring - Remove deprecated icons, as some icons are moved into binary - New Light theme * New Icons - Redesigns almost every icon as symbolic - Adds icons for most commands * Add Option for Icon Themes - Adds option for icon themes - Removes useless label from Preferences category list * Update Icon Functions - Adds themePath() boolean - Adds function for recoloring black pixels in pixmaps to any color - Rebuilds createQIcon to use fromTheme() and recolorPixmap() - Removes createQIconOnOff as it seemed to be a rarely used duplicate of createQIcon - Removes a grey horizontal line drawn above the console play bar in the viewer * Set Default Icon Theme and Paths - Sets search paths for icons for use with QIcon::fromTheme() - Sets default start icon theme on first install - Sets flag for displaying icons in menus, so we can selectively hide them * Set Icons for Commands - Sets icons for the commands - Hides icons being displayed in menus as most icons are 20x20, they will look blurry when shrunk to 16x16 - Selectively allows icons to display for Tools in menus * Change Icon Sizes, General Fixes and Stylesheet Additions - Change icon sizes to new size - Remove margin around FX Editor window - Remove white line under color sliders in Style Editor - Make keyframe icons uniform and color stylable in the stylesheets - Removes deprecated stylesheet strings - Redesign GUI for palette list view - Make tree list header sort row stylable - Remove black lines from scrollbars in New Project window - Remove margin around combobox in Level Strip - Alter how some lines are drawn in the Timeline to fix some alpha issues - Make conditional fixed onion skin and normal onion skin dots contrast more against a light background area to make sure they have good visibility - Make text always viewable in the FPS field in console bar - Increase size of radio buttons in Cleanup Settings - Increase size of switches in motion path nodes - Remove unessesary "Layer" label in Timeline and other rects - Various colors made stylable in the stylesheets; palette numpad and selection frame, cleanup settings border, scene cast folder path, schematic lines, ruler, xsheet lines, keyframes, cell input box and more - Moves some external stylesheet icons into binary * Make TPanelTitleBar Icon States Stylable - Makes icon states for TPanelTitleBar buttons stylable in stylesheets * Travis Fixes * Swap Startup Popup Logos They were in the wrong folders * Revert "Swap Startup Popup Logos" This reverts commit 815908a9f3e725f48507dab8a2270bdfa045649d. * Fix Startup Popup Logo It wasn't switching * Feedback Changes - Change render visualization to clapboard - Fix text contrast on levels in XSheet * Make Cell Selection More Clear * Darken Light Theme and Tint Empty Cell Selection * Fix missing icons * Fix memo button * Bring back colors * Hide Motion Tab * Fix Play Range Area (Light) Make play range area more visible * Vector Column Color Co-authored-by: pojienie <pojienie@gmail.com> Co-authored-by: rim <11380091+rozhuk-im@users.noreply.github.com> Co-authored-by: shun-iwasawa <shun.iwasawa@ghibli.jp> Co-authored-by: Rodney <rodney.baker@gmail.com> Co-authored-by: DoctorRyan <65507211+DoctorRyan@users.noreply.github.com> Co-authored-by: shun-iwasawa <shun-iwasawa@users.noreply.github.com> Co-authored-by: Kite <konero@users.noreply.github.com> Co-authored-by: Jeremy Bullock <turtletooth@users.noreply.github.com> Co-authored-by: DoctorRyan <doctorryan1969.gmail.com>
2020-09-01 06:51:22 +12:00
#include "toonzqt/gutil.h"
2016-03-19 06:57:51 +13:00
#include "toonzqt/treemodel.h"
#include <QStringList>
#include <QTreeView>
#include <QHeaderView>
#include <QMouseEvent>
#include <qvariant.h>
#include <qicon.h>
#include <qtextedit.h>
#include "tfx.h"
#include <assert.h>
//====================================================================================================
// Item
//----------------------------------------------------------------------------------------------------
TreeModel::Item::Item()
2016-06-15 18:43:10 +12:00
: m_model(0), m_parent(0), m_depth(0), m_row(0), m_opened(false) {}
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TreeModel::Item::~Item() {
qDeleteAll(m_childItems);
m_childItems.clear();
m_model = 0;
m_row = 0;
m_depth = 0;
m_parent = 0;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::Item::updateChild(Item *child, int row) {
assert(m_model);
child->m_model = m_model;
child->m_depth = m_depth + 1;
child->m_parent = this;
child->m_row = row;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::Item::updateChildren() {
int i;
for (i = 0; i < m_childItems.size(); i++) updateChild(m_childItems[i], i);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TreeModel::Item *TreeModel::Item::appendChild(TreeModel::Item *child) {
assert(child);
assert(!m_childItems.contains(child));
updateChild(child, m_childItems.size());
m_childItems.append(child);
return child;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
/*
void TreeModel::Item::deleteChild(Item *child)
{
int index = m_childItems.indexOf(child);
if(index != -1)
{
m_childItems.takeAt(index);
2016-06-15 18:43:10 +12:00
assert(!m_childItems.contains(child));
2016-03-19 06:57:51 +13:00
// m_childItems is not supposed to contain duplicated entries
delete child;
updateChildren();
}
}
*/
//------------------------------------------------------------------------------------------------------------------
/*
Item* matchItem(Item*item, QList<Item*> &items)
{
void *itemData = item->getInternalPointer();
if(!itemData) return 0;
int i;
for(i=0;i<items.size();i++)
if(items.at(i)->getInternalPointer()==itemData)
return items.at(i);
return 0;
}
*/
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::Item::setChildren(QList<Item *> &newChildren) {
assert(m_model);
QModelIndex itemIndex = createIndex();
// save old children and clear 'm_childItems'
QList<Item *> oldChildren(m_childItems);
m_childItems.clear();
int i;
// for each child to add
for (i = 0; i < newChildren.size(); i++) {
Item *newChild = newChildren.at(i);
void *newInternalPointer = newChild->getInternalPointer();
if (newInternalPointer != 0) {
// search among old children
int j;
for (j = 0; j < oldChildren.size(); j++)
if (oldChildren.at(j)->getInternalPointer() == newInternalPointer)
break;
if (j < oldChildren.size()) {
Item *oldChild = oldChildren.takeAt(j);
if (oldChild != newChild) {
// Found! Delete newChild, remove it from 'newChildren' and
// update consequently the index
delete newChild;
newChildren.takeAt(i);
i--;
// use the found child instead of the new one.
newChild = oldChild;
oldChild->refresh();
} else {
// should never happen; (if it happens this is not a big problem)
assert(0);
}
}
}
// add the new child to 'm_childItems'
m_childItems.push_back(newChild);
}
// update children model, row, parent, etc.
updateChildren();
// postpone item deletion to avoid the (possible) reuse of the
// same pointer for the newly created items. (Pointers match is
// used updating persistent indices. see: TreeModel::endRefresh())
for (i = 0; i < oldChildren.size(); i++) {
Item *itemToDelete = oldChildren[i];
if (!m_model->m_itemsToDelete.contains(itemToDelete))
m_model->m_itemsToDelete.push_back(itemToDelete);
}
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
QVariant TreeModel::Item::data(int role) const {
if (role == Qt::DecorationRole)
UI update and Icons from Konero (#126) * add multi arc mockup * implement mutli arc * add join and smooth option * reset multiarc and arc when deactivated * create self loop if the last point is the same as the first * make join option in multiarc consistent with tape tool * fix a bug where thickness don't affect mutliarc in vector level * remove join option in geometric tool * stop mutliarc after closing shape * double click can also end multi arc * fix a bug where multiArc will produce buggy stroke * fix a bug where geometric tools is not deactivated * add multiArc shortcut * rewrite multiArc * revert changes to tvectorimage * add undo data for multiArc * Paste as Copy Command for XSheet * Remove unneeded code * Bug fix * prevent guide lines from jumping around in MultiArc * make stroke color consistent in MultiArc * remove color in MultiArc's undo data * make color consistent in MultiArc with previous version * Fix single image raster levels * fix compilation error * fix a bug where multiArc might generate bugged stroke * Remove ICONV dep (#3304) * fix crash on saving studio palette * Move to Paste Special Menu * Don't Set Fixed Width if Docking a Floating Panel * Update how_to_build_win.md New draft of pr for requested changes to windows build instructions. * fix geometric tool multiarc smooth option * fix level saving failure * fix wrong warning after saving palette * fix a bug where moving a control point while holding alt has unintended result * fix travis-install (#3389) * Fix assert debug crash in flipconsole.cpp Fix crash when using the viewer controls in the console (debug) * Redraw Audio Waveform Fills the waveform rather than outlines it. * Update .gitignore * fix undo data when drawing arc and mutliarc * fix overwriting raster drawing palette (#3387) * mode sensitive fx settings * Create New Style Command Button (#3394) * Create New Style Command Button This PR creates a new button in the pallette editor that creates a new style. Button is large and easy access for a faster and easier workflow. Original code developed by Turtletooth for Tahoma. Given permission to develop within Openoonz. Co-Authored-By: Jeremy Bullock <turtletooth@users.noreply.github.com> * Update paletteviewergui.cpp Made changes to the PR per request by Shun. * Fixed a space within the code that wasn't suppose to be there. Co-authored-by: Jeremy Bullock <turtletooth@users.noreply.github.com> * tahoma license (#3396) * new style button optional * fix loading pegbars (removing updateKeyframes) * periodic random expression * add fx in linear color space this commit is based on source for the ComposeAdd plugin fx by DWANGO Co., Ltd. in dwango_opentoonz_plugins and opentoonz_plugin_utility repositories. * fractal noise iwa fx * skip unnecessary icon invalidation * fix frame range fill with tablet * stop function editor to open by dbl clicking key * Expanding the radius of the rotation handle. This just changes when the cursor transforms into the rotation tool. (cherry picked from commit 7722ae989bbdc6aa5cb48df7a4c08bae1fe6ea39) * fix vector img patern stroke style * Update Stylesheets - Support the new icon sizes - XSheet and Timeline significantly redesigned - Lots of margin fixes and refactoring - Remove deprecated icons, as some icons are moved into binary - New Light theme * New Icons - Redesigns almost every icon as symbolic - Adds icons for most commands * Add Option for Icon Themes - Adds option for icon themes - Removes useless label from Preferences category list * Update Icon Functions - Adds themePath() boolean - Adds function for recoloring black pixels in pixmaps to any color - Rebuilds createQIcon to use fromTheme() and recolorPixmap() - Removes createQIconOnOff as it seemed to be a rarely used duplicate of createQIcon - Removes a grey horizontal line drawn above the console play bar in the viewer * Set Default Icon Theme and Paths - Sets search paths for icons for use with QIcon::fromTheme() - Sets default start icon theme on first install - Sets flag for displaying icons in menus, so we can selectively hide them * Set Icons for Commands - Sets icons for the commands - Hides icons being displayed in menus as most icons are 20x20, they will look blurry when shrunk to 16x16 - Selectively allows icons to display for Tools in menus * Change Icon Sizes, General Fixes and Stylesheet Additions - Change icon sizes to new size - Remove margin around FX Editor window - Remove white line under color sliders in Style Editor - Make keyframe icons uniform and color stylable in the stylesheets - Removes deprecated stylesheet strings - Redesign GUI for palette list view - Make tree list header sort row stylable - Remove black lines from scrollbars in New Project window - Remove margin around combobox in Level Strip - Alter how some lines are drawn in the Timeline to fix some alpha issues - Make conditional fixed onion skin and normal onion skin dots contrast more against a light background area to make sure they have good visibility - Make text always viewable in the FPS field in console bar - Increase size of radio buttons in Cleanup Settings - Increase size of switches in motion path nodes - Remove unessesary "Layer" label in Timeline and other rects - Various colors made stylable in the stylesheets; palette numpad and selection frame, cleanup settings border, scene cast folder path, schematic lines, ruler, xsheet lines, keyframes, cell input box and more - Moves some external stylesheet icons into binary * Make TPanelTitleBar Icon States Stylable - Makes icon states for TPanelTitleBar buttons stylable in stylesheets * Travis Fixes * Swap Startup Popup Logos They were in the wrong folders * Revert "Swap Startup Popup Logos" This reverts commit 815908a9f3e725f48507dab8a2270bdfa045649d. * Fix Startup Popup Logo It wasn't switching * Feedback Changes - Change render visualization to clapboard - Fix text contrast on levels in XSheet * Make Cell Selection More Clear * Darken Light Theme and Tint Empty Cell Selection * Fix missing icons * Fix memo button * Bring back colors * Hide Motion Tab * Fix Play Range Area (Light) Make play range area more visible * Vector Column Color Co-authored-by: pojienie <pojienie@gmail.com> Co-authored-by: rim <11380091+rozhuk-im@users.noreply.github.com> Co-authored-by: shun-iwasawa <shun.iwasawa@ghibli.jp> Co-authored-by: Rodney <rodney.baker@gmail.com> Co-authored-by: DoctorRyan <65507211+DoctorRyan@users.noreply.github.com> Co-authored-by: shun-iwasawa <shun-iwasawa@users.noreply.github.com> Co-authored-by: Kite <konero@users.noreply.github.com> Co-authored-by: Jeremy Bullock <turtletooth@users.noreply.github.com> Co-authored-by: DoctorRyan <doctorryan1969.gmail.com>
2020-09-01 06:51:22 +12:00
return createQIcon("folder", true);
2016-06-15 18:43:10 +12:00
else
return QVariant();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
QModelIndex TreeModel::Item::createIndex() {
return m_parent ? m_model->createIndex(m_row, 0, this) : QModelIndex();
2016-03-19 06:57:51 +13:00
}
//====================================================================================================
// TreeModel
//----------------------------------------------------------------------------------------------------
TreeModel::TreeModel(TreeView *parent)
2016-06-15 18:43:10 +12:00
: QAbstractItemModel(parent), m_rootItem(0), m_view(parent) {}
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TreeModel::~TreeModel() { delete m_rootItem; }
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::setExpandedItem(const QModelIndex &index, bool expanded) {
2020-04-17 19:02:53 +12:00
if (m_view) m_view->setExpanded(index, expanded);
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::beginRefresh() { emit layoutAboutToBeChanged(); }
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::endRefresh() {
QList<QModelIndex> oldIndices, newIndices;
int i;
QList<Item *>::iterator it;
// comment out as no subclass of TreeModel reimplement removeRows() for now
// and it causes assertion failure on calling beginRemoveRows() when deleting
// the last column in the xsheet
/*
2016-06-15 18:43:10 +12:00
for (i = m_itemsToDelete.size() - 1; i >= 0; i--) {
int row = m_itemsToDelete[i]->getRow();
Item *parentItem = m_itemsToDelete[i]->getParent();
QModelIndex parentIndex =
parentItem ? parentItem->createIndex() : QModelIndex();
beginRemoveRows(parentIndex, row, row);
removeRows(row, 1, parentIndex); // NOTE: This is currently doing NOTHING?
(see
2016-06-15 18:43:10 +12:00
// Qt's manual)
endRemoveRows();
}*/
2016-06-15 18:43:10 +12:00
qDeleteAll(m_itemsToDelete);
m_itemsToDelete.clear();
if (!persistentIndexList().empty()) {
for (i = 0; i < persistentIndexList().size(); i++) {
QModelIndex oldIndex = persistentIndexList()[i];
Item *item = static_cast<Item *>(oldIndex.internalPointer());
if (item) {
QModelIndex newIndex = item->createIndex();
if (oldIndex != newIndex) {
oldIndices.push_back(oldIndex);
newIndices.push_back(newIndex);
}
}
}
changePersistentIndexList(oldIndices, newIndices);
}
emit layoutChanged();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
int TreeModel::columnCount(const QModelIndex &parent) const { return 1; }
2016-03-19 06:57:51 +13:00
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const {
if (!index.isValid()) return Qt::ItemFlags();
2016-06-15 18:43:10 +12:00
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
QModelIndex TreeModel::index(int row, int column,
const QModelIndex &parent) const {
// column=!0 are not supported
if (column != 0) return QModelIndex();
Item *parentItem =
parent.isValid() ? (Item *)(parent.internalPointer()) : m_rootItem;
// if m_rootItem has not been defined yet. (It should not happen, but just in
// case)
if (!parentItem) return QModelIndex();
int childCount = parentItem->getChildCount();
if (row < 0 || row >= childCount) return QModelIndex();
Item *item = parentItem->getChild(row);
if (!item) return QModelIndex(); // it should never happen
return item->createIndex();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
QModelIndex TreeModel::parent(const QModelIndex &index) const {
if (!index.isValid()) return QModelIndex();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Item *item = (Item *)index.internalPointer();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TreeModel::Item *parentItem = item->getParent();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!parentItem || parentItem == m_rootItem) return QModelIndex();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return parentItem->createIndex();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
int TreeModel::rowCount(const QModelIndex &parent) const {
if (parent.column() > 0) return 0;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (!parent.isValid())
return m_rootItem ? m_rootItem->getChildCount() : 0;
else
return ((Item *)(parent.internalPointer()))->getChildCount();
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::onExpanded(const QModelIndex &index) {
if (!index.isValid()) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Item *item = (Item *)(index.internalPointer());
item->setIsOpen(true);
2016-03-19 06:57:51 +13:00
}
//---------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::onCollapsed(const QModelIndex &index) {
if (!index.isValid()) return;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Item *item = (Item *)(index.internalPointer());
item->setIsOpen(false);
2016-03-19 06:57:51 +13:00
}
//---------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
QVariant TreeModel::data(const QModelIndex &index, int role) const {
if (!index.isValid()) return QVariant();
Item *item = static_cast<Item *>(index.internalPointer());
return item->data(role);
2016-03-19 06:57:51 +13:00
}
//---------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::setRootItem(Item *rootItem) {
if (rootItem == m_rootItem) return;
delete m_rootItem;
m_rootItem = rootItem;
if (m_rootItem) m_rootItem->setModel(this);
2016-03-19 06:57:51 +13:00
}
// postpone freeing, so existing items can be referenced while refreshing.
void TreeModel::setRootItem_NoFree(Item *rootItem) {
if (rootItem == m_rootItem) return;
m_rootItem = rootItem;
if (m_rootItem) m_rootItem->setModel(this);
}
2016-03-19 06:57:51 +13:00
//---------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeModel::setRowHidden(int row, const QModelIndex &parent, bool hide) {
2020-04-17 19:02:53 +12:00
if (m_view) m_view->setRowHidden(row, parent, hide);
2016-03-19 06:57:51 +13:00
}
//====================================================================================================
// TreeView
//----------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
TreeView::TreeView(QWidget *parent) : QTreeView(parent), m_dragging(false) {
header()->hide();
setUniformRowHeights(true);
setIconSize(QSize(32, 32));
2016-03-19 06:57:51 +13:00
}
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
//! Resizes viewport to contents
void TreeView::resizeToConts(void) { resizeColumnToContents(0); }
2016-03-19 06:57:51 +13:00
//-----------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeView::resizeEvent(QResizeEvent *event) {
resizeColumnToContents(0);
QTreeView::resizeEvent(event);
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeView::setModel(TreeModel *model) {
QTreeView::setModel(model);
disconnect();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
connect(this, SIGNAL(expanded(const QModelIndex &)), model,
SLOT(onExpanded(const QModelIndex &)));
connect(this, SIGNAL(collapsed(const QModelIndex &)), model,
SLOT(onCollapsed(const QModelIndex &)));
// setItemDelegate(new Delegate(this));
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Connect all possible changes that can alter the
// bottom horizontal scrollbar to resize contents...
connect(this, SIGNAL(expanded(const QModelIndex &)), this,
SLOT(resizeToConts()));
connect(this, SIGNAL(collapsed(const QModelIndex &)), this,
SLOT(resizeToConts()));
connect(this->model(), SIGNAL(layoutChanged()), this, SLOT(resizeToConts()));
2016-03-19 06:57:51 +13:00
}
2016-06-15 18:43:10 +12:00
//----------------------------------------------------------------------------------------------------------------
void TreeView::mouseDoubleClickEvent(QMouseEvent *) {
// ignore double click!
}
void TreeView::mousePressEvent(QMouseEvent *e) {
if (e->button() != Qt::RightButton) QTreeView::mousePressEvent(e);
QModelIndex index = indexAt(e->pos());
if (index.isValid()) {
TreeModel::Item *item =
static_cast<TreeModel::Item *>(index.internalPointer());
QRect itemRect = visualRect(index);
QPoint itemPos = e->pos() - itemRect.topLeft();
if (e->button() == Qt::RightButton) {
if (selectionMode() != QAbstractItemView::ExtendedSelection)
setCurrentIndex(item->createIndex());
onClick(item, itemPos, e);
openContextMenu(item, e->globalPos());
} else if (e->button() == Qt::LeftButton) {
m_dragging = true;
setMouseTracking(true);
onClick(item, itemPos, e);
}
// for drag & drop
else if (e->button() == Qt::MiddleButton) {
2016-06-15 18:43:10 +12:00
m_dragging = true;
setMouseTracking(true);
onMidClick(item, itemPos, e);
}
}
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeView::mouseMoveEvent(QMouseEvent *e) {
QTreeView::mouseMoveEvent(e);
if (m_dragging) {
QModelIndex index = indexAt(e->pos());
if (index.isValid()) {
TreeModel::Item *item =
static_cast<TreeModel::Item *>(index.internalPointer());
QRect itemRect = visualRect(index);
QPoint itemPos = e->pos() - itemRect.topLeft();
onDrag(item, itemPos, e);
}
}
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void TreeView::mouseReleaseEvent(QMouseEvent *e) {
QTreeView::mouseReleaseEvent(e);
if (m_dragging) {
m_dragging = false;
setMouseTracking(false);
onRelease();
}
2016-03-19 06:57:51 +13:00
}
//----------------------------------------------------------------------------------------------------------------
/*
2016-06-15 18:43:10 +12:00
bool TreeView::Delegate::editorEvent(QEvent *e, QAbstractItemModel
*abstractModel, const QStyleOptionViewItem &option, const QModelIndex &index)
2016-03-19 06:57:51 +13:00
{
if(e->type() != QEvent::MouseButtonPress) return false;
TreeModel *model = dynamic_cast<TreeModel *>(abstractModel);
if(!model || !index.isValid()) return false;
2016-06-15 18:43:10 +12:00
TreeModel::Item *item = static_cast<TreeModel::Item
*>(index.internalPointer());
2016-03-19 06:57:51 +13:00
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(e);
QPoint pos = mouseEvent->pos();
2016-06-15 18:43:10 +12:00
m_treeView->onClick(item, pos, option);
2016-03-19 06:57:51 +13:00
return true;
}
*/