📄 multimediadlg.cpp
字号:
/******************************************************************************\
* Technische Universitaet Darmstadt, Institut fuer Nachrichtentechnik
* Copyright (c) 2001
*
* Author(s):
* Volker Fischer
*
* 6/8/2005 Andrea Russo
* - save Journaline pages as HTML
*
******************************************************************************
*
* 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.
*
* 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
\******************************************************************************/
#include "MultimediaDlg.h"
MultimediaDlg::MultimediaDlg(CDRMReceiver* pNDRMR, QWidget* parent,
const char* name, bool modal, WFlags f) : pDRMRec(pNDRMR),
MultimediaDlgBase(parent, name, modal, f)
{
#ifdef _WIN32 /* This works only reliable under Windows :-( */
/* Get window geometry data from DRMReceiver module and apply it */
const QRect WinGeom(pDRMRec->GeomMultimediaDlg.iXPos,
pDRMRec->GeomMultimediaDlg.iYPos,
pDRMRec->GeomMultimediaDlg.iWSize,
pDRMRec->GeomMultimediaDlg.iHSize);
if (WinGeom.isValid() && !WinGeom.isEmpty() && !WinGeom.isNull())
setGeometry(WinGeom);
#else /* Under Linux only restore the size */
resize(pDRMRec->GeomMultimediaDlg.iWSize,
pDRMRec->GeomMultimediaDlg.iHSize);
#endif
/* Picture controls should be invisable. These controls are only used for
storing the resources */
PixmapFhGIIS->hide();
PixmapLogoJournaline->hide();
/* Set pictures in source factory */
QMimeSourceFactory::defaultFactory()->setImage("PixmapFhGIIS",
PixmapFhGIIS->pixmap()->convertToImage());
QMimeSourceFactory::defaultFactory()->setImage("PixmapLogoJournaline",
PixmapLogoJournaline->pixmap()->convertToImage());
/* Set FhG IIS text */
strFhGIISText = "<table><tr><td><img source=\"PixmapFhGIIS\"></td>"
"<td><font face=\"Courier\" size=\"-1\">Features NewsService "
"Journaline(R) decoder technology by Fraunhofer IIS, Erlangen, "
"Germany. For more information visit http://www.iis.fhg.de/dab"
"</font></td></tr></table>";
/* Set Journaline headline text */
strJournalineHeadText =
"<table><tr><td><img source=\"PixmapLogoJournaline\"></td>"
"<td><h2>NewsService Journaline" + QString(QChar(174)) /* (R) */ +
"</h2></td></tr></table>";
/* Set Menu ***************************************************************/
/* File menu ------------------------------------------------------------ */
pFileMenu = new QPopupMenu(this);
CHECK_PTR(pFileMenu);
pFileMenu->insertItem(tr("C&lear all"), this, SLOT(OnClearAll()),
CTRL+Key_X, 0);
pFileMenu->insertSeparator();
pFileMenu->insertItem(tr("&Save..."), this, SLOT(OnSave()), CTRL+Key_S, 1);
pFileMenu->insertItem(tr("Save &all..."), this, SLOT(OnSaveAll()),
CTRL+Key_A, 2);
pFileMenu->insertSeparator();
pFileMenu->insertItem(tr("&Close"), this, SLOT(close()), 0, 3);
/* Main menu bar -------------------------------------------------------- */
pMenu = new QMenuBar(this);
CHECK_PTR(pMenu);
pMenu->insertItem(tr("&File"), pFileMenu);
/* Now tell the layout about the menu */
MultimediaDlgBaseLayout->setMenuBar(pMenu);
/* Update time for color LED */
LEDStatus->SetUpdateTime(1000);
/* Init slide-show (needed for setting up vectors and indices) */
ClearAllSlideShow();
/* Init container and GUI */
InitApplication(pDRMRec->GetDataDecoder()->GetAppType());
/* Connect controls */
connect(PushButtonStepBack, SIGNAL(clicked()),
this, SLOT(OnButtonStepBack()));
connect(PushButtonStepForw, SIGNAL(clicked()),
this, SLOT(OnButtonStepForw()));
connect(PushButtonJumpBegin, SIGNAL(clicked()),
this, SLOT(OnButtonJumpBegin()));
connect(PushButtonJumpEnd, SIGNAL(clicked()),
this, SLOT(OnButtonJumpEnd()));
connect(TextBrowser, SIGNAL(textChanged()),
this, SLOT(OnTextChanged()));
connect(&Timer, SIGNAL(timeout()),
this, SLOT(OnTimer()));
}
MultimediaDlg::~MultimediaDlg()
{
/* Set window geometry data in DRMReceiver module */
QRect WinGeom = geometry();
pDRMRec->GeomMultimediaDlg.iXPos = WinGeom.x();
pDRMRec->GeomMultimediaDlg.iYPos = WinGeom.y();
pDRMRec->GeomMultimediaDlg.iHSize = WinGeom.height();
pDRMRec->GeomMultimediaDlg.iWSize = WinGeom.width();
}
void MultimediaDlg::InitApplication(CDataDecoder::EAppType eNewAppType)
{
/* Set internal parameter */
eAppType = eNewAppType;
/* Actual inits */
switch (eAppType)
{
case CDataDecoder::AT_MOTSLISHOW:
InitMOTSlideShow();
break;
case CDataDecoder::AT_JOURNALINE:
InitJournaline();
break;
default:
InitNotSupported();
break;
}
}
void MultimediaDlg::OnTextChanged()
{
/* Check, if the current text is a link ID or regular text */
if (TextBrowser->text().compare(TextBrowser->text().left(1), "<") != 0)
{
/* Save old ID */
NewIDHistory.Add(iCurJourObjID);
/* Set text to news ID text which was selected by the user */
iCurJourObjID = TextBrowser->text().toInt();
SetJournalineText();
/* Enable back button */
PushButtonStepBack->setEnabled(TRUE);
}
}
void MultimediaDlg::OnTimer()
{
CMOTObject NewPic;
QPixmap NewImage;
FILE* pFiBody;
int iCurNumPict;
/* Check out which application is transmitted right now */
CDataDecoder::EAppType eNewAppType =
pDRMRec->GetDataDecoder()->GetAppType();
if (eNewAppType != eAppType)
InitApplication(eNewAppType);
switch (eAppType)
{
case CDataDecoder::AT_MOTSLISHOW:
/* Poll the data decoder module for new picture */
if (pDRMRec->GetDataDecoder()->GetSlideShowPicture(NewPic) == TRUE)
{
/* Store received picture */
iCurNumPict = vecRawImages.Size();
vecRawImages.Add(NewPic);
/* If the last received picture was selected, automatically show
new picture */
if (iCurImagePos == iCurNumPict - 1)
{
iCurImagePos = iCurNumPict;
SetSlideShowPicture();
}
else
UpdateAccButtonsSlideShow();
}
break;
case CDataDecoder::AT_JOURNALINE:
SetJournalineText();
break;
}
}
void MultimediaDlg::ExtractJournalineBody(const int iCurJourID,
const _BOOLEAN bHTMLExport,
QString& strTitle, QString& strItems)
{
/* Get news from actual Journaline decoder */
CNews News;
pDRMRec->GetDataDecoder()->GetNews(iCurJourID, News);
/* Decode UTF-8 coding for title */
strTitle = QString().fromUtf8(QCString(News.sTitle.c_str()));
strItems = "";
for (int i = 0; i < News.vecItem.Size(); i++)
{
QString strCurItem;
if (bHTMLExport == FALSE)
{
/* Decode UTF-8 coding of this item text */
strCurItem = QString().fromUtf8(
QCString(News.vecItem[i].sText.c_str()));
}
else
{
/* In case of HTML export, do not decode UTF-8 coding */
strCurItem = News.vecItem[i].sText.c_str();
}
/* Replace \n by html command <br> */
strCurItem = strCurItem.replace(QRegExp("\n"), "<br>");
if (News.vecItem[i].iLink == JOURNALINE_IS_NO_LINK)
{
/* Only text, no link */
strItems += strCurItem + QString("<br>");
}
else if (News.vecItem[i].iLink == JOURNALINE_LINK_NOT_ACTIVE)
{
/* Un-ordered list item without link */
strItems += QString("<li>") + strCurItem + QString("</li>");
}
else
{
if (bHTMLExport == FALSE)
{
QString strLinkStr = QString().setNum(News.vecItem[i].iLink);
/* Un-ordered list item with link */
strItems += QString("<li><a href=\"") + strLinkStr +
QString("\">") + strCurItem +
QString("</a></li>");
/* Store link location in factory (stores ID) */
QMimeSourceFactory::defaultFactory()->
setText(strLinkStr, strLinkStr);
}
else
strItems += QString("<li>") + strCurItem + QString("</li>");
}
}
}
void MultimediaDlg::SetJournalineText()
{
/* Get title and body with html links */
QString strTitle("");
QString strItems("");
ExtractJournalineBody(iCurJourObjID, FALSE, strTitle, strItems);
/* Set html text. Standard design. The first character must be a "<". This
is used to identify whether normal text is displayed or an ID was set */
QString strAllText =
"<table>"
"<tr><th>" + strJournalineHeadText + "</th></tr>"
"<tr><td><hr></td></tr>" /* horizontial line */
"<tr><th>" + strTitle + "</th></tr>"
"<tr><td><ul type=\"square\">" + strItems + "</ul></td></tr>"
"<tr><td><hr></td></tr>" /* horizontial line */
"<tr><td>" + strFhGIISText + "</td></tr>"
"</table>";
/* Only update text browser if text has changed */
if (TextBrowser->text().compare(strAllText) != 0)
TextBrowser->setText(strAllText);
/* Enable / disable "save" menu item if title is present or not */
if (strTitle == "")
pFileMenu->setItemEnabled(1, FALSE);
else
pFileMenu->setItemEnabled(1, TRUE);
}
void MultimediaDlg::showEvent(QShowEvent* pEvent)
{
/* Activte real-time timer when window is shown */
Timer.start(GUI_CONTROL_UPDATE_TIME);
/* Update window */
OnTimer();
}
void MultimediaDlg::hideEvent(QHideEvent* pEvent)
{
/* Deactivate real-time timer so that it does not get new pictures */
Timer.stop();
}
void MultimediaDlg::SetStatus(int MessID, int iMessPara)
{
switch(MessID)
{
case MS_MOT_OBJ_STAT:
LEDStatus->SetLight(iMessPara);
break;
}
}
void MultimediaDlg::OnButtonStepBack()
{
switch (eAppType)
{
case CDataDecoder::AT_MOTSLISHOW:
iCurImagePos--;
SetSlideShowPicture();
break;
case CDataDecoder::AT_JOURNALINE:
/* Step one level back, get ID from history */
iCurJourObjID = NewIDHistory.Back();
/* If root ID is reached, disable back button */
if (iCurJourObjID == 0)
PushButtonStepBack->setEnabled(FALSE);
SetJournalineText();
break;
}
}
void MultimediaDlg::OnButtonStepForw()
{
iCurImagePos++;
SetSlideShowPicture();
}
void MultimediaDlg::OnButtonJumpBegin()
{
/* Reset current picture number to zero (begin) */
iCurImagePos = 0;
SetSlideShowPicture();
}
void MultimediaDlg::OnButtonJumpEnd()
{
/* Go to last received picture */
iCurImagePos = GetIDLastPicture();
SetSlideShowPicture();
}
void MultimediaDlg::SetSlideShowPicture()
{
QPixmap NewImage;
int iPicSize;
/* Copy current image from image storage vector */
CMOTObject vecbyCurPict(vecRawImages[iCurImagePos]);
/* The standard version of QT does not have jpeg support, if FreeImage
library is installed, the following routine converts the picture to
png which can be displayed */
JpgToPng(vecbyCurPict);
/* Get picture size */
iPicSize = vecbyCurPict.vecbRawData.Size();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -