2021-09-12 Fred Gleason <fredg@paravelsystems.com>

* Added an 'RDBiPushButton' widget.
	* Modified the behavior of the buttons in the 'Edit Cart' dialog in
	rdlibrary(1) to grey-out when there is no cut selected.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-09-12 17:10:11 -04:00
parent ce2321c2c9
commit 76548116e5
7 changed files with 215 additions and 36 deletions

View File

@ -22413,3 +22413,7 @@
2021-09-12 Fred Gleason <fredg@paravelsystems.com>
* Fixed a regression in rdlibrary(1) that caused the first cut to
fail to be selected automatically when creating a new cart.
2021-09-12 Fred Gleason <fredg@paravelsystems.com>
* Added an 'RDBiPushButton' widget.
* Modified the behavior of the buttons in the 'Edit Cart' dialog in
rdlibrary(1) to grey-out when there is no cut selected.

View File

@ -67,6 +67,7 @@ dist_librd_la_SOURCES = dbversion.h\
rdaudioinfo.cpp rdaudioinfo.h\
rdaudiosettings.cpp rdaudiosettings.h\
rdaudiostore.cpp rdaudiostore.h\
rdbipushbutton.cpp rdbipushbutton.h\
rdbusybar.cpp rdbusybar.h\
rdbusydialog.cpp rdbusydialog.h\
rdbutton_dialog.cpp rdbutton_dialog.h\
@ -301,6 +302,7 @@ nodist_librd_la_SOURCES = moc_rdadd_cart.cpp\
moc_rdaudioimport.cpp\
moc_rdaudioinfo.cpp\
moc_rdaudiostore.cpp\
moc_rdbipushbutton.cpp\
moc_rdbusybar.cpp\
moc_rdbusydialog.cpp\
moc_rdbutton_dialog.cpp\

View File

@ -1,4 +1,4 @@
# lib.pro
# librd.pro
#
# The lib/ QMake project file for Rivendell.
#
@ -44,6 +44,7 @@ SOURCES += rdapplication.cpp
SOURCES += rdaudio_exists.cpp
SOURCES += rdaudio_port.cpp
SOURCES += rdaudiosettings.cpp
SOURCES += rdbipushbutton.cpp
SOURCES += rdbusybar.cpp
SOURCES += rdbusydialog.cpp
SOURCES += rdbutton_dialog.cpp
@ -228,6 +229,7 @@ HEADERS += rdapplication.h
HEADERS += rdaudio_exists.h
HEADERS += rdaudio_port.h
HEADERS += rdaudiosettings.h
HEADERS += rdbipushbutton.h
HEADERS += rdbusybar.h
HEADERS += rdbusydialog.h
HEADERS += rdbutton_dialog.h

98
lib/rdbipushbutton.cpp Normal file
View File

@ -0,0 +1,98 @@
// rdbipushbutton.cpp
//
// QPushButton with a two-part legend
//
// (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License
// version 2 as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <QEvent>
#include <QPainter>
#include "rdbipushbutton.h"
RDBiPushButton::RDBiPushButton(QWidget *parent,RDConfig *c)
: QPushButton(parent), RDFontEngine(font(),c)
{
}
RDBiPushButton::RDBiPushButton(const QString &top_text,
const QString &bottom_text,QWidget *parent,
RDConfig *c)
: QPushButton(parent), RDFontEngine(font(),c)
{
d_top_text=top_text;
d_bottom_text=bottom_text;
}
QString RDBiPushButton::topText() const
{
return d_top_text;
}
void RDBiPushButton::setTopText(const QString &str)
{
d_top_text=str;
update();
}
QString RDBiPushButton::bottomText() const
{
return d_bottom_text;
}
void RDBiPushButton::setBottomText(const QString &str)
{
d_bottom_text=str;
update();
}
void RDBiPushButton::changeEvent(QEvent *e)
{
if(e->type()==QEvent::EnabledChange) {
update();
e->accept();
}
}
void RDBiPushButton::paintEvent(QPaintEvent *e)
{
int w=size().width();
int h=size().height();
QFontMetrics *m=buttonFontMetrics();
QPushButton::paintEvent(e);
QPainter *p=new QPainter(this);
if(isEnabled()) {
p->setPen(palette().color(QPalette::Inactive,QPalette::ButtonText));
}
else {
p->setPen(palette().color(QPalette::Disabled,QPalette::ButtonText));
}
p->setFont(buttonFont());
p->drawText((w-m->width(d_top_text))/2,h/2-5,d_top_text);
p->drawLine(10,h/2,w-10,h/2);
p->drawText((w-m->width(d_bottom_text))/2,h/2+m->height(),d_bottom_text);
p->end();
delete p;
}

