From fcace16d02968ea32a11314b476685c044bb2e74 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 6 Jul 2021 15:58:14 -0400 Subject: [PATCH] 2021-07-06 Fred Gleason * Modified the start buttons in rdcartslots(1) to display channel labels. Signed-off-by: Fred Gleason --- ChangeLog | 3 ++ lib/Makefile.am | 2 + lib/lib.pro | 2 + lib/rdcartslot.cpp | 7 +-- lib/rdcartslot.h | 5 +- lib/rdslotbutton.cpp | 122 ++++++++++++++++++++++++++++++++++++++++++ lib/rdslotbutton.h | 54 +++++++++++++++++++ lib/rdslotoptions.cpp | 41 ++++++++------ lib/rdslotoptions.h | 4 +- 9 files changed, 219 insertions(+), 21 deletions(-) create mode 100644 lib/rdslotbutton.cpp create mode 100644 lib/rdslotbutton.h diff --git a/ChangeLog b/ChangeLog index 96a8c017..509168a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22008,3 +22008,6 @@ 2021-07-06 Fred Gleason * Modified the sound panel buttons in rdpanel(1) to display channel labels when playing. +2021-07-06 Fred Gleason + * Modified the start buttons in rdcartslots(1) to display channel + labels. diff --git a/lib/Makefile.am b/lib/Makefile.am index 5a515d4a..f4301ee1 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -244,6 +244,7 @@ dist_librd_la_SOURCES = dbversion.h\ rdsimpleplayer.cpp rdsimpleplayer.h\ rdslider.cpp rdslider.h\ rdslotbox.cpp rdslotbox.h\ + rdslotbutton.cpp rdslotbutton.h\ rdslotdialog.cpp rdslotdialog.h\ rdslotoptions.cpp rdslotoptions.h\ rdsocket.cpp rdsocket.h\ @@ -410,6 +411,7 @@ nodist_librd_la_SOURCES = moc_rdadd_cart.cpp\ moc_rdsocket.cpp\ moc_rdsound_panel.cpp\ moc_rdslotbox.cpp\ + moc_rdslotbutton.cpp\ moc_rdslotdialog.cpp\ moc_rdstationlistmodel.cpp\ moc_rdstereometer.cpp\ diff --git a/lib/lib.pro b/lib/lib.pro index 1e214728..fe35ae5f 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -183,6 +183,7 @@ SOURCES += rdsettings.cpp SOURCES += rdservicelistmodel.cpp SOURCES += rdsimpleplayer.cpp SOURCES += rdslider.cpp +SOURCES += rdslotbutton.cpp SOURCES += rdsocket.cpp SOURCES += rdsocketstrings.cpp SOURCES += rdsound_panel.cpp @@ -370,6 +371,7 @@ HEADERS += rdservicelistmodel.h HEADERS += rdsettings.h HEADERS += rdsimpleplayer.h HEADERS += rdslider.h +HEADERS += rdslotbutton.h HEADERS += rdsocket.h HEADERS += rdsocketstrings.h HEADERS += rdsound_panel.h diff --git a/lib/rdcartslot.cpp b/lib/rdcartslot.cpp index 6050cfbb..a5909058 100644 --- a/lib/rdcartslot.cpp +++ b/lib/rdcartslot.cpp @@ -87,10 +87,13 @@ RDCartSlot::RDCartSlot(int slotnum,RDRipc *ripc,RDCae *cae,RDStation *station, // // Start Button // - slot_start_button=new QPushButton(QString().sprintf("%d",slotnum+1),this); + slot_start_button=new RDSlotButton(slotnum,this); + slot_start_button->setPortLabel(slot_options->outputPortLabel()); slot_start_button->setGeometry(0,0,sizeHint().height(),sizeHint().height()); slot_start_button->setFont(hugeButtonFont()); slot_start_button->setDisabled(true); + connect(slot_deck,SIGNAL(stateChanged(int,RDPlayDeck::State)), + slot_start_button,SLOT(setState(int,RDPlayDeck::State))); connect(slot_start_button,SIGNAL(clicked()),this,SLOT(startData())); // @@ -473,7 +476,6 @@ void RDCartSlot::stateChangedData(int id,RDPlayDeck::State state) LogPlayout(state); slot_start_button-> setEnabled(slot_options->mode()==RDSlotOptions::CartDeckMode); - slot_start_button->setPalette(slot_playing_color); slot_load_button->setDisabled(true); slot_options_button->setDisabled(true); break; @@ -483,7 +485,6 @@ void RDCartSlot::stateChangedData(int id,RDPlayDeck::State state) LogPlayout(state); slot_start_button-> setEnabled(slot_options->mode()==RDSlotOptions::CartDeckMode); - slot_start_button->setPalette(slot_ready_color); slot_load_button->setEnabled(true); slot_options_button->setEnabled(true); slot_box->setTimer(0); diff --git a/lib/rdcartslot.h b/lib/rdcartslot.h index 9debccbf..7ed6d5fe 100644 --- a/lib/rdcartslot.h +++ b/lib/rdcartslot.h @@ -2,7 +2,7 @@ // // The cart slot widget. // -// (C) Copyright 2012,2016 Fred Gleason +// (C) Copyright 2012-2021 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -78,7 +79,7 @@ class RDCartSlot : public RDWidget void SetInput(bool state); void LogPlayout(RDPlayDeck::State state); void ClearTempCart(); - QPushButton *slot_start_button; + RDSlotButton *slot_start_button; QPushButton *slot_load_button; QPushButton *slot_options_button; std::vector *slot_svc_names; diff --git a/lib/rdslotbutton.cpp b/lib/rdslotbutton.cpp new file mode 100644 index 00000000..f0f53aaf --- /dev/null +++ b/lib/rdslotbutton.cpp @@ -0,0 +1,122 @@ +// rdslotbutton.cpp +// +// Start/stop button for rdcartslots(1). +// +// (C) Copyright 2021 Fred Gleason +// +// 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 +#include + +#include "rdslotbutton.h" + +RDSlotButton::RDSlotButton(int slotnum,QWidget *parent,RDConfig *c) + : QPushButton(parent), RDFontEngine(c) +{ + d_slot_number=slotnum; + + // + // Palettes + // + d_ready_color= + QPalette(QColor(BUTTON_STOPPED_BACKGROUND_COLOR), + palette().color(QPalette::Background)); + d_playing_color= + QPalette(QColor(BUTTON_PLAY_BACKGROUND_COLOR), + palette().color(QPalette::Background)); + setFocusPolicy(Qt::NoFocus); +} + + +int RDSlotButton::slotNumber() const +{ + return d_slot_number; +} + + +QString RDSlotButton::portLabel() const +{ + return d_port_label; +} + + +void RDSlotButton::setState(int id,RDPlayDeck::State state) +{ + switch(state) { + case RDPlayDeck::Playing: + setPalette(d_playing_color); + WriteKeycap(); + break; + + case RDPlayDeck::Stopped: + case RDPlayDeck::Finished: + setPalette(d_ready_color); + WriteKeycap(); + break; + + case RDPlayDeck::Stopping: + case RDPlayDeck::Paused: + break; + } +} + + +void RDSlotButton::setPortLabel(const QString &str) +{ + if(str!=d_port_label) { + d_port_label=str; + WriteKeycap(); + } +} + + +void RDSlotButton::resizeEvent(QResizeEvent *e) +{ + setIconSize(QSize(size().width()-4,size().height()-4)); + WriteKeycap(); +} + + +void RDSlotButton::WriteKeycap() +{ + int w=size().width(); + int h=size().height(); + + QPixmap *pix=new QBitmap(w-4,h-4); + QPainter *p=new QPainter(pix); + p->setRenderHint(QPainter::Antialiasing,true); + p->setRenderHint(QPainter::SmoothPixmapTransform,true); + p->setPen(Qt::black); + p->setBrush(Qt::black); + p->fillRect(0,0,w,h,palette().color(QPalette::Background)); + + p->setFont(hugeButtonFont()); + p->drawText((w-p->fontMetrics().width(QString(). + sprintf("%d",1+d_slot_number)))/2, + p->fontMetrics().height(), + QString().sprintf("%d",1+d_slot_number)); + + p->setFont(bigLabelFont()); + p->drawText((w-p->fontMetrics().width(d_port_label))/2, + 3*h/4, + d_port_label); + + p->end(); + setIcon(*pix); + + delete p; + delete pix; +} diff --git a/lib/rdslotbutton.h b/lib/rdslotbutton.h new file mode 100644 index 00000000..90dd2978 --- /dev/null +++ b/lib/rdslotbutton.h @@ -0,0 +1,54 @@ +// rdslotbutton.h +// +// Start/stop button for rdcartslots(1). +// +// (C) Copyright 2021 Fred Gleason +// +// 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 RDSLOTBUTTON_H +#define RDSLOTBUTTON_H + +#include + +#include +#include + +class RDSlotButton : public QPushButton, public RDFontEngine +{ + Q_OBJECT + public: + RDSlotButton(int slotnum,QWidget *parent,RDConfig *c=NULL); + int slotNumber() const; + QString portLabel() const; + + public slots: + void setState(int id,RDPlayDeck::State state); + void setPortLabel(const QString &str); + + protected: + void resizeEvent(QResizeEvent *e); + + private: + void WriteKeycap(); + int d_slot_number; + RDPlayDeck::State d_dstate; + QString d_port_label; + QPalette d_ready_color; + QPalette d_playing_color; +}; + + +#endif // RDSLOTBUTTON_H diff --git a/lib/rdslotoptions.cpp b/lib/rdslotoptions.cpp index 6c947482..adc2a02a 100644 --- a/lib/rdslotoptions.cpp +++ b/lib/rdslotoptions.cpp @@ -130,6 +130,12 @@ int RDSlotOptions::outputPort() const } +QString RDSlotOptions::outputPortLabel() const +{ + return set_output_port_label; +} + + bool RDSlotOptions::load() { bool ret=false; @@ -137,21 +143,25 @@ bool RDSlotOptions::load() RDSqlQuery *q; sql=QString("select ")+ - "`CARD`,"+ // 00 - "`INPUT_PORT`,"+ // 01 - "`OUTPUT_PORT`,"+ // 02 - "`MODE`,"+ // 03 - "`DEFAULT_MODE`,"+ // 04 - "`HOOK_MODE`,"+ // 05 - "`DEFAULT_HOOK_MODE`,"+ // 06 - "`STOP_ACTION`,"+ // 07 - "`DEFAULT_STOP_ACTION`,"+ // 08 - "`CART_NUMBER`,"+ // 09 - "`DEFAULT_CART_NUMBER`,"+ // 10 - "`SERVICE_NAME` "+ // 11 - "from `CARTSLOTS` where "+ - "(`STATION_NAME`='"+RDEscapeString(set_stationname)+"')&&"+ - QString().sprintf("(`SLOT_NUMBER`=%u)",set_slotno); + "`CARTSLOTS`.`CARD`,"+ // 00 + "`CARTSLOTS`.`INPUT_PORT`,"+ // 01 + "`CARTSLOTS`.`OUTPUT_PORT`,"+ // 02 + "`CARTSLOTS`.`MODE`,"+ // 03 + "`CARTSLOTS`.`DEFAULT_MODE`,"+ // 04 + "`CARTSLOTS`.`HOOK_MODE`,"+ // 05 + "`CARTSLOTS`.`DEFAULT_HOOK_MODE`,"+ // 06 + "`CARTSLOTS`.`STOP_ACTION`,"+ // 07 + "`CARTSLOTS`.`DEFAULT_STOP_ACTION`,"+ // 08 + "`CARTSLOTS`.`CART_NUMBER`,"+ // 09 + "`CARTSLOTS`.`DEFAULT_CART_NUMBER`,"+ // 10 + "`CARTSLOTS`.`SERVICE_NAME`,"+ // 11 + "`AUDIO_OUTPUTS`.`LABEL` "+ // 12 + "from `CARTSLOTS` left join `AUDIO_OUTPUTS` "+ + "on `CARTSLOTS`.`OUTPUT_PORT`=`AUDIO_OUTPUTS`.`PORT_NUMBER` where "+ + "`AUDIO_OUTPUTS`.`STATION_NAME`='"+RDEscapeString(set_stationname)+"' && "+ + "`AUDIO_OUTPUTS`.`CARD_NUMBER`=`CARTSLOTS`.`CARD` && "+ + "`AUDIO_OUTPUTS`.`PORT_NUMBER`=`CARTSLOTS`.`OUTPUT_PORT` && "+ + QString().sprintf("`CARTSLOTS`.`SLOT_NUMBER`=%u",set_slotno); q=new RDSqlQuery(sql); if(q->first()) { ret=true; @@ -162,6 +172,7 @@ bool RDSlotOptions::load() set_card=q->value(0).toInt(); set_input_port=q->value(1).toInt(); set_output_port=q->value(2).toInt(); + set_output_port_label=q->value(12).toString(); // // Mode diff --git a/lib/rdslotoptions.h b/lib/rdslotoptions.h index 27164385..4c54dc34 100644 --- a/lib/rdslotoptions.h +++ b/lib/rdslotoptions.h @@ -2,7 +2,7 @@ // // Container class for RDCartSlot options // -// (C) Copyright 2012,2016 Fred Gleason +// (C) Copyright 2012-2021 Fred Gleason // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -42,6 +42,7 @@ class RDSlotOptions int card() const; int inputPort() const; int outputPort() const; + QString outputPortLabel() const; bool load(); void save() const; void clear(); @@ -57,6 +58,7 @@ class RDSlotOptions int set_card; int set_input_port; int set_output_port; + QString set_output_port_label; QString set_stationname; unsigned set_slotno; };