@ -0,0 +1,89 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash 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 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash 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 ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file io.c
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
#include "io.h" |
|||
#include <string.h> |
|||
#include <stdio.h> |
|||
|
|||
// silly macro to save some typing
|
|||
#define PASS_ARR(c_) (c_), sizeof(c_) |
|||
|
|||
static bool ethash_io_write_file(char const *dirname, |
|||
char const* filename, |
|||
size_t filename_length, |
|||
void const* data, |
|||
size_t data_size) |
|||
{ |
|||
bool ret = false; |
|||
char *fullname = ethash_io_create_filename(dirname, filename, filename_length); |
|||
if (!fullname) { |
|||
return false; |
|||
} |
|||
FILE *f = fopen(fullname, "wb"); |
|||
if (!f) { |
|||
goto free_name; |
|||
} |
|||
if (data_size != fwrite(data, 1, data_size, f)) { |
|||
goto close; |
|||
} |
|||
|
|||
ret = true; |
|||
close: |
|||
fclose(f); |
|||
free_name: |
|||
free(fullname); |
|||
return ret; |
|||
} |
|||
|
|||
bool ethash_io_write(char const *dirname, |
|||
ethash_params const* params, |
|||
ethash_blockhash_t seedhash, |
|||
void const* cache, |
|||
uint8_t **data, |
|||
size_t *data_size) |
|||
{ |
|||
char info_buffer[DAG_MEMO_BYTESIZE]; |
|||
// allocate the bytes
|
|||
uint8_t *temp_data_ptr = malloc(params->full_size); |
|||
if (!temp_data_ptr) { |
|||
goto end; |
|||
} |
|||
ethash_compute_full_data(temp_data_ptr, params, cache); |
|||
|
|||
if (!ethash_io_write_file(dirname, PASS_ARR(DAG_FILE_NAME), temp_data_ptr, params->full_size)) { |
|||
goto fail_free; |
|||
} |
|||
|
|||
ethash_io_serialize_info(ETHASH_REVISION, seedhash, info_buffer); |
|||
if (!ethash_io_write_file(dirname, PASS_ARR(DAG_MEMO_NAME), info_buffer, DAG_MEMO_BYTESIZE)) { |
|||
goto fail_free; |
|||
} |
|||
|
|||
*data = temp_data_ptr; |
|||
*data_size = params->full_size; |
|||
return true; |
|||
|
|||
fail_free: |
|||
free(temp_data_ptr); |
|||
end: |
|||
return false; |
|||
} |
|||
|
|||
#undef PASS_ARR |
@ -0,0 +1,116 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash 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 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash 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 ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file io.h
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
#pragma once |
|||
#include <stdlib.h> |
|||
#include <stdint.h> |
|||
#include <stdbool.h> |
|||
#include "ethash.h" |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
typedef struct ethash_blockhash { uint8_t b[32]; } ethash_blockhash_t; |
|||
|
|||
static const char DAG_FILE_NAME[] = "full"; |
|||
static const char DAG_MEMO_NAME[] = "full.info"; |
|||
// MSVC thinks that "static const unsigned int" is not a compile time variable. Sorry for the #define :(
|
|||
#define DAG_MEMO_BYTESIZE 36 |
|||
|
|||
/// Possible return values of @see ethash_io_prepare
|
|||
enum ethash_io_rc { |
|||
ETHASH_IO_FAIL = 0, ///< There has been an IO failure
|
|||
ETHASH_IO_MEMO_MISMATCH, ///< Memo file either did not exist or there was content mismatch
|
|||
ETHASH_IO_MEMO_MATCH, ///< Memo file existed and contents matched. No need to do anything
|
|||
}; |
|||
|
|||
/**
|
|||
* Prepares io for ethash |
|||
* |
|||
* Create the DAG directory if it does not exist, and check if the memo file matches. |
|||
* If it does not match then it's deleted to pave the way for @ref ethash_io_write() |
|||
* |
|||
* @param dirname A null terminated c-string of the path of the ethash |
|||
* data directory. If it does not exist it's created. |
|||
* @param seedhash The seedhash of the current block number |
|||
* @return For possible return values @see enum ethash_io_rc |
|||
*/ |
|||
enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash); |
|||
/**
|
|||
* Fully computes data and writes it to the file on disk. |
|||
* |
|||
* This function should be called after @see ethash_io_prepare() and only if |
|||
* its return value is @c ETHASH_IO_MEMO_MISMATCH. Will write both the full data |
|||
* and the memo file. |
|||
* |
|||
* @param[in] dirname A null terminated c-string of the path of the ethash |
|||
* data directory. Has to exist. |
|||
* @param[in] params An ethash_params object containing the full size |
|||
* and the cache size |
|||
* @param[in] seedhash The seedhash of the current block number |
|||
* @param[in] cache The cache data. Would have usually been calulated by |
|||
* @see ethash_prep_light(). |
|||
* @param[out] data Pass a pointer to uint8_t by reference here. If the |
|||
* function is succesfull then this point to the allocated |
|||
* data calculated by @see ethash_prep_full(). Memory |
|||
* ownership is transfered to the callee. Remember that |
|||
* you eventually need to free this with a call to free(). |
|||
* @param[out] data_size Pass a size_t by value. If the function is succesfull |
|||
* then this will contain the number of bytes allocated |
|||
* for @a data. |
|||
* @return True for success and false in case of failure. |
|||
*/ |
|||
bool ethash_io_write(char const *dirname, |
|||
ethash_params const* params, |
|||
ethash_blockhash_t seedhash, |
|||
void const* cache, |
|||
uint8_t **data, |
|||
size_t *data_size); |
|||
|
|||
static inline void ethash_io_serialize_info(uint32_t revision, |
|||
ethash_blockhash_t seed_hash, |
|||
char *output) |
|||
{ |
|||
// if .info is only consumed locally we don't really care about endianess
|
|||
memcpy(output, &revision, 4); |
|||
memcpy(output + 4, &seed_hash, 32); |
|||
} |
|||
|
|||
static inline char *ethash_io_create_filename(char const *dirname, |
|||
char const* filename, |
|||
size_t filename_length) |
|||
{ |
|||
// in C the cast is not needed, but a C++ compiler will complain for invalid conversion
|
|||
char *name = (char*)malloc(strlen(dirname) + filename_length); |
|||
if (!name) { |
|||
return NULL; |
|||
} |
|||
|
|||
name[0] = '\0'; |
|||
strcat(name, dirname); |
|||
strcat(name, filename); |
|||
return name; |
|||
} |
|||
|
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -0,0 +1,76 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash 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 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash 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 ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file io_posix.c
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include "io.h" |
|||
#include <sys/types.h> |
|||
#include <sys/stat.h> |
|||
#include <errno.h> |
|||
#include <libgen.h> |
|||
#include <stdio.h> |
|||
#include <unistd.h> |
|||
|
|||
enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash) |
|||
{ |
|||
char read_buffer[DAG_MEMO_BYTESIZE]; |
|||
char expect_buffer[DAG_MEMO_BYTESIZE]; |
|||
enum ethash_io_rc ret = ETHASH_IO_FAIL; |
|||
|
|||
// assert directory exists, full owner permissions and read/search for others
|
|||
int rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); |
|||
if (rc == -1 && errno != EEXIST) { |
|||
goto end; |
|||
} |
|||
|
|||
char *memofile = ethash_io_create_filename(dirname, DAG_MEMO_NAME, sizeof(DAG_MEMO_NAME)); |
|||
if (!memofile) { |
|||
goto end; |
|||
} |
|||
|
|||
// try to open memo file
|
|||
FILE *f = fopen(memofile, "rb"); |
|||
if (!f) { |
|||
// file does not exist, so no checking happens. All is fine.
|
|||
ret = ETHASH_IO_MEMO_MISMATCH; |
|||
goto free_memo; |
|||
} |
|||
|
|||
if (fread(read_buffer, 1, DAG_MEMO_BYTESIZE, f) != DAG_MEMO_BYTESIZE) { |
|||
goto close; |
|||
} |
|||
|
|||
ethash_io_serialize_info(ETHASH_REVISION, seedhash, expect_buffer); |
|||
if (memcmp(read_buffer, expect_buffer, DAG_MEMO_BYTESIZE) != 0) { |
|||
// we have different memo contents so delete the memo file
|
|||
if (unlink(memofile) != 0) { |
|||
goto close; |
|||
} |
|||
ret = ETHASH_IO_MEMO_MISMATCH; |
|||
} |
|||
|
|||
ret = ETHASH_IO_MEMO_MATCH; |
|||
|
|||
close: |
|||
fclose(f); |
|||
free_memo: |
|||
free(memofile); |
|||
end: |
|||
return ret; |
|||
} |
@ -0,0 +1,73 @@ |
|||
/*
|
|||
This file is part of ethash. |
|||
|
|||
ethash 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 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
ethash 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 ethash. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/** @file io_win32.c
|
|||
* @author Lefteris Karapetsas <lefteris@ethdev.com> |
|||
* @date 2015 |
|||
*/ |
|||
|
|||
#include "io.h" |
|||
#include <direct.h> |
|||
#include <errno.h> |
|||
#include <stdio.h> |
|||
|
|||
enum ethash_io_rc ethash_io_prepare(char const *dirname, ethash_blockhash_t seedhash) |
|||
{ |
|||
char read_buffer[DAG_MEMO_BYTESIZE]; |
|||
char expect_buffer[DAG_MEMO_BYTESIZE]; |
|||
enum ethash_io_rc ret = ETHASH_IO_FAIL; |
|||
|
|||
// assert directory exists
|
|||
int rc = _mkdir(dirname); |
|||
if (rc == -1 && errno != EEXIST) { |
|||
goto end; |
|||
} |
|||
|
|||
char *memofile = ethash_io_create_filename(dirname, DAG_MEMO_NAME, sizeof(DAG_MEMO_NAME)); |
|||
if (!memofile) { |
|||
goto end; |
|||
} |
|||
|
|||
// try to open memo file
|
|||
FILE *f = fopen(memofile, "rb"); |
|||
if (!f) { |
|||
// file does not exist, so no checking happens. All is fine.
|
|||
ret = ETHASH_IO_MEMO_MISMATCH; |
|||
goto free_memo; |
|||
} |
|||
|
|||
if (fread(read_buffer, 1, DAG_MEMO_BYTESIZE, f) != DAG_MEMO_BYTESIZE) { |
|||
goto close; |
|||
} |
|||
|
|||
ethash_io_serialize_info(ETHASH_REVISION, seedhash, expect_buffer); |
|||
if (memcmp(read_buffer, expect_buffer, DAG_MEMO_BYTESIZE) != 0) { |
|||
// we have different memo contents so delete the memo file
|
|||
if (_unlink(memofile) != 0) { |
|||
goto close; |
|||
} |
|||
ret = ETHASH_IO_MEMO_MISMATCH; |
|||
} |
|||
|
|||
ret = ETHASH_IO_MEMO_MATCH; |
|||
|
|||
close: |
|||
fclose(f); |
|||
free_memo: |
|||
free(memofile); |
|||
end: |
|||
return ret; |
|||
} |
@ -0,0 +1,107 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum 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 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/**
|
|||
* @file SemanticInformation.cpp |
|||
* @author Christian <c@ethdev.com> |
|||
* @date 2015 |
|||
* Helper to provide semantic information about assembly items. |
|||
*/ |
|||
|
|||
#include <libevmcore/SemanticInformation.h> |
|||
#include <libevmcore/AssemblyItem.h> |
|||
|
|||
using namespace std; |
|||
using namespace dev; |
|||
using namespace dev::eth; |
|||
|
|||
bool SemanticInformation::breaksCSEAnalysisBlock(AssemblyItem const& _item) |
|||
{ |
|||
switch (_item.type()) |
|||
{ |
|||
default: |
|||
case UndefinedItem: |
|||
case Tag: |
|||
return true; |
|||
case Push: |
|||
case PushString: |
|||
case PushTag: |
|||
case PushSub: |
|||
case PushSubSize: |
|||
case PushProgramSize: |
|||
case PushData: |
|||
return false; |
|||
case Operation: |
|||
{ |
|||
if (isSwapInstruction(_item) || isDupInstruction(_item)) |
|||
return false; |
|||
if (_item.instruction() == Instruction::GAS || _item.instruction() == Instruction::PC) |
|||
return true; // GAS and PC assume a specific order of opcodes
|
|||
if (_item.instruction() == Instruction::MSIZE) |
|||
return true; // msize is modified already by memory access, avoid that for now
|
|||
if (_item.instruction() == Instruction::SHA3) |
|||
return true; //@todo: we have to compare sha3's not based on their memory addresses but on the memory content.
|
|||
InstructionInfo info = instructionInfo(_item.instruction()); |
|||
if (_item.instruction() == Instruction::SSTORE) |
|||
return false; |
|||
if (_item.instruction() == Instruction::MSTORE) |
|||
return false; |
|||
//@todo: We do not handle the following memory instructions for now:
|
|||
// calldatacopy, codecopy, extcodecopy, mstore8,
|
|||
// msize (note that msize also depends on memory read access)
|
|||
|
|||
// the second requirement will be lifted once it is implemented
|
|||
return info.sideEffects || info.args > 2; |
|||
} |
|||
} |
|||
} |
|||
|
|||
bool SemanticInformation::isCommutativeOperation(AssemblyItem const& _item) |
|||
{ |
|||
if (_item.type() != Operation) |
|||
return false; |
|||
switch (_item.instruction()) |
|||
{ |
|||
case Instruction::ADD: |
|||
case Instruction::MUL: |
|||
case Instruction::EQ: |
|||
case Instruction::AND: |
|||
case Instruction::OR: |
|||
case Instruction::XOR: |
|||
return true; |
|||
default: |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
bool SemanticInformation::isDupInstruction(AssemblyItem const& _item) |
|||
{ |
|||
if (_item.type() != Operation) |
|||
return false; |
|||
return Instruction::DUP1 <= _item.instruction() && _item.instruction() <= Instruction::DUP16; |
|||
} |
|||
|
|||
bool SemanticInformation::isSwapInstruction(AssemblyItem const& _item) |
|||
{ |
|||
if (_item.type() != Operation) |
|||
return false; |
|||
return Instruction::SWAP1 <= _item.instruction() && _item.instruction() <= Instruction::SWAP16; |
|||
} |
|||
|
|||
bool SemanticInformation::isJumpInstruction(AssemblyItem const& _item) |
|||
{ |
|||
return _item == AssemblyItem(Instruction::JUMP) || _item == AssemblyItem(Instruction::JUMPI); |
|||
} |
@ -0,0 +1,50 @@ |
|||
/*
|
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum 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 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/ |
|||
/**
|
|||
* @file SemanticInformation.h |
|||
* @author Christian <c@ethdev.com> |
|||
* @date 2015 |
|||
* Helper to provide semantic information about assembly items. |
|||
*/ |
|||
|
|||
#pragma once |
|||
|
|||
|
|||
namespace dev |
|||
{ |
|||
namespace eth |
|||
{ |
|||
|
|||
class AssemblyItem; |
|||
|
|||
/**
|
|||
* Helper functions to provide context-independent information about assembly items. |
|||
*/ |
|||
struct SemanticInformation |
|||
{ |
|||
/// @returns true if the given items starts a new block for common subexpression analysis.
|
|||
static bool breaksCSEAnalysisBlock(AssemblyItem const& _item); |
|||
/// @returns true if the item is a two-argument operation whose value does not depend on the
|
|||
/// order of its arguments.
|
|||
static bool isCommutativeOperation(AssemblyItem const& _item); |
|||
static bool isDupInstruction(AssemblyItem const& _item); |
|||
static bool isSwapInstruction(AssemblyItem const& _item); |
|||
static bool isJumpInstruction(AssemblyItem const& _item); |
|||
}; |
|||
|
|||
} |
|||
} |
@ -0,0 +1,260 @@ |
|||
/* |
|||
This file is part of cpp-ethereum. |
|||
|
|||
cpp-ethereum 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 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
cpp-ethereum 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 cpp-ethereum. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
/** @file StatesComboBox.qml |
|||
* @author Ali Mashatan ali@ethdev.com |
|||
* @date 2015 |
|||
* Ethereum IDE client. |
|||
*/ |
|||
|
|||
import QtQuick 2.0 |
|||
import QtQuick.Controls 1.0 |
|||
import QtQuick.Layouts 1.1 |
|||
import QtGraphicalEffects 1.0 |
|||
|
|||
Rectangle { |
|||
id: statesComboBox |
|||
|
|||
width: 200 |
|||
height: 23 |
|||
|
|||
Component.onCompleted: { |
|||
var top = dropDownList |
|||
while (top.parent) { |
|||
top = top.parent |
|||
if (top.objectName == "debugPanel") |
|||
break |
|||
} |
|||
var coordinates = dropDownList.mapToItem(top, 0, 0) |
|||
//the order is important |
|||
dropDownShowdowList.parent = top |
|||
dropDownList.parent = top |
|||
|
|||
dropDownShowdowList.x = coordinates.x |
|||
dropDownShowdowList.y = coordinates.y |
|||
|
|||
dropDownList.x = coordinates.x |
|||
dropDownList.y = coordinates.y |
|||
} |
|||
|
|||
signal selectItem(real item) |
|||
signal editItem(real item) |
|||
signal selectCreate |
|||
property int rowHeight: 25 |
|||
property variant items |
|||
property alias selectedItem: chosenItemText.text |
|||
property alias selectedIndex: listView.currentRow |
|||
function setSelectedIndex(index) { |
|||
listView.currentRow = index |
|||
chosenItemText.text = statesComboBox.items.get(index).title |
|||
} |
|||
|
|||
signal comboClicked |
|||
|
|||
property variant colorItem |
|||
property variant colorSelect |
|||
|
|||
SourceSansProRegular |
|||
{ |
|||
id: regularFont |
|||
} |
|||
|
|||
SourceSansProBold |
|||
{ |
|||
id: boldFont |
|||
} |
|||
|
|||
smooth: true |
|||
Rectangle { |
|||
id: chosenItem |
|||
width: parent.width |
|||
height: statesComboBox.height |
|||
color: statesComboBox.color |
|||
|
|||
Text { |
|||
id: chosenItemText |
|||
anchors.left: parent.left |
|||
anchors.leftMargin: 10 |
|||
anchors.verticalCenter: parent.verticalCenter |
|||
color: statesComboBox.colorItem |
|||
text: "" |
|||
font.family: regularFont.name |
|||
} |
|||
|
|||
MouseArea { |
|||
anchors.fill: parent |
|||
onClicked: { |
|||
statesComboBox.state = statesComboBox.state === "dropDown" ? "" : "dropDown" |
|||
} |
|||
} |
|||
} |
|||
|
|||
Rectangle { |
|||
id: dropDownShowdowList |
|||
width: statesComboBox.width |
|||
opacity: 0.3 |
|||
height: 0 |
|||
clip: true |
|||
radius: 4 |
|||
anchors.top: chosenItem.top |
|||
anchors.margins: 2 |
|||
color: "gray" |
|||
} |
|||
//ToDo: We need scrollbar for items |
|||
Rectangle { |
|||
id: dropDownList |
|||
width: statesComboBox.width |
|||
height: 0 |
|||
clip: true |
|||
radius: 4 |
|||
anchors.top: chosenItem.top |
|||
anchors.topMargin: 23 |
|||
color: statesComboBox.color |
|||
|
|||
ColumnLayout { |
|||
spacing: 2 |
|||
TableView { |
|||
id: listView |
|||
height: 20 |
|||
implicitHeight: 0 |
|||
width: statesComboBox.width |
|||
model: statesComboBox.items |
|||
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff |
|||
currentRow: -1 |
|||
headerVisible: false |
|||
backgroundVisible: false |
|||
alternatingRowColors: false |
|||
frameVisible: false |
|||
|
|||
TableViewColumn { |
|||
role: "title" |
|||
title: "" |
|||
width: statesComboBox.width |
|||
delegate: mainItemDelegate |
|||
} |
|||
rowDelegate: Rectangle { |
|||
width: statesComboBox.width |
|||
height: statesComboBox.rowHeight |
|||
} |
|||
Component { |
|||
id: mainItemDelegate |
|||
Rectangle { |
|||
id: itemDelegate |
|||
width: statesComboBox.width |
|||
height: statesComboBox.height |
|||
Text { |
|||
id: textItemid |
|||
text: styleData.value |
|||
color: statesComboBox.colorItem |
|||
anchors.top: parent.top |
|||
anchors.left: parent.left |
|||
anchors.leftMargin: 10 |
|||
anchors.topMargin: 5 |
|||
font.family: regularFont.name |
|||
} |
|||
Image { |
|||
id: imageItemid |
|||
height: 20 |
|||
width: 20 |
|||
anchors.right: parent.right |
|||
anchors.top: parent.top |
|||
anchors.margins: 5 |
|||
visible: false |
|||
fillMode: Image.PreserveAspectFit |
|||
source: "img/edit_combox.png" |
|||
} |
|||
|
|||
MouseArea { |
|||
anchors.fill: parent |
|||
hoverEnabled: true |
|||
|
|||
onEntered: { |
|||
imageItemid.visible = true |
|||
textItemid.color = statesComboBox.colorSelect |
|||
} |
|||
onExited: { |
|||
imageItemid.visible = false |
|||
textItemid.color = statesComboBox.colorItem |
|||
} |
|||
onClicked: { |
|||
if (mouseX > imageItemid.x |
|||
&& mouseX < imageItemid.x + imageItemid.width |
|||
&& mouseY > imageItemid.y |
|||
&& mouseY < imageItemid.y + imageItemid.height) |
|||
statesComboBox.editItem(styleData.row) |
|||
else { |
|||
statesComboBox.state = "" |
|||
var prevSelection = chosenItemText.text |
|||
chosenItemText.text = styleData.value |
|||
listView.currentRow = styleData.row |
|||
statesComboBox.selectItem(styleData.row) |
|||
} |
|||
} |
|||
} |
|||
} //Item |
|||
} //Component |
|||
} //Table View |
|||
|
|||
RowLayout { |
|||
anchors.top: listView.bottom |
|||
anchors.topMargin: 4 |
|||
anchors.left: parent.left |
|||
anchors.leftMargin: 10 |
|||
Text { |
|||
id: createStateText |
|||
width: statesComboBox.width |
|||
height: statesComboBox.height |
|||
font.family: boldFont.name |
|||
color: "#808080" |
|||
text: qsTr("Create State ...") |
|||
font.weight: Font.DemiBold |
|||
MouseArea { |
|||
anchors.fill: parent |
|||
hoverEnabled: true |
|||
|
|||
onEntered: { |
|||
createStateText.color = statesComboBox.colorSelect |
|||
} |
|||
onExited: { |
|||
createStateText.color = statesComboBox.colorItem |
|||
} |
|||
onClicked: { |
|||
statesComboBox.state = "" |
|||
statesComboBox.selectCreate() |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
states: State { |
|||
name: "dropDown" |
|||
PropertyChanges { |
|||
target: dropDownList |
|||
height: (statesComboBox.rowHeight * (statesComboBox.items.count + 1)) |
|||
} |
|||
PropertyChanges { |
|||
target: dropDownShowdowList |
|||
width: statesComboBox.width + 3 |
|||
height: (statesComboBox.rowHeight * (statesComboBox.items.count + 1)) + 3 |
|||
} |
|||
PropertyChanges { |
|||
target: listView |
|||
height: 20 |
|||
implicitHeight: (statesComboBox.rowHeight * (statesComboBox.items.count)) |
|||
} |
|||
} |
|||
} |
Before Width: | Height: | Size: 501 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 871 B |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 406 B |
After Width: | Height: | Size: 200 B |
After Width: | Height: | Size: 414 B |
After Width: | Height: | Size: 531 B |
After Width: | Height: | Size: 904 B |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 235 B |
@ -0,0 +1,19 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE QtCreatorCodeStyle> |
|||
<!-- Written by QtCreator 3.3.2, 2015-03-31T14:55:07. --> |
|||
<qtcreator> |
|||
<data> |
|||
<variable>CodeStyleData</variable> |
|||
<valuemap type="QVariantMap"> |
|||
<value type="bool" key="AutoSpacesForTabs">false</value> |
|||
<value type="int" key="IndentSize">4</value> |
|||
<value type="int" key="PaddingMode">2</value> |
|||
<value type="bool" key="SpacesForTabs">false</value> |
|||
<value type="int" key="TabSize">4</value> |
|||
</valuemap> |
|||
</data> |
|||
<data> |
|||
<variable>DisplayName</variable> |
|||
<value type="QString">Eth</value> |
|||
</data> |
|||
</qtcreator> |