예제 #1
0
void ScrollBar::onCreate(const ScrollBar * Id)
{
	Inherited::onCreate(Id);

    DefaultBoundedRangeModelUnrecPtr TheModel(DefaultBoundedRangeModel::create());
    setRangeModel(TheModel);

    if(Id != NULL)
    {
        if(Id->getVerticalMinButton() != NULL &&
            Id->getVerticalMaxButton() != NULL &&
            Id->getVerticalScrollBar() != NULL &&
            Id->getVerticalScrollField() != NULL)
        {
            FieldContainerUnrecPtr TempPtr(Id->getVerticalMinButton()->shallowCopy());
            setVerticalMinButton(dynamic_pointer_cast<Button>(TempPtr));

            TempPtr = Id->getVerticalMaxButton()->shallowCopy();
            setVerticalMaxButton(dynamic_pointer_cast<Button>(TempPtr));

            TempPtr = Id->getVerticalScrollBar()->shallowCopy();
            setVerticalScrollBar(dynamic_pointer_cast<Button>(TempPtr));

            TempPtr = Id->getVerticalScrollField()->shallowCopy();
            setVerticalScrollField(dynamic_pointer_cast<Button>(TempPtr));
        }
        
        if(Id->getHorizontalMinButton() != NULL &&
            Id->getHorizontalMaxButton() != NULL &&
            Id->getHorizontalScrollBar() != NULL &&
            Id->getHorizontalScrollField() != NULL)
        {
            FieldContainerUnrecPtr TempPtr(Id->getHorizontalMinButton()->shallowCopy());
            setHorizontalMinButton(dynamic_pointer_cast<Button>(TempPtr));

            TempPtr = Id->getHorizontalMaxButton()->shallowCopy();
            setHorizontalMaxButton(dynamic_pointer_cast<Button>(TempPtr));

            TempPtr = Id->getHorizontalScrollBar()->shallowCopy();
            setHorizontalScrollBar(dynamic_pointer_cast<Button>(TempPtr));

            TempPtr = Id->getHorizontalScrollField()->shallowCopy();
            setHorizontalScrollField(dynamic_pointer_cast<Button>(TempPtr));
        }
    }
}
예제 #2
0
KNMusicTreeViewBase::KNMusicTreeViewBase(QWidget *parent, KNMusicTab *tab) :
    QTreeView(parent),
    m_musicTab(tab),
    m_mouseAnime(new QTimeLine(200, this)),
    m_proxyModel(nullptr),
    m_hScrollBar(new QScrollBar(Qt::Horizontal, this)),
    m_vScrollBar(new QScrollBar(Qt::Vertical, this)),
    m_dragMoveRow(-1),
    m_dragIndicatorPos(QAbstractItemView::OnViewport),
    m_initialLoad(true),
    m_pressed(false),
    m_notAcceptDragMove(false)
{
    //Set properties.
    setAllColumnsShowFocus(true);
    setAlternatingRowColors(false); //We will use our own alternating drawing.
    setContentsMargins(0, 0, 0, 0);
    setDragDropMode(QAbstractItemView::InternalMove);
    setDragEnabled(true);
    setDropIndicatorShown(true);
    setFrameShape(QFrame::NoFrame);
    setIndentation(0);
    setMouseTracking(true);
    setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
    setSelectionBehavior(QAbstractItemView::SelectRows);
    setSelectionMode(QAbstractItemView::ExtendedSelection);
    setUniformRowHeights(true);
    setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    //Set scroll bar policies.
    horizontalScrollBar()->setSingleStep(5);
    horizontalScrollBar()->setPageStep(5);
    verticalScrollBar()->setSingleStep(4);
    verticalScrollBar()->setPageStep(4);
    //Configure the horizontal scroll bar.
    m_hScrollBar->setObjectName("MusicScrollBar");
    m_hScrollBar->setStyle(KNSaoStyle::instance());
    m_hScrollBar->hide();
    m_hScrollBar->setFixedHeight(ScrollBarWidth);
    knTheme->registerWidget(m_hScrollBar);
    setHorizontalScrollBar(m_hScrollBar);
    //Configure the vertical scroll bar.
    m_vScrollBar->setObjectName("MusicScrollBar");
    m_vScrollBar->setStyle(KNSaoStyle::instance());
    m_vScrollBar->hide();
    knTheme->registerWidget(m_vScrollBar);
    connect(verticalScrollBar(), &QScrollBar::rangeChanged,
            [=](int min, int max)
            {
                //Update the range first.
                m_vScrollBar->setRange(min, max);
                //Check whether the scroll bar is still valid.
                m_vScrollBar->setVisible(min!=max);
                //Update scrollbar state parameters.
                m_vScrollBar->setPageStep(verticalScrollBar()->pageStep());
                m_vScrollBar->setSingleStep(verticalScrollBar()->singleStep());
                //Update the geometry.
                updateVerticalScrollBarGeometry();
            });
    connect(verticalScrollBar(), &QScrollBar::valueChanged,
            [=](int value)
            {
                //Block the signal.
                m_vScrollBar->blockSignals(true);
                //Reset the value.
                m_vScrollBar->setValue(value);
                //Release the block
                m_vScrollBar->blockSignals(false);
            });
    connect(m_vScrollBar, &QScrollBar::valueChanged,
            verticalScrollBar(), &QScrollBar::setValue);

    //Configure the time line.
    m_mouseAnime->setEasingCurve(QEasingCurve::OutCubic);
    m_mouseAnime->setUpdateInterval(10);
    //Link the time line.
    connect(m_mouseAnime, &QTimeLine::frameChanged,
            this, &KNMusicTreeViewBase::onActionMouseInOut);

    //Generate the music tree view animation header.
    KNMusicTreeViewHeader *header=new KNMusicTreeViewHeader(this);
    //Link the reqirement.
    connect(header, &KNMusicTreeViewHeader::requireResizeColumnToContents,
            this, &KNMusicTreeViewBase::resizeColumnToContents);
    //Set the header view.
    setHeader(header);

    //Set the rating delegate for Rating and AlbumRating row.
    setItemDelegateForColumn(Rating,
                             new KNMusicRatingDelegate(this));
    setItemDelegateForColumn(AlbumRating,
                             new KNMusicRatingDelegate(this));

    //Set the search shortcut.
    QAction *searchAction=new QAction(this);
    searchAction->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_F));
    searchAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
    connect(searchAction, &QAction::triggered,
            [=]
            {
                //Check whether the search plugin is loaded.
                if(knMusicGlobal->search())
                {
                    knMusicGlobal->search()->onActionSearchShortcut(this);
                }
            });
    addAction(searchAction);

    //Link the tree view signal and slot.
    connect(this, &KNMusicTreeViewBase::activated,
            this, &KNMusicTreeViewBase::onActionActivate);

    //Link with theme manager.
    connect(knTheme, &KNThemeManager::themeChange,
            this, &KNMusicTreeViewBase::onActionThemeUpdate);
}