50
lib/rdbipushbutton.h Normal file
View File

@ -0,0 +1,50 @@
// rdbipushbutton.h
//
// QPushButton with a two-part legend
//
// (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License
// version 2 as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef RDBIPUSHBUTTON_H
#define RDBIPUSHBUTTON_H
#include <QPushButton>
#include <rdfontengine.h>
class RDBiPushButton : public QPushButton, public RDFontEngine
{
Q_OBJECT
public:
RDBiPushButton(QWidget *parent,RDConfig *c=NULL);
RDBiPushButton(const QString &top_text,const QString &bottom_text,
QWidget *parent,RDConfig *c=NULL);
QString topText() const;
void setTopText(const QString &str);
QString bottomText() const;
void setBottomText(const QString &str);
protected:
void changeEvent(QEvent *e);
void paintEvent(QPaintEvent *e);
private:
QString d_top_text;
QString d_bottom_text;
};
#endif // RDBIPUSHBUTTON_H

View File

@ -54,12 +54,10 @@ AudioCart::AudioCart(AudioControls *controls,RDCart *cart,QString *path,
new RDMarkerDialog("RDLibrary",rda->libraryConf()->outputCard(),
rda->libraryConf()->outputPort(),this);
QColor system_button_text_color = palette().buttonText().color();
//
// Add Cut Button
//
QPushButton *add_cut_button=new QPushButton(this);
add_cut_button=new QPushButton(this);
add_cut_button->setGeometry(10,0,80,50);
add_cut_button->setFont(buttonFont());
add_cut_button->setText(tr("Add"));
@ -68,7 +66,7 @@ AudioCart::AudioCart(AudioControls *controls,RDCart *cart,QString *path,
//
// Delete Cut Button
//
QPushButton *delete_cut_button=new QPushButton(this);
delete_cut_button=new QPushButton(this);
delete_cut_button->setGeometry(10,60,80,50);
delete_cut_button->setFont(buttonFont());
delete_cut_button->setText(tr("Delete"));
@ -77,7 +75,7 @@ AudioCart::AudioCart(AudioControls *controls,RDCart *cart,QString *path,
//
// Copy Cut Button
//
QPushButton *copy_cut_button=new QPushButton(this);
copy_cut_button=new QPushButton(this);
copy_cut_button->setGeometry(10,120,80,50);
copy_cut_button->setFont(buttonFont());
copy_cut_button->setText(tr("Copy"));
@ -105,26 +103,16 @@ AudioCart::AudioCart(AudioControls *controls,RDCart *cart,QString *path,
//
// Record Cut Button
//
QPixmap *pix=new QPixmap(QSize(70,40));
QPainter *p=new QPainter(pix);
QFontMetrics *m=new QFontMetrics(buttonFont());
p->fillRect(0,0,70,40,palette().color(QPalette::Active,QPalette::Button));
p->setPen(QColor(system_button_text_color));
p->setFont(buttonFont());
p->drawText((70-m->width(tr("Cut Info")))/2,15,tr("Cut Info"));
p->drawLine(10,19,60,19);
p->drawText((70-m->width(tr("Record")))/2,33,tr("Record"));
p->end();
QPushButton *record_cut_button=new QPushButton(this);
record_cut_button=
new RDBiPushButton(tr("Cut Info"),tr("Record"),this,rda->config());
record_cut_button->setGeometry(550,0,80,50);
record_cut_button->setIconSize(QSize(78,48));
record_cut_button->setIcon(*pix);
record_cut_button->setFont(buttonFont());
connect(record_cut_button,SIGNAL(clicked()),this,SLOT(recordCutData()));
//
// Send to (external) Editor Button (ex: Audacity)
//
QPushButton *ext_editor_cut_button=new QPushButton(this);
ext_editor_cut_button=new QPushButton(this);
ext_editor_cut_button->setGeometry(550,60,80,50);
ext_editor_cut_button->setFont(buttonFont());
ext_editor_cut_button->setText(tr("Edit\nAudio"));
@ -140,7 +128,7 @@ AudioCart::AudioCart(AudioControls *controls,RDCart *cart,QString *path,
//
// Edit Cut Button
//
QPushButton *edit_cut_button=new QPushButton(this);
edit_cut_button=new QPushButton(this);
edit_cut_button->setGeometry(550,60+yoffset,80,50);
edit_cut_button->setFont(buttonFont());
edit_cut_button->setText(tr("Edit\nMarkers"));
@ -149,25 +137,16 @@ AudioCart::AudioCart(AudioControls *controls,RDCart *cart,QString *path,
//
// Import Cut Button
//
p=new QPainter(pix);
m=new QFontMetrics(buttonFont());
p->fillRect(0,0,70,40,palette().color(QPalette::Active,QPalette::Button));
p->setPen(QColor(system_button_text_color));
p->setFont(buttonFont());
p->drawText((70-m->width(tr("Import")))/2,15,tr("Import"));
p->drawLine(10,19,60,19);
p->drawText((70-m->width(tr("Export")))/2,33,tr("Export"));
p->end();
QPushButton *import_cut_button=new QPushButton(this);
import_cut_button->setIcon(*pix);
import_cut_button->setIconSize(QSize(78,48));
import_cut_button=
new RDBiPushButton(tr("Import"),tr("Export"),this,rda->config());
import_cut_button->setGeometry(550,120+yoffset,80,50);
import_cut_button->setFont(buttonFont());
connect(import_cut_button,SIGNAL(clicked()),this,SLOT(importCutData()));
//
// Rip Cut Button
//
QPushButton *rip_cut_button=new QPushButton(this);
rip_cut_button=new QPushButton(this);
rip_cut_button->setGeometry(550,180+yoffset,80,50);
rip_cut_button->setFont(buttonFont());
rip_cut_button->setText(tr("Rip CD"));
@ -221,6 +200,12 @@ void AudioCart::changeCutScheduling(int sched)
rdcart_cut_model->setCartNumber(rdcart_cart->number());
rdcart_cut_view->setModel(rdcart_cut_model);
rdcart_cut_view->resizeColumnsToContents();
connect(rdcart_cut_view->selectionModel(),
SIGNAL(selectionChanged(const QItemSelection &,
const QItemSelection &)),
this,
SLOT(selectionChangedData(const QItemSelection &,
const QItemSelection &)));
if(old_model==NULL) { // Set default cut selection
if(rdcart_cut_model->rowCount()>0) {
@ -244,6 +229,8 @@ void AudioCart::changeCutScheduling(int sched)
}
rdcart_use_weighting=sched!=0;
UpdateButtons();
}
@ -495,6 +482,13 @@ void AudioCart::doubleClickedData(const QModelIndex &index)
}
void AudioCart::selectionChangedData(const QItemSelection &before,
const QItemSelection &after)
{
UpdateButtons();
}
void AudioCart::ripCutData()
{
int track;
@ -626,6 +620,24 @@ void AudioCart::importCutData()
}
void AudioCart::UpdateButtons()
{
QModelIndex row=SingleSelectedLine();
add_cut_button->setEnabled(rdcart_modification_allowed);
delete_cut_button->setEnabled(row.isValid()&&rdcart_modification_allowed);
copy_cut_button->setEnabled(row.isValid());
paste_cut_button->
setEnabled(row.isValid()&&(cut_clipboard!=NULL)&&
rdcart_modification_allowed);
record_cut_button->setEnabled(row.isValid());
ext_editor_cut_button->setEnabled(row.isValid()&&rdcart_modification_allowed);
edit_cut_button->setEnabled(row.isValid());
import_cut_button->setEnabled(row.isValid()&&rdcart_modification_allowed);
rip_cut_button->setEnabled(row.isValid()&&rdcart_modification_allowed);
}
QModelIndex AudioCart::SingleSelectedLine() const
{
if(rdcart_cut_view->selectionModel()->selectedRows().size()!=1) {

View File

@ -21,6 +21,7 @@
#ifndef AUDIO_CART_H
#define AUDIO_CART_H
#include <rdbipushbutton.h>
#include <rdcart.h>
#include <rdcutlistmodel.h>
#include <rdmarkerdialog.h>
@ -54,6 +55,8 @@ class AudioCart : public RDWidget
void editCutData();
void recordCutData();
void doubleClickedData(const QModelIndex &index);
void selectionChangedData(const QItemSelection &before,
const QItemSelection &after);
void ripCutData();
void importCutData();
@ -68,6 +71,7 @@ class AudioCart : public RDWidget
void audioChanged();
private:
void UpdateButtons();
QModelIndex SingleSelectedLine() const;
RDCart *rdcart_cart;
RDTableView *rdcart_cut_view;
@ -76,12 +80,19 @@ class AudioCart : public RDWidget
QString *rdcart_import_path;
bool rdcart_new_cart;
AudioControls *rdcart_controls;
QPushButton *add_cut_button;
QPushButton *delete_cut_button;
QPushButton *copy_cut_button;
QPushButton *paste_cut_button;
RDBiPushButton *record_cut_button;
QPushButton *ext_editor_cut_button;
QPushButton *edit_cut_button;
QPushButton *import_cut_button;
QPushButton *rip_cut_button;
bool rdcart_modification_allowed;
bool rdcart_import_metadata;
bool rdcart_profile_rip;
bool rdcart_use_weighting;
RDMarkerDialog *rdcart_marker_dialog;
};