"Fossies" - the Fresh Open Source Software Archive

Member "MP3Diags-unstable-1.5.01/src/NoteFilterDlgImpl.cpp" (10 Feb 2019, 10137 Bytes) of package /linux/privat/MP3Diags-unstable-1.5.01.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "NoteFilterDlgImpl.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.3.04_vs_1.5.01.

    1 /***************************************************************************
    2  *   MP3 Diags - diagnosis, repairs and tag editing for MP3 files          *
    3  *                                                                         *
    4  *   Copyright (C) 2009 by Marian Ciobanu                                  *
    5  *   ciobi@inbox.com                                                       *
    6  *                                                                         *
    7  *   This program is free software; you can redistribute it and/or modify  *
    8  *   it under the terms of the GNU General Public License version 2 as     *
    9  *   published by the Free Software Foundation.                            *
   10  *                                                                         *
   11  *   This program is distributed in the hope that it will be useful,       *
   12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
   13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
   14  *   GNU General Public License for more details.                          *
   15  *                                                                         *
   16  *   You should have received a copy of the GNU General Public License     *
   17  *   along with this program; if not, write to the                         *
   18  *   Free Software Foundation, Inc.,                                       *
   19  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
   20  ***************************************************************************/
   21 
   22 #include  <algorithm>
   23 
   24 #include  <QAction>
   25 
   26 #include  "NoteFilterDlgImpl.h"
   27 
   28 #include  "Helpers.h"
   29 #include  "StoredSettings.h"
   30 #include  "CommonData.h"
   31 
   32 using namespace std;
   33 using namespace pearl;
   34 
   35 
   36 
   37 //=====================================================================================================================
   38 //=====================================================================================================================
   39 //=====================================================================================================================
   40 
   41 
   42 /*override*/ std::string NoteListElem::getText(int nCol) const
   43 {
   44     if (0 == nCol)
   45     {
   46         //return m_pCommonData->getNoteLabel(m_pNote).toUtf8().constData();
   47         return convStr(getNoteLabel(m_pNote));
   48     }
   49     return convStr(Notes::tr(m_pNote->getDescription()));
   50 }
   51 
   52 
   53 
   54 
   55 //=====================================================================================================================
   56 //=====================================================================================================================
   57 //=====================================================================================================================
   58 
   59 
   60 NoteFilterDlgImpl::NoteFilterDlgImpl(CommonData* pCommonData, QWidget* pParent /* =0*/) :
   61         QDialog(pParent, getDialogWndFlags()),
   62         NoteListPainterBase(pCommonData, convStr(tr("<all notes>")))
   63 {
   64     TRACER("NoteFilterDlgImpl constr");
   65     setupUi(this);
   66 
   67     m_pListHldr->setLayout(new QHBoxLayout());
   68 
   69     for (int i = 0, n = pCommonData->getUniqueNotes().getCount(); i < n; ++i)
   70     {
   71         m_vpOrigAll.push_back(new NoteListElem(pCommonData->getUniqueNotes().get(i), m_pCommonData));
   72     }
   73 
   74     for (int i = 0, n = cSize(pCommonData->m_filter.getNotes()); i < n; ++i)
   75     {
   76         int k (pCommonData->getUniqueNotes().getPos(pCommonData->m_filter.getNotes()[i]));
   77         if (k >= 0)
   78         {
   79             m_vOrigSel.push_back(k);
   80         }
   81     }
   82 
   83     m_vSel = m_vOrigSel;
   84 
   85     m_pDoubleList = new DoubleList(
   86             *this,
   87             DoubleList::ADD_ALL | DoubleList::DEL_ALL | DoubleList::RESTORE_OPEN,
   88             DoubleList::SINGLE_UNSORTABLE,
   89             convStr(tr("Available notes")),
   90             convStr(tr("Include notes")),
   91             this);
   92 
   93     m_pListHldr->layout()->addWidget(m_pDoubleList);
   94     m_pListHldr->layout()->setContentsMargins(0, 0, 0, 0);
   95 
   96     int nWidth, nHeight;
   97     m_pCommonData->m_settings.loadNoteFilterSettings(nWidth, nHeight);
   98     if (nWidth > 400 && nHeight > 400)
   99     {
  100         resize(nWidth, nHeight);
  101     }
  102     else
  103     {
  104         defaultResize(*this);
  105     }
  106 
  107     connect(m_pDoubleList, SIGNAL(avlDoubleClicked(int)), this, SLOT(onAvlDoubleClicked(int)));
  108 
  109     { QAction* p (new QAction(this)); p->setShortcut(QKeySequence("F1")); connect(p, SIGNAL(triggered()), this, SLOT(onHelp())); addAction(p); }
  110 }
  111 
  112 
  113 NoteFilterDlgImpl::~NoteFilterDlgImpl()
  114 {
  115     clearPtrContainer(m_vpOrigAll);
  116 }
  117 
  118 
  119 
  120 void NoteFilterDlgImpl::logState(const char* /*szPlace*/) const
  121 {
  122     /*cout << szPlace << ": m_filter.m_vSelDirs=" << m_pCommonData->m_filter.m_vSelDirs.size() << " m_availableDirs.m_vstrDirs=" << m_availableDirs.m_vstrDirs.size() << " m_selectedDirs.m_vSelDirs=" << m_selectedDirs.m_vstrDirs.size() << endl;*/
  123 }
  124 
  125 
  126 
  127 
  128 //---------------------------------------------------------------------------------------------------------------------
  129 //---------------------------------------------------------------------------------------------------------------------
  130 
  131 void NoteFilterDlgImpl::on_m_pOkB_clicked()
  132 {
  133     //logState("on_m_pOkB_clicked 1");
  134     //m_pCommonData->m_filter.m_vpSelNotes = m_selectedNotes.m_vpNotes;
  135     vector<const Note*> v;
  136     //m_pCommonData->m_filter.m_vpSelNotes.clear();
  137     for (int i = 0, n = cSize(m_vSel); i < n; ++i)
  138     {
  139         const NoteListElem* p (dynamic_cast<const NoteListElem*>(m_vpOrigAll[m_vSel[i]]));
  140         CB_ASSERT(0 != p);
  141         v.push_back(p->getNote());
  142     }
  143     m_pCommonData->m_filter.setNotes(v); //ttt2 in other case changing a parent window before the modal dialog was closed led to incorrect resizing; however, here it seems OK
  144     //logState("on_m_pOkB_clicked 2");
  145     m_pCommonData->m_settings.saveNoteFilterSettings(width(), height());
  146     accept();
  147 }
  148 
  149 void NoteFilterDlgImpl::on_m_pCancelB_clicked()
  150 {
  151     reject();
  152 }
  153 
  154 
  155 void NoteFilterDlgImpl::onAvlDoubleClicked(int nRow)
  156 {
  157     //m_pCommonData->m_filter.m_vpSelNotes.clear();
  158     vector<const Note*> v;
  159     const NoteListElem* p (dynamic_cast<const NoteListElem*>(m_vpOrigAll[getAvailable()[nRow]]));
  160     CB_ASSERT(0 != p);
  161     v.push_back(p->getNote());
  162     m_pCommonData->m_filter.setNotes(v);
  163 
  164     accept();
  165 }
  166 
  167 
  168 //---------------------------------------------------------------------------------------------------------------------
  169 //---------------------------------------------------------------------------------------------------------------------
  170 
  171 
  172 
  173 /*override*/ string NoteFilterDlgImpl::getTooltip(TooltipKey eTooltipKey) const
  174 {
  175     switch (eTooltipKey)
  176     {
  177     case SELECTED_G: return "";//"Notes to be included";
  178     case AVAILABLE_G: return "";//"Available notes";
  179     case ADD_B: return convStr(tr("Add selected note(s)"));
  180     case DELETE_B: return convStr(tr("Remove selected note(s)"));
  181     case ADD_ALL_B: return convStr(tr("Add all notes"));
  182     case DELETE_ALL_B: return convStr(tr("Remove all notes"));
  183     case RESTORE_DEFAULT_B: return "";
  184     case RESTORE_OPEN_B: return convStr(tr("Restore lists to the configuration they had when the window was open"));
  185     default: CB_ASSERT(false);
  186     }
  187 }
  188 
  189 
  190 /*override*/ void NoteFilterDlgImpl::reset()
  191 {
  192     CB_ASSERT(false);
  193 }
  194 
  195 
  196 void NoteFilterDlgImpl::onHelp()
  197 {
  198     openHelp("170_note_filter.html");
  199 }
  200 
  201 
  202 
  203 //=====================================================================================================================
  204 //=====================================================================================================================
  205 //=====================================================================================================================
  206 
  207 
  208 /*override*/ std::string NoteListPainterBase::getColTitle(int nCol) const
  209 {
  210     switch (nCol)
  211     {
  212     case 0: return convStr(NoteFilterDlgImpl::tr("L"));
  213     case 1: return convStr(NoteFilterDlgImpl::tr("Note"));
  214     default: return "???";
  215     }
  216 }
  217 
  218 
  219 
  220 /*override*/ void NoteListPainterBase::getColor(int nIndex, int nColumn, bool bSubList, QColor& bckgColor, QColor& penColor, double& dGradStart, double& dGradEnd) const
  221 {
  222     //LAST_STEP("NoteListPainterBase::getColor()");
  223     const NoteListElem* p (dynamic_cast<const NoteListElem*>(getAll()[nIndex]));
  224     CB_ASSERT(0 != p);
  225     const Note* pNote (p->getNote());
  226 
  227     {
  228         const SubList& v (getAvailable());
  229         if (m_vpAvail.size() != v.size()) // !!! there's no need for a "dirty" flag; after the content of getAvailable() changes, a paint is executed, and when it gets here sizes will be different
  230         {
  231             m_vpAvail.clear();
  232             for (int i = 0; i < cSize(v); ++i)
  233             {
  234                 const NoteListElem* p (dynamic_cast<const NoteListElem*>(getAll()[v[i]]));
  235                 m_vpAvail.push_back(p->getNote());
  236             }
  237         }
  238     }
  239 
  240     {
  241         const SubList& v (getSel());
  242         if (m_vpSel.size() != v.size())
  243         {
  244             m_vpSel.clear();
  245             for (int i = 0; i < cSize(v); ++i)
  246             {
  247                 const NoteListElem* p (dynamic_cast<const NoteListElem*>(getAll()[v[i]]));
  248                 m_vpSel.push_back(p->getNote());
  249             }
  250         }
  251     }
  252 
  253     if (0 == nColumn)
  254     {
  255         if (Note::ERR == pNote->getSeverity())
  256         {
  257             penColor = ERROR_PEN_COLOR();
  258         }
  259         else if (Note::SUPPORT == pNote->getSeverity())
  260         {
  261             penColor = SUPPORT_PEN_COLOR();
  262         }
  263     }
  264 
  265     m_pCommonData->getNoteColor(*pNote, bSubList ? m_vpSel : m_vpAvail, bckgColor, dGradStart, dGradEnd);
  266 }
  267 
  268 
  269 // positive values are used for fixed widths, while negative ones are for "stretched"
  270 /*override*/ int NoteListPainterBase::getColWidth(int nCol) const
  271 {
  272     switch (nCol)
  273     {
  274     case 0: return CELL_WIDTH + 10;
  275     case 1: return -1;
  276     }
  277     CB_ASSERT(false);
  278 }
  279 
  280 
  281 /*override*/ int NoteListPainterBase::getHdrHeight() const
  282 {
  283     return CELL_HEIGHT;
  284 }
  285 
  286 
  287 /*override*/ Qt::Alignment NoteListPainterBase::getAlignment(int nCol) const
  288 {
  289     if (0 == nCol)
  290     {
  291         //return Qt::AlignTop | Qt::AlignHCenter;
  292         return Qt::AlignVCenter | Qt::AlignHCenter;
  293     }
  294     return Qt::AlignTop | Qt::AlignLeft;
  295 }
  296 
  297