2021-01-18 07:28:54 +00:00
|
|
|
/* Copyright 2013-2021 MultiMC Contributors
|
2013-10-08 22:11:24 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2013-10-12 14:19:49 +01:00
|
|
|
#include <QMessageBox>
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
#include "InfoFrame.h"
|
|
|
|
#include "ui_InfoFrame.h"
|
2021-11-22 02:55:16 +00:00
|
|
|
|
|
|
|
#include "ui/dialogs/CustomMessageBox.h"
|
2013-11-04 01:53:05 +00:00
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
InfoFrame::InfoFrame(QWidget *parent) :
|
|
|
|
QFrame(parent),
|
|
|
|
ui(new Ui::InfoFrame)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->descriptionLabel->setHidden(true);
|
|
|
|
ui->nameLabel->setHidden(true);
|
|
|
|
updateHiddenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
InfoFrame::~InfoFrame()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InfoFrame::updateWithMod(Mod const& m)
|
2013-10-08 21:45:48 +01:00
|
|
|
{
|
2022-08-09 05:53:50 +01:00
|
|
|
if (m.type() == ResourceType::FOLDER)
|
2018-07-15 13:51:05 +01:00
|
|
|
{
|
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
2013-10-08 22:25:56 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
QString text = "";
|
|
|
|
QString name = "";
|
|
|
|
if (m.name().isEmpty())
|
2022-04-16 02:07:35 +01:00
|
|
|
name = m.internal_id();
|
2018-07-15 13:51:05 +01:00
|
|
|
else
|
|
|
|
name = m.name();
|
2013-10-09 03:10:56 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
if (m.homeurl().isEmpty())
|
|
|
|
text = name;
|
|
|
|
else
|
|
|
|
text = "<a href=\"" + m.homeurl() + "\">" + name + "</a>";
|
|
|
|
if (!m.authors().isEmpty())
|
2019-08-03 04:30:46 +01:00
|
|
|
text += " by " + m.authors().join(", ");
|
2013-10-08 21:45:48 +01:00
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
setName(text);
|
2013-10-08 21:45:48 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
if (m.description().isEmpty())
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
setDescription(QString());
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
setDescription(m.description());
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2013-10-09 01:03:02 +01:00
|
|
|
}
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
void InfoFrame::updateWithResource(const Resource& resource)
|
2013-10-08 21:45:48 +01:00
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
setName(resource.name());
|
2013-10-08 21:45:48 +01:00
|
|
|
}
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
void InfoFrame::clear()
|
2013-10-08 21:45:48 +01:00
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
setName();
|
|
|
|
setDescription();
|
2013-10-08 21:45:48 +01:00
|
|
|
}
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
void InfoFrame::updateHiddenState()
|
2016-01-02 03:01:00 +00:00
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
if(ui->descriptionLabel->isHidden() && ui->nameLabel->isHidden())
|
2018-07-15 13:51:05 +01:00
|
|
|
{
|
|
|
|
setHidden(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setHidden(false);
|
|
|
|
}
|
2016-01-02 03:01:00 +00:00
|
|
|
}
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
void InfoFrame::setName(QString text)
|
2013-10-08 21:45:48 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if(text.isEmpty())
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
ui->nameLabel->setHidden(true);
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
ui->nameLabel->setText(text);
|
|
|
|
ui->nameLabel->setHidden(false);
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
updateHiddenState();
|
2013-10-08 21:45:48 +01:00
|
|
|
}
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
void InfoFrame::setDescription(QString text)
|
2013-10-08 21:45:48 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
if(text.isEmpty())
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
ui->descriptionLabel->setHidden(true);
|
2018-07-15 13:51:05 +01:00
|
|
|
updateHiddenState();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
ui->descriptionLabel->setHidden(false);
|
2018-07-15 13:51:05 +01:00
|
|
|
updateHiddenState();
|
|
|
|
}
|
2022-08-10 18:48:34 +01:00
|
|
|
ui->descriptionLabel->setToolTip("");
|
2018-07-15 13:51:05 +01:00
|
|
|
QString intermediatetext = text.trimmed();
|
|
|
|
bool prev(false);
|
|
|
|
QChar rem('\n');
|
|
|
|
QString finaltext;
|
|
|
|
finaltext.reserve(intermediatetext.size());
|
|
|
|
foreach(const QChar& c, intermediatetext)
|
|
|
|
{
|
|
|
|
if(c == rem && prev){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prev = c == rem;
|
|
|
|
finaltext += c;
|
|
|
|
}
|
|
|
|
QString labeltext;
|
|
|
|
labeltext.reserve(300);
|
|
|
|
if(finaltext.length() > 290)
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
ui->descriptionLabel->setOpenExternalLinks(false);
|
|
|
|
ui->descriptionLabel->setTextFormat(Qt::TextFormat::RichText);
|
|
|
|
m_description = text;
|
2020-11-02 21:28:07 +00:00
|
|
|
// This allows injecting HTML here.
|
2018-07-15 13:51:05 +01:00
|
|
|
labeltext.append("<html><body>" + finaltext.left(287) + "<a href=\"#mod_desc\">...</a></body></html>");
|
2022-08-10 18:48:34 +01:00
|
|
|
QObject::connect(ui->descriptionLabel, &QLabel::linkActivated, this, &InfoFrame::descriptionEllipsisHandler);
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
ui->descriptionLabel->setTextFormat(Qt::TextFormat::PlainText);
|
2018-07-15 13:51:05 +01:00
|
|
|
labeltext.append(finaltext);
|
|
|
|
}
|
2022-08-10 18:48:34 +01:00
|
|
|
ui->descriptionLabel->setText(labeltext);
|
2013-10-08 21:45:48 +01:00
|
|
|
}
|
2015-11-12 23:50:38 +00:00
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
void InfoFrame::descriptionEllipsisHandler(QString link)
|
2013-10-12 14:19:49 +01:00
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
if(!m_current_box)
|
2018-07-15 13:51:05 +01:00
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
m_current_box = CustomMessageBox::selectable(this, "", m_description);
|
|
|
|
connect(m_current_box, &QMessageBox::finished, this, &InfoFrame::boxClosed);
|
|
|
|
m_current_box->show();
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
m_current_box->setText(m_description);
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2015-11-12 23:50:38 +00:00
|
|
|
}
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
void InfoFrame::boxClosed(int result)
|
2015-11-12 23:50:38 +00:00
|
|
|
{
|
2022-08-10 18:48:34 +01:00
|
|
|
m_current_box = nullptr;
|
2013-10-12 14:19:49 +01:00
|
|
|
}
|