106 lines
2.5 KiB
C++
106 lines
2.5 KiB
C++
/***************************************************************************
|
|
|
|
source::worx raDIYo
|
|
Copyright © 2020-2022 c.holzheuer
|
|
chris@sourceworx.org
|
|
|
|
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 <QDebug>
|
|
#include <QPainter>
|
|
#include <QStandardPaths>
|
|
#include <QDir>
|
|
#include <QTextStream>
|
|
|
|
#include <swlistcontrol.h>
|
|
|
|
|
|
SWListControl::SWListControl( QWidget* parent, QSettings* settings )
|
|
: SWBaseControl( parent, settings ), _checkedID( 0 )
|
|
|
|
{
|
|
|
|
Ui_SWListControl::setupUi( this );
|
|
_contentView->setFocus();
|
|
// ListControls können auch per DIAL gesteuert werden.
|
|
setAcceptDial( true );
|
|
|
|
// Scrollbars sind Ihh-Bä
|
|
_contentView->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
|
|
|
|
// 'innere' SIGNALS einsammeln ...
|
|
// click
|
|
connect( _contentView, SIGNAL( itemClicked(QListWidgetItem*) ), this, SLOT( onItemActivated(QListWidgetItem*) ) );
|
|
// doublelcick, 'enter'
|
|
connect( _contentView, SIGNAL( itemActivated(QListWidgetItem*) ), this, SLOT( onItemActivated(QListWidgetItem*) ) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief Standard-Destruktor
|
|
*/
|
|
|
|
SWListControl::~SWListControl()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* kommt von aussen vom RotaryDial
|
|
*/
|
|
|
|
void SWListControl::onDialPushed()
|
|
{
|
|
QListWidgetItem* item = _contentView->item( _checkedID );
|
|
// das schickt ein SIGNAL, wann kommt das zurück?
|
|
onItemActivated( item );
|
|
}
|
|
|
|
|
|
/**
|
|
* kommt von aussen vom RotaryDial
|
|
*/
|
|
|
|
void SWListControl::onDialDeltaChanged( int delta )
|
|
{
|
|
if( 0 == _contentView->count() )
|
|
return;
|
|
_checkedID = ( _checkedID + delta ) % _contentView->count();
|
|
if( _checkedID < 0 )
|
|
_checkedID = _contentView->count() - 1;
|
|
_contentView->setCurrentRow( _checkedID, QItemSelectionModel::ClearAndSelect );
|
|
}
|
|
|
|
|
|
/**
|
|
* kommt von innen
|
|
*/
|
|
|
|
void SWListControl::onItemActivated( QListWidgetItem* item )
|
|
{
|
|
QString urltext = item->data( SWListControlRole ).toString();
|
|
SWUrl entry( item->text(), urltext );
|
|
_checkedID = _contentView->currentRow();
|
|
emit entryActivated( entry );
|
|
|
|
}
|
|
|
|
|
|
QListWidgetItem& SWListControl::createItem( const QString& title, const QString& body )
|
|
{
|
|
QListWidgetItem* item = new QListWidgetItem( title, _contentView );
|
|
item->setData( SWListControlRole, body );
|
|
|
|
return *item;
|
|
}
|