summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Controls/TreeItem.h
blob: 8d4619df37d21e2c257c673db3f50d8959562eba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/****************************************************************************
**
** Copyright (C) 2002 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//==============================================================================
//	Prefix
//==============================================================================
#ifndef INCLUDED_TREE_ITEM_H
#define INCLUDED_TREE_ITEM_H 1

#pragma once

//==============================================================================
//	Includes
//==============================================================================
#include "FlowLayout.h"
#include "ToggleButton.h"
#include "TextEditInPlace.h"

#include <QPixmap>
//==============================================================================
//	Forwards
//==============================================================================
class CTreeControl;
class CRenderer;
class CSIcon;
class CTreeItem;
class CTest_TreeControl;

//=============================================================================
/**
 * Class encapsulating a single row in a tree control.  Manages the toggle, the
 * icon, and the name of the tree item.  When you create a tree item you must
 * associate it with a tree control.  Then you can specify it's parent when you
 * call AddItem( ).
 */
class CTreeItem : public QObject, public CFlowLayout
{
    Q_OBJECT
public:
    typedef std::vector<CTreeItem *> TItemList;

public:
    CTreeItem(CTreeControl *inTreeControl);
    virtual ~CTreeItem();

    DEFINE_OBJECT_COUNTER(CTreeItem)

    void Draw(CRenderer *inRenderer) override;

    void SetBackgroundColor(const ::CColor &inColor);
    ::CColor GetBackgroundColor();
    void SetTextColor(const ::CColor &inColor);
    void SetTextBGFocusColor(const ::CColor &inColor);

    void SetParentItem(CTreeItem *inParent);
    CTreeItem *GetParentItem();
    bool GetEditMode();

    virtual void SetIcon(const QString &inIcon,
                         const QString &inSelectedIcon);
    virtual void SetIcon(const QPixmap &inNormalIcon, const QPixmap &inSelectedIcon);
    void SetIsNameEditable(bool inIsEditable);
    virtual void SetText(const Q3DStudio::CString &inText);
    virtual Q3DStudio::CString GetText();
    virtual void OnNameChanged(CControl *inControl);
    void SetIndent(long inAmount, bool inIsRecursive);

    bool OnMouseDown(CPt inPoint, Qt::KeyboardModifiers inFlags) override;
    bool OnMouseDoubleClick(CPt inPoint, Qt::KeyboardModifiers inFlags) override;
    bool OnMouseRDown(CPt inPoint, Qt::KeyboardModifiers inFlags) override;

    bool IsExpanded();
    virtual void ToggleExpansion();
    virtual void Expand();
    virtual void Collapse();

    virtual void AddItem(CTreeItem *inItem, CTreeItem *inInsertBefore = nullptr);
    long GetNumChildItems();
    CTreeItem *GetChildItem(long inIndex);
    long GetChildTreeItemIndex(const CTreeItem *inChildItem) const;
    void GetItemIterator(TItemList::iterator &outListBegin, TItemList::iterator &outListEnd);
    void GetReverseItemIterator(TItemList::reverse_iterator &outListBegin,
                                TItemList::reverse_iterator &outListEnd);
    virtual bool IsContainer();
    bool IsRootItem();
    virtual void RemoveItem();
    void UpdateToggle();
    virtual void RemoveChildren();
    void RemoveFromList(CTreeItem *inItem);
    virtual void Detach();
    virtual CTreeItem *FindPrevSortSibling(CTreeItem *inChild);
    virtual CTreeItem *FindNextSortSibling(CTreeItem *inChild);

    bool IsSelected();
    virtual void SetSelected(bool inIsSelected);
    bool DeselectChildren();

    void SetVisibleSelection(bool inValue);
    bool GetVisibleSelection() const;
Q_SIGNALS:
    void SigToggle(CControl *);

protected:
    // Member Vars
    CTreeControl *m_TreeControl;
    CTreeItem *m_Parent;
    CToggleButton *m_Toggle;
    CTextEditInPlace *m_Name;
    CCommitDataListener *m_NameChangeListener;
    CSIcon *m_Icon;
    QPixmap m_NormalIcon;
    QPixmap m_SelectedIcon;
    TItemList m_ItemList;
    long m_ControlGap;
    long m_IndentLevel;
    long m_IndentSize;
    bool m_IsExpanded;
    bool m_IsSelected;
    bool m_ShowVisibleSelection;
    ::CColor m_Color;
    ::CColor m_TextColor;

    // Member Functions
    void CreateToggle();
    void OnToggleExpansion(CToggleButton *inButton, CButtonControl::EButtonState inState);
    void HideChildItems();
    void ShowChildItems();

private:
    /// Private because no one outside this class should be calling it; use AddItem( ) instead.
    void AddChild(CControl *inControl, CControl *inInsertBefore = nullptr) override;
};
#endif // INCLUDED_TREE_ITEM_